「IOS」支付宝APP支付
1. App支付iOS集成
按照支付宝的官方文档就可以集成,很顺利。但是有16处warning。
warning: (arm64) /Users/tommy/Desktop/Project/AliPay/Cornerstone/standard/1520_cp_record_client_release_828632/AlipaySDK4Standard/AlipaySDK/Library/UTDID.framework/UTDID(UTDIDAES.o) unable to open object file: No such file or directory
看在运行官方提供的支付宝DEMO中也会有此处的warning,所以此处等日后优化处理。
2.组装请求信息。
TIPS:这一步应在商户服务端完成,商户服务端直接将组装和签名后的请求串orderString传给客户端,客户端直接传给SDK发起请求。
步骤如下:
1.整合信息,将商品信息拼接成字符串。
1.appID; //appId
2.method = “alipay.trade.app.pay"; //固定写法
3.charset = "utf-8";
4.timestamp
5.version = "1.0";
6.sign_type = “RSA"; //固定写法
// NOTE: 商品数据
7.biz_content;
8.biz_content.body =“ ”; //”我是测试数据”;
9.biz_content.subject = "1";
10.biz_content.out_trade_no = ‘’ //订单ID(由商家自行制定)
11.biz_content.timeout_express = "30m"; //超时时间设置
7.total_amount //商品价格
例如app_id=2088421490941334&biz_content={"timeout_express":"30m","seller_id":"","product_code":"QUICK_MSECURITY_PAY","total_amount":"0.01","subject":"1","body":"我是测试数据","out_trade_no":"2W198CASQ6769ID"}&charset=utf-8&method=alipay.trade.app.pay&sign_type=RSA×tamp=2016-11-15 15:28:58&version=1.0
2. 商品信息加密
例如:
app_id=2088421490941334&biz_content=%7B%22timeout_express%22%3A%2230m%22%2C%22seller_id%22%3A%22%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22total_amount%22%3A%220.01%22%2C%22subject%22%3A%221%22%2C%22body%22%3A%22%E6%88%91%E6%98%AF%E6%B5%8B%E8%AF%95%E6%95%B0%E6%8D%AE%22%2C%22out_trade_no%22%3A%22E51W0J0WBHP5J8E%22%7D&charset=utf-8&method=alipay.trade.app.pay&sign_type=RSA×tamp=2016-11-15%2015%3A45%3A22&version=1.0
3. // NOTE: 获取私钥并将商户信息签名,需要遵循RSA签名规范,并将签名字符串base64编码和UrlEncode
例如:
signedString = vUhZosbhfwep6IXN99%2BI%2FZrRj3o81%2Fy0Fh5Oxt2r4VtVgkChwye9jfMHABra%2Bija77NeHm%2FcchelshtxTkp%2B%2FRaFFC34re%2FQlW51WxFKlGMxhM%2FNRm1r42rlqtSjiOjM1vWCQ%2FQDRs837WVwKRSAb4kD7OUDcHSU6k4cMsQGGwQ%3D
4.将签名成功字符串格式化为订单字符串,请严格按照该格式orderInfoEncoded&signedString。
app_id=2088421490941334&biz_content=%7B%22timeout_express%22%3A%2230m%22%2C%22seller_id%22%3A%22%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22total_amount%22%3A%220.01%22%2C%22subject%22%3A%221%22%2C%22body%22%3A%22%E6%88%91%E6%98%AF%E6%B5%8B%E8%AF%95%E6%95%B0%E6%8D%AE%22%2C%22out_trade_no%22%3A%22E51W0J0WBHP5J8E%22%7D&charset=utf-8&method=alipay.trade.app.pay&sign_type=RSA×tamp=2016-11-15%2015%3A45%3A22&version=1.0&sign=vUhZosbhfwep6IXN99%2BI%2FZrRj3o81%2Fy0Fh5Oxt2r4VtVgkChwye9jfMHABra%2Bija77NeHm%2FcchelshtxTkp%2B%2FRaFFC34re%2FQlW51WxFKlGMxhM%2FNRm1r42rlqtSjiOjM1vWCQ%2FQDRs837WVwKRSAb4kD7OUDcHSU6k4cMsQGGwQ%3D
把此字符串提供给终端进行唤起。
3.配置支付宝客户端返回url处理方法。
NOTE: 9.0以后使用新API接口
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary*)options{
if ([url.host isEqualToString:@"safepay"]) {
//跳转支付宝钱包进行支付,处理支付结果
[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
NSLog(@"result = %@",resultDic);
}];
}
return YES;
}
这里要注意的是此事件openURL 会在appDelegate 多次共同调用(如微信,支付宝,微博,QQ)等,一定要做好多事件的适配。适配方式其实很简单,通过配置的URL Schemes 就可以区分。