天天省钱快报

WXApiManager.m 3.7KB

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