支付宝集成核心问题总结

本文总结了支付宝集成过程中的核心问题,包括应用内scheme的注册以确保支付回调的正常进行,以及在AppDelegate中处理iOS9及以后版本的支付回调结果适配。同时,对于客户端未安装支付宝APP时的网页支付情况也进行了说明。

1.scheme 注册

应用注册scheme,在AlixPayDemo-Info.plist定义URL types,appScheme会用在支付宝客户端支付回调中,因此必须在本应用中注册scheme,保证唯一。如何添加scheme,点击查看详情

  NSString *appScheme = @"aliPayDemo";
 [[AlipaySDK defaultService] payOrder:str fromScheme:appScheme callback:^(NSDictionary *resultDic) {
            NSLog(@"reslut = %@",resultDic);

        }];

2.处理支付回调结果

支付宝支付回调结果在AppDelegate中通过openURL返回。
2.1但由于IOS9,该接口发生变化,因此2个接口都需要进行适配;
2.2由于客户端没有安装支付宝APP的话,会调用网页进行支付,所以同样存在2中状态,需要分别处理

//IOS9.0 DEPRECATED
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation{

    if ([sourceApplication isEqualToString:@"com.alipay.iphoneclient"]) {

        if ([url.host isEqualToString:@"safepay"]) {
            [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {

            }];

            [[AlipaySDK defaultService] processAuth_V2Result:url
                                             standbyCallback:^(NSDictionary *resultDic) {
                                                 NSLog(@"result = %@",resultDic);
                                                 NSString *resultStr = resultDic[@"result"];
                                                 NSLog(@"result = %@",resultStr);
                                             }];
        } else if ([url.host isEqualToString:@"platformapi"]){
        //支付宝钱包快登授权返回 authCode
            [[AlipaySDK defaultService] processAuthResult:url standbyCallback:^(NSDictionary *resultDic) {
                NSLog(@"result = %@",resultDic);
            }];
        }

    }
    return YES;
}
//IOS9.0 
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options{


    if ([[options valueForKey:UIApplicationOpenURLOptionsSourceApplicationKey] isEqualToString:@"com.alipay.iphoneclient"]) {

        if ([url.host isEqualToString:@"safepay"]) {
            [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {

            }];

            [[AlipaySDK defaultService] processAuth_V2Result:url
                                             standbyCallback:^(NSDictionary *resultDic) {
                                                 NSLog(@"result = %@",resultDic);
                                                 NSString *resultStr = resultDic[@"result"];
                                                 NSLog(@"result = %@",resultStr);
                                             }];
//支付宝钱包快登授权返回 authCode
            [[AlipaySDK defaultService] processAuthResult:url standbyCallback:^(NSDictionary *resultDic) {
                NSLog(@"result = %@",resultDic);
            }];
        }

    }


    return YES;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值