APPdelegateModularForPay.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // APPdelegateModularForPay.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2019/3/26.
  6. // Copyright © 2019 JCZ. All rights reserved.
  7. //
  8. #import "APPdelegateModularForPay.h"
  9. #import "RQAppEventAnnotation.h"
  10. /// 微信SDK头文件
  11. #import <WXApi.h>
  12. #import <WXApiObject.h>
  13. /// 微信支付器
  14. #import "payRequsestHandler.h"
  15. /// 支付
  16. #import <AlipaySDK/AlipaySDK.h>
  17. RQAppEventMod(APPdelegateModularForPay)
  18. @interface APPdelegateModularForPay () <WXApiDelegate>
  19. @end
  20. @implementation APPdelegateModularForPay
  21. - (NSInteger)moduleLevel {
  22. return 5;
  23. }
  24. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  25. [self initMudule];
  26. // [self destroyModule];
  27. return YES;
  28. }
  29. - (void)initMudule {
  30. /// 初始化微信支付
  31. [self initWechatPay];
  32. }
  33. #pragma mark - 初始化微信支付
  34. - (void)initWechatPay {
  35. /**微信支付
  36. 1、导入微信支付SDK,注册微信支付
  37. 2、设置微信appid为URL schemes
  38. 3、发起支付,调用微信支付
  39. 4、处理支付结果
  40. */
  41. [WXApi registerApp:@"wx606fa102dbc4b8ab" universalLink:@"https://app.jppt.com.cn/JSJPStudent/"];
  42. }
  43. #pragma mark WeChatPay
  44. - (void)onResp:(BaseResp *)resp {
  45. if([resp isKindOfClass:[PayResp class]]){
  46. //支付返回结果,实际支付结果需要去微信服务器端查询
  47. NSString *strMsg,*strTitle = [NSString stringWithFormat:@"支付结果"];
  48. switch (resp.errCode) {
  49. case WXSuccess:
  50. strMsg = @"支付结果:成功!";
  51. //NSLog(@"支付成功-PaySuccess,retcode = %d", resp.errCode);
  52. break;
  53. default:
  54. strMsg = [NSString stringWithFormat:@"支付结果:失败!retcode = %d, retstr = %@", resp.errCode,resp.errStr];
  55. //NSLog(@"错误,retcode = %d, retstr = %@", resp.errCode,resp.errStr);
  56. break;
  57. }
  58. [RQ_SHARE_FUNCTION showAlertWithTitle:strTitle message:strMsg alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
  59. }
  60. if ([resp isKindOfClass:[WXLaunchMiniProgramResp class]]) {
  61. // NSString *string = resp.extMsg;
  62. // 对应JsApi navigateBackApplication中的extraData字段数据
  63. }
  64. }
  65. //- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL * _Nonnull)url {
  66. // //这里判断是否发起的请求为微信支付,如果是的话,用WXApi的方法调起微信客户端的支付页面(://pay 之前的那串字符串就是你的APPID,)
  67. // if ([[NSString stringWithFormat:@"%@",url] rangeOfString:[NSString stringWithFormat:@"%@://pay",APP_ID]].location != NSNotFound) {
  68. // return [WXApi handleOpenURL:url delegate:self];
  69. // }
  70. //
  71. // return YES;
  72. //}
  73. //
  74. //#pragma mark AliPay
  75. //- (BOOL)application:(UIApplication *)application
  76. // openURL:(NSURL *)url
  77. // sourceApplication:(NSString *)sourceApplication
  78. // annotation:(id)annotation {
  79. //
  80. // if ([url.host isEqualToString:@"safepay"]) {
  81. // //跳转支付宝钱包进行支付,处理支付结果
  82. // [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
  83. // //NSLog(@"PaymentResult 支付结果11--><>%@",resultDic);
  84. // if ([[resultDic objectForKey:@"resultStatus"] isEqual:@"9000"]) {
  85. // //支付成功
  86. // [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_SUCCESSED];
  87. // }else{
  88. // [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_FAILED];
  89. // }
  90. // }];
  91. // }
  92. //
  93. //
  94. // //这里判断是否发起的请求为微信支付,如果是的话,用WXApi的方法调起微信客户端的支付页面(://pay 之前的那串字符串就是你的APPID,)
  95. // if ([[NSString stringWithFormat:@"%@",url] rangeOfString:[NSString stringWithFormat:@"%@://pay",APP_ID]].location != NSNotFound) {
  96. // return [WXApi handleOpenURL:url delegate:self];
  97. // }
  98. // return YES;
  99. //}
  100. // NOTE: 9.0以后使用新API接口
  101. - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
  102. {
  103. if ([url.host isEqualToString:@"safepay"]) {
  104. //跳转支付宝钱包进行支付,处理支付结果
  105. [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
  106. //NSLog(@"result 支付结果22--><>%@",resultDic);
  107. if ([[resultDic objectForKey:@"resultStatus"] isEqual:@"9000"]) {
  108. //支付成功
  109. [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_SUCCESSED];
  110. }else{
  111. [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_FAILED];
  112. }
  113. }];
  114. }
  115. //这里判断是否发起的请求为微信支付,如果是的话,用WXApi的方法调起微信客户端的支付页面(://pay 之前的那串字符串就是你的APPID,)
  116. if ([[NSString stringWithFormat:@"%@",url] rangeOfString:[NSString stringWithFormat:@"%@://pay",APP_ID]].location != NSNotFound) {
  117. return [WXApi handleOpenURL:url delegate:self];
  118. }
  119. return YES;
  120. }
  121. @end