IOS支付宝支付流程

一、集成和配置。

      1、签名注册AppKey 我们是由后台完成。

      2、我用cocoapods集成

            pod 'AlipaySDK-iOS'

      3、需要在info文件 URL Types中建一个URL Schems 支付宝返回应用用到,和跳转时schemeStr设置一样就行。

二、代码实现

      1、AppDelegate 的代码实现

           # import <AlipaySDK/AlipaySDK.h>支付宝

      - (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(@"result = %@",resultDic); }]; } 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 = %@",resultDic); //发送支付成功通知 [[NSNotificationCenter defaultCenter] postNotificationName:ReturnSucceedPayNotification object:nil]; }]; } if ([url.host isEqualToString:@"platformapi"]){//支付宝钱包快登授权返回authCode [[AlipaySDK defaultService] processAuthResult:url standbyCallback:^(NSDictionary *resultDic) { //【由于在跳转支付宝客户端支付的过程中,商户app在后台很可能被系统kill了,所以pay接口的callback就会失效,请商户对standbyCallback返回的回调结果进行处理,就是在这个方法里面处理跟callback一样的逻辑】 NSLog(@"platformapi result = %@",resultDic); //发送支付失败通知 [[NSNotificationCenter defaultCenter] postNotificationName:ReturnSucceedPayNotification object:nil]; } ];}; return YES; }

2、签名和拼接在后台,APP不在进行二次签名,向后台创建单子返回数据为

     3、获取返回的sign,跳转支付宝进行支付

        NSString *appScheme = @"PayAppScheme";       //跟info文件 URL Types中Schems一致。
        NSString *orderString = [self.payDict objectForKey:@"sign"];
       [[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
          NSLog(@"reslut = %@",resultDic);
       }];

 
 

猜你喜欢

转载自www.cnblogs.com/xiyangxixia/p/10929167.html