1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- //
- // WXApiManager.m
- // SDKSample
- //
- // Created by Jeason on 16/07/2015.
- //
- //
- #import <UIKit/UIKit.h>
- #import "WXApiManager.h"
- @implementation WXApiManager
- #pragma mark - LifeCycle
- +(instancetype)sharedManager {
- static dispatch_once_t onceToken;
- static WXApiManager *instance;
- dispatch_once(&onceToken, ^{
- instance = [[WXApiManager alloc] init];
- });
- return instance;
- }
- - (void)dealloc {
- self.delegate = nil;
- [super dealloc];
- }
- #pragma mark - WXApiDelegate
- - (void)onResp:(BaseResp *)resp {
- if ([resp isKindOfClass:[SendMessageToWXResp class]]) {
- if (_delegate
- && [_delegate respondsToSelector:@selector(managerDidRecvMessageResponse:)]) {
- SendMessageToWXResp *messageResp = (SendMessageToWXResp *)resp;
- [_delegate managerDidRecvMessageResponse:messageResp];
- }
- } else if ([resp isKindOfClass:[SendAuthResp class]]) {
- if (_delegate
- && [_delegate respondsToSelector:@selector(managerDidRecvAuthResponse:)]) {
- SendAuthResp *authResp = (SendAuthResp *)resp;
- [_delegate managerDidRecvAuthResponse:authResp];
- }
- } else if ([resp isKindOfClass:[AddCardToWXCardPackageResp class]]) {
- if (_delegate
- && [_delegate respondsToSelector:@selector(managerDidRecvAddCardResponse:)]) {
- AddCardToWXCardPackageResp *addCardResp = (AddCardToWXCardPackageResp *)resp;
- [_delegate managerDidRecvAddCardResponse:addCardResp];
- }
- }else if([resp isKindOfClass:[PayResp class]]){
- //支付返回结果,实际支付结果需要去微信服务器端查询
- NSString *strMsg,*strTitle = [NSString stringWithFormat:@"支付结果"];
-
- switch (resp.errCode) {
- case WXSuccess:
- strMsg = @"支付结果:成功!";
- NSLog(@"支付成功-PaySuccess,retcode = %d", resp.errCode);
- break;
-
- default:
- strMsg = [NSString stringWithFormat:@"支付结果:失败!retcode = %d, retstr = %@", resp.errCode,resp.errStr];
- NSLog(@"错误,retcode = %d, retstr = %@", resp.errCode,resp.errStr);
- break;
- }
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:strTitle message:strMsg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
- [alert show];
- [alert release];
- }
- }
- - (void)onReq:(BaseReq *)req {
- if ([req isKindOfClass:[GetMessageFromWXReq class]]) {
- if (_delegate
- && [_delegate respondsToSelector:@selector(managerDidRecvGetMessageReq:)]) {
- GetMessageFromWXReq *getMessageReq = (GetMessageFromWXReq *)req;
- [_delegate managerDidRecvGetMessageReq:getMessageReq];
- }
- } else if ([req isKindOfClass:[ShowMessageFromWXReq class]]) {
- if (_delegate
- && [_delegate respondsToSelector:@selector(managerDidRecvShowMessageReq:)]) {
- ShowMessageFromWXReq *showMessageReq = (ShowMessageFromWXReq *)req;
- [_delegate managerDidRecvShowMessageReq:showMessageReq];
- }
- } else if ([req isKindOfClass:[LaunchFromWXReq class]]) {
- if (_delegate
- && [_delegate respondsToSelector:@selector(managerDidRecvLaunchFromWXReq:)]) {
- LaunchFromWXReq *launchReq = (LaunchFromWXReq *)req;
- [_delegate managerDidRecvLaunchFromWXReq:launchReq];
- }
- }
- }
- @end
|