一、支付宝支付要注意的问题:
导入AlipaySDk,预编译一下,这是会发现会有好多错误:
错误一:
解决办法:
这个是要添加pch文件并配置
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
错误二:
解决办法:在Header Search Paths 配置路径
错误三:
添加依赖库:
白名单配置:info.plist
iOS 9系统策略更新,应用需要在“Info.plist”中将要使用的URL Schemes列为白名单,才可正常检查其他应用是否安装。
各个平台白名单说明:
http://blog.csdn.net/hou3035/article/details/50843217
URL Types配置:
特别注意:
/**
重要说明
privateKey等数据严禁放在客户端,加签过程务必要放在服务端完成;
防止商户私密数据泄露,造成不必要的资金损失,及面临各种安全风险;
*/
/*
*生成订单信息及签名
*/
//将商品信息赋予AlixPayOrder的成员变量
Order* order = [Order new];
// NOTE: app_id设置
order.app_id = appID;
// NOTE: 支付接口名称
order.method = @"alipay.trade.app.pay";
// NOTE: 参数编码格式
order.charset = @"utf-8";
// NOTE: 当前时间点
NSDateFormatter* formatter = [NSDateFormatter new];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
order.timestamp = [formatter stringFromDate:[NSDate date]];
// NOTE: 支付版本
order.version = @"1.0";
// NOTE: sign_type 根据商户设置的私钥来决定
order.sign_type = (rsa2PrivateKey.length > 1)?@"RSA2":@"RSA";
// NOTE: 商品数据
order.biz_content = [BizContent new];
order.biz_content.body = @"我是测试数据";
order.biz_content.subject = @"1";
order.biz_content.out_trade_no = [self generateTradeNO]; //订单ID(由商家自行制定)
order.biz_content.timeout_express = @"30m"; //超时时间设置
order.biz_content.total_amount = [NSString stringWithFormat:@"%.2f", 0.01]; //商品价格
//将商品信息拼接成字符串
NSString *orderInfo = [order orderInfoEncoded:NO];
NSString *orderInfoEncoded = [order orderInfoEncoded:YES];
NSLog(@"orderSpec = %@",orderInfo);
// NOTE: 获取私钥并将商户信息签名,外部商户的加签过程请务必放在服务端,防止公私钥数据泄露;
// 需要遵循RSA签名规范,并将签名字符串base64编码和UrlEncode
NSString *signedString = nil;
RSADataSigner* signer = [[RSADataSigner alloc] initWithPrivateKey:((rsa2PrivateKey.length > 1)?rsa2PrivateKey:rsaPrivateKey)];
if ((rsa2PrivateKey.length > 1)) {
signedString = [signer signString:orderInfo withRSA2:YES];
} else {
signedString = [signer signString:orderInfo withRSA2:NO];
}
// NOTE: 如果加签成功,则继续执行支付
if (signedString != nil) {
//应用注册scheme,在AliSDKDemo-Info.plist定义URL types
NSString *appScheme = @"alisdkdemo";
// NOTE: 将签名成功字符串格式化为订单字符串,请严格按照该格式
NSString *orderString = [NSString stringWithFormat:@"%@&sign=%@",
orderInfoEncoded, signedString];
二、微信支付要注意的问题:
1.白名单、URL Types配置问题和支付宝一样,不再说明。
2.app注册微信crash,代码如下:
[WXApi registerApp:appId withDescription:description];
解决方案:Targets -> Bulid setting -> Other Linker Flags
3.依赖库在支付宝中已经说明。
4.和支付宝不一样,微信如果没有安装是不会跳转到微信网页支付的,支付宝就不存在这个问题,所以微信在调起支付的时候要判断是否已经安装微信。
if([WXApi isWXAppInstalled])
{
PayReq *req = [[PayReq alloc] init];
req.openID = appId;
req.partnerId = partnerId;
req.prepayId = prepayId;
req.package = package;
req.nonceStr = nonceStr;
req.timeStamp = (UInt32)timeStamp.integerValue;
req.sign = sign;
[WXApi sendReq:req];
}
else
{
if(self.WXPayResponseBlock)
{
self.WXPayResponseBlock(-3, @"未安装微信");
}
}
字段说明:
@param appId 微信开放平台审核通过的应用APPID
@param partnerId 微信支付分配的商户号
@param prepayId 微信生成的预支付回话标识,该值有效期为2小时
@param package 暂填写固定值Sign=WXPay
@param nonceStr 随机字符串,不长于32位。推荐随机数生成算法
@param timeStamp 时间戳,请见接口规则-参数规定
@param sign 签名,详见签名生成算法
注意:
和支付宝一样,这些信息都要从服务端获取,严禁放在客户端。
三、 银联支付
银联支付基本上没有什么坑,用起来也比较简单,就是SDK比较难找。
https://open.unionpay.com/ajweb/help/file/techFile?productId=3
关于配置问题就不说了,和支付宝、微信支付一样,提供一篇文章非常详细。
http://blog.csdn.net/lxlzy/article/details/53338278
下面是个人封装的三种支付,可做参考:
https://github.com/DeveloperiMichael/SAPlatformPayManager