123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- //
- // APPdelegateModularForPay.m
- // jiaPei
- //
- // Created by 张嵘 on 2019/3/26.
- // Copyright © 2019 JCZ. All rights reserved.
- //
- #import "APPdelegateModularForPay.h"
- #import "RQAppEventAnnotation.h"
- /// 微信SDK头文件
- #import <WXApi.h>
- #import <WXApiObject.h>
- /// 微信支付器
- #import "payRequsestHandler.h"
- /// 支付
- #import <AlipaySDK/AlipaySDK.h>
- RQAppEventMod(APPdelegateModularForPay)
- @interface APPdelegateModularForPay () <WXApiDelegate>
- @end
- @implementation APPdelegateModularForPay
- - (NSInteger)moduleLevel {
- return 5;
- }
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- [self initMudule];
- // [self destroyModule];
- return YES;
- }
- - (void)initMudule {
- /// 初始化微信支付
- [self initWechatPay];
- }
- #pragma mark - 初始化微信支付
- - (void)initWechatPay {
- /**微信支付
- 1、导入微信支付SDK,注册微信支付
- 2、设置微信appid为URL schemes
- 3、发起支付,调用微信支付
- 4、处理支付结果
- */
- [WXApi registerApp:@"wx606fa102dbc4b8ab" universalLink:@"https://app.jppt.com.cn/JSJPStudent/"];
- }
- #pragma mark WeChatPay
- - (void)onResp:(BaseResp *)resp {
- 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;
- }
- [RQ_SHARE_FUNCTION showAlertWithTitle:strTitle message:strMsg alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
- }
-
- if ([resp isKindOfClass:[WXLaunchMiniProgramResp class]]) {
- // NSString *string = resp.extMsg;
- // 对应JsApi navigateBackApplication中的extraData字段数据
- }
- }
- //- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL * _Nonnull)url {
- // //这里判断是否发起的请求为微信支付,如果是的话,用WXApi的方法调起微信客户端的支付页面(://pay 之前的那串字符串就是你的APPID,)
- // if ([[NSString stringWithFormat:@"%@",url] rangeOfString:[NSString stringWithFormat:@"%@://pay",APP_ID]].location != NSNotFound) {
- // return [WXApi handleOpenURL:url delegate:self];
- // }
- //
- // return YES;
- //}
- //
- //#pragma mark AliPay
- //- (BOOL)application:(UIApplication *)application
- // openURL:(NSURL *)url
- // sourceApplication:(NSString *)sourceApplication
- // annotation:(id)annotation {
- //
- // if ([url.host isEqualToString:@"safepay"]) {
- // //跳转支付宝钱包进行支付,处理支付结果
- // [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
- // //NSLog(@"PaymentResult 支付结果11--><>%@",resultDic);
- // if ([[resultDic objectForKey:@"resultStatus"] isEqual:@"9000"]) {
- // //支付成功
- // [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_SUCCESSED];
- // }else{
- // [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_FAILED];
- // }
- // }];
- // }
- //
- //
- // //这里判断是否发起的请求为微信支付,如果是的话,用WXApi的方法调起微信客户端的支付页面(://pay 之前的那串字符串就是你的APPID,)
- // if ([[NSString stringWithFormat:@"%@",url] rangeOfString:[NSString stringWithFormat:@"%@://pay",APP_ID]].location != NSNotFound) {
- // return [WXApi handleOpenURL:url delegate:self];
- // }
- // return YES;
- //}
- // NOTE: 9.0以后使用新API接口
- - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
- {
- if ([url.host isEqualToString:@"safepay"]) {
- //跳转支付宝钱包进行支付,处理支付结果
- [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
- //NSLog(@"result 支付结果22--><>%@",resultDic);
- if ([[resultDic objectForKey:@"resultStatus"] isEqual:@"9000"]) {
- //支付成功
- [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_SUCCESSED];
-
- }else{
- [[NSNotificationCenter defaultCenter] postNotificationName:ALI_PAY_RESULT object:ALIPAY_FAILED];
- }
- }];
- }
- //这里判断是否发起的请求为微信支付,如果是的话,用WXApi的方法调起微信客户端的支付页面(://pay 之前的那串字符串就是你的APPID,)
- if ([[NSString stringWithFormat:@"%@",url] rangeOfString:[NSString stringWithFormat:@"%@://pay",APP_ID]].location != NSNotFound) {
- return [WXApi handleOpenURL:url delegate:self];
- }
-
- return YES;
- }
- @end
|