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;
}