WXApiManager.m 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // WXApiManager.m
  3. // SDKSample
  4. //
  5. // Created by Jeason on 16/07/2015.
  6. //
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "WXApiManager.h"
  10. @implementation WXApiManager
  11. #pragma mark - LifeCycle
  12. +(instancetype)sharedManager {
  13. static dispatch_once_t onceToken;
  14. static WXApiManager *instance;
  15. dispatch_once(&onceToken, ^{
  16. instance = [[WXApiManager alloc] init];
  17. });
  18. return instance;
  19. }
  20. - (void)dealloc {
  21. self.delegate = nil;
  22. [super dealloc];
  23. }
  24. #pragma mark - WXApiDelegate
  25. - (void)onResp:(BaseResp *)resp {
  26. if ([resp isKindOfClass:[SendMessageToWXResp class]]) {
  27. if (_delegate
  28. && [_delegate respondsToSelector:@selector(managerDidRecvMessageResponse:)]) {
  29. SendMessageToWXResp *messageResp = (SendMessageToWXResp *)resp;
  30. [_delegate managerDidRecvMessageResponse:messageResp];
  31. }
  32. } else if ([resp isKindOfClass:[SendAuthResp class]]) {
  33. if (_delegate
  34. && [_delegate respondsToSelector:@selector(managerDidRecvAuthResponse:)]) {
  35. SendAuthResp *authResp = (SendAuthResp *)resp;
  36. [_delegate managerDidRecvAuthResponse:authResp];
  37. }
  38. } else if ([resp isKindOfClass:[AddCardToWXCardPackageResp class]]) {
  39. if (_delegate
  40. && [_delegate respondsToSelector:@selector(managerDidRecvAddCardResponse:)]) {
  41. AddCardToWXCardPackageResp *addCardResp = (AddCardToWXCardPackageResp *)resp;
  42. [_delegate managerDidRecvAddCardResponse:addCardResp];
  43. }
  44. }else if([resp isKindOfClass:[PayResp class]]){
  45. //支付返回结果,实际支付结果需要去微信服务器端查询
  46. NSString *strMsg,*strTitle = [NSString stringWithFormat:@"支付结果"];
  47. switch (resp.errCode) {
  48. case WXSuccess:
  49. strMsg = @"支付结果:成功!";
  50. NSLog(@"支付成功-PaySuccess,retcode = %d", resp.errCode);
  51. break;
  52. default:
  53. strMsg = [NSString stringWithFormat:@"支付结果:失败!retcode = %d, retstr = %@", resp.errCode,resp.errStr];
  54. NSLog(@"错误,retcode = %d, retstr = %@", resp.errCode,resp.errStr);
  55. break;
  56. }
  57. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:strTitle message:strMsg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  58. [alert show];
  59. [alert release];
  60. }
  61. }
  62. - (void)onReq:(BaseReq *)req {
  63. if ([req isKindOfClass:[GetMessageFromWXReq class]]) {
  64. if (_delegate
  65. && [_delegate respondsToSelector:@selector(managerDidRecvGetMessageReq:)]) {
  66. GetMessageFromWXReq *getMessageReq = (GetMessageFromWXReq *)req;
  67. [_delegate managerDidRecvGetMessageReq:getMessageReq];
  68. }
  69. } else if ([req isKindOfClass:[ShowMessageFromWXReq class]]) {
  70. if (_delegate
  71. && [_delegate respondsToSelector:@selector(managerDidRecvShowMessageReq:)]) {
  72. ShowMessageFromWXReq *showMessageReq = (ShowMessageFromWXReq *)req;
  73. [_delegate managerDidRecvShowMessageReq:showMessageReq];
  74. }
  75. } else if ([req isKindOfClass:[LaunchFromWXReq class]]) {
  76. if (_delegate
  77. && [_delegate respondsToSelector:@selector(managerDidRecvLaunchFromWXReq:)]) {
  78. LaunchFromWXReq *launchReq = (LaunchFromWXReq *)req;
  79. [_delegate managerDidRecvLaunchFromWXReq:launchReq];
  80. }
  81. }
  82. }
  83. @end