标签:
支付宝支付 -- 适配iOS9
首先我们一起看一下,最终调起支付宝完成支付的必要参数和方法(Order类由支付宝demo中提供)
1 Order *order = [Order new]; 2 order.partner = kAliPayPartner; 3 order.seller = kAliPaySeller; 4 order.tradeNO = @"111"; 5 order.productName = @"阿里支付test商品"; //商品标题 6 order.productDescription = @"阿里支付test商品描述"; //商品描述 7 order.amount = @"0.01"; //商品价格 8 order.notifyURL = @"http://www.xxx.com"; //回调URL 9 10 order.service = @"mobile.securitypay.pay"; 11 order.paymentType = @"1"; 12 order.inputCharset = @"utf-8"; 13 order.itBPay = @"30m"; 14 order.showUrl = @"m.alipay.com"; 15 16 // 应用注册scheme 17 NSString *appScheme = @"aliPay"; 18 19 //将商品信息拼接成字符串 20 NSString *orderSpec = [order description]; 21 NSLog(@"orderSpec = %@",orderSpec); 22 23 //获取私钥并将商户信息签名,外部商户可以根据情况存放私钥和签名,只需要遵循RSA签名规范,并将签名字符串base64编码和UrlEncode 24 id<DataSigner> signer = CreateRSADataSigner(kAliPayPrivateKey); 25 NSString *signedString = [signer signString:orderSpec]; 26 27 //将签名成功字符串格式化为订单字符串,请严格按照该格式 28 NSString *orderString = nil; 29 if (signedString != nil) { 30 orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"", 31 orderSpec, signedString, @"RSA"]; 32 33 [[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) { 34 NSLog(@"reslut = %@",resultDic); 35 }]; 36 37 }
1.到支付宝开放平台申请移动支付资质,并创建应用,得到
partner : 2088121154111111 (参考格式)
seller:即支付宝账号,例如邮箱号手机号等
https://open.alipay.com/platform/home.htm
2.下载demo,并将下列类库文件等加入工程
AlipaySDK.bundle
AlipaySDK.framework
Order类
openssl文件夹
Util文件夹
3.在buildPhases选项卡的LinkBinaryWithLibraries中,添加系统依赖库
1 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 2 { 3 4 //如果极简开发包不可用,会跳转支付宝钱包进行支付,需要将支付宝钱包的支付结果回传给开发包 5 if ([url.host isEqualToString:@"safepay"]) { 6 [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) { 7 //【由于在跳转支付宝客户端支付的过程中,商户app在后台很可能被系统kill了,所以pay接口的callback就会失效,请商户对standbyCallback返回的回调结果进行处理,就是在这个方法里面处理跟callback一样的逻辑】 8 NSLog(@"result = %@",resultDic); 9 }]; 10 } 11 if ([url.host isEqualToString:@"platformapi"]){//支付宝钱包快登授权返回authCode 12 13 [[AlipaySDK defaultService] processAuthResult:url standbyCallback:^(NSDictionary *resultDic) { 14 //【由于在跳转支付宝客户端支付的过程中,商户app在后台很可能被系统kill了,所以pay接口的callback就会失效,请商户对standbyCallback返回的回调结果进行处理,就是在这个方法里面处理跟callback一样的逻辑】 15 NSLog(@"result = %@",resultDic); 16 }]; 17 } 18 return YES; 19 }
1 <key>NSAppTransportSecurity</key> 2 <dict> 3 <key>NSExceptionDomains</key> 4 <dict> 5 <key>alipay.com</key> 6 <dict> 7 <key>NSIncludesSubdomains</key> 8 <true/> 9 <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> 10 <true/> 11 <key>NSTemporaryExceptionMinimumTLSVersion</key> 12 <string>TLSv1.0</string> 13 <key>NSTemporaryExceptionRequiresForwardSecrecy</key> 14 <false/> 15 </dict> 16 <key>alipayobjects.com</key> 17 <dict> 18 <key>NSIncludesSubdomains</key> 19 <true/> 20 <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> 21 <true/> 22 <key>NSTemporaryExceptionMinimumTLSVersion</key> 23 <string>TLSv1.0</string> 24 <key>NSTemporaryExceptionRequiresForwardSecrecy</key> 25 <false/> 26 </dict> 27 </dict> 28 </dict>
2.工程未使用https,并对NSAppTransportSecurity下NSAllowsArbitraryLoads设置为true
再次运行. 支付一个试试 呵呵. 应该成功了标签:
原文地址:http://www.cnblogs.com/aaalice/p/5078419.html