在做iOS支付相关的项目时,必不可少的会涉及到支付宝,银联,微信支付三座大山
供参考的demo
支付宝
https://github.com/poholo/alipay
银联
https://github.com/poholo/unionpay
支付宝
当在使用其他SDK时,必须要做的一件事
阅读支付宝和demo【此废话适合所有】
①----支付宝
1.导入支付宝需要的对应的库
将支付宝Demo中的下列文件拷贝到需要集成的项目中去
APAuthV2Info.h
APAuthV2Info.m
合作者身份ID alipayPartner = @
"12345678XXXX"
;
接口名称 alipaySeller = @
"zhan@163.com"
;
签名 aliPayPrivateKey = @
"私钥"
;
//公钥 alipayRSA_PUBLIC=@"一般长"; 客户端不用服务器
服务器异步通知页面路径 alipayNotifServerURL = @
"一个网址"
;
//支付结果,支付宝会通知服务器
Order \*order = [[Order alloc] init];
order.partner = alipayPartner ;
order.seller = alipaySeller;
order.tradeNO = tn;
//订单ID(由商家自行制定)
order.productName = [NSString stringWithFormat:@
"汽车服务充值-%@"
,@
"支付"
];
//商品标题
order.productDescription = [NSString stringWithFormat:@
"%@:支付宝移动支付充值"
,@
"xxxx"
];
//商品描述
order.amount = _txtCNY.text;
//商品价格
order.notifyURL = alipayNotifServerURL;
//回调URL
order.service = @
"mobile.securitypay.pay"
;
order.paymentType = @
"1"
;
order.inputCharset = @
"utf-8"
;
order.itBPay = @
"30m"
;
order.showUrl = @
"m.alipay.com"
;
//应用注册scheme,在AlixPayDemo-Info.plist定义URL types
NSString *appScheme = URLScheme;
[[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
NSLog(@
"reslut = %@"
,resultDic);
if
([resultDic[@
"resultStatus"
] intValue]==9000) {
//进入充值列表页面
NSLog(@
"支付成功"
);
}
else
{
NSString *resultMes = resultDic[@
"memo"
];
resultMes = (resultMes.length<=0?@
"支付失败"
:resultMes);
NSLog(@
"%@"
,resultMes);
}
}];
//上面支付时已经传给了支付宝客户端回调shema名称
NSString *appScheme = URLScheme;
//具体设置shema方法此处就不再累赘,这儿需要处理来自支付宝shema回调,才能完成上面方法的block回调
在APPDelegate -
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
//跳转支付宝钱包进行支付,处理支付结果
[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
NSLog(@
"result = %@"
,resultDic);
}];
return
YES;
}
②---银联
参照银联demo
第一步:导入库
SDK说明
SDK分为以下两个版本:
1>支持纯无卡交易静态库,以下简称UPPayPlugin,包含文件:
UPPayPlugin.h
UPPayPluginDelegate.h
libUPPayPlugin.a
2>支持纯无法交易和VIPOS音频口支付静态库,以下简称UPPayPluginPro,包含的文件:
UPPayPluginPro.h
UPPayPluginDelegate.h
libUPPayPluginPro.a
需要将.m改成.mm
添加SDK包
a) 根据商户选择的SDK版本,将sdk/inc目录和sdk/libs目录下对应版本的三个文件添加到UPPayDemo工程中;
b) 如果你选择的是UPPayPlugin版本,添加QuartzCore.framework、Security.framework到工程中;
c) 如果你选择的是UPPayPluginPro版本,添加QuartzCore.framework、AudioToolbox.framework, CoreAudio.framework、 MediaPlayer.framework, AVFoundation.framework和Security.framework到工程中;
d) 在工程的Build Settings中找到Other Linker Flags中添加-ObjC宏;
导入到工程,让服务器提供交易流水号信息
接下来第二大步:对接
拿到咱们服务器给的流水号信息
+ (BOOL)startPay:(NSString*)tn
mode:(NSString*)mode
viewController:(UIViewController*)viewController
delegate:(id)delegate;
参数说明:
tn NSString* 交易流水号信息,银联后台生成,通过商户后台返回到客户端并传入支付控件;
mode NSString* 接入模式设定,两个值:@
"00"
:代表接入生产环境(正式版本需要);@
"01"
:代表接入开发测试环境(测试版本需要);
viewController UIViewController* 商户应用程序调用银联手机支付的当前UIViewController;
delegate id 实现UPPayPluginDelegate方法的UIViewController;
嗯,这些都是文档中的,请仔细看看[上线的时候一定药修改mode模式]。
mode在测试环境下可以银联给的测试号 tn=@"01" 测试环境
-
测试使用卡号、手机号信息(此类信息仅供测试,不会发生正式交易)招商银行预付费卡:
-
银行卡号:6216261000000000018
-
身份证号:341126197709218366
-
手 机 号 :13552535506
-
验 证 码 :123456 【要点击获取验证码,不然提交会报错】
*引入头文件 \
#import "UPPayPluginPro.h"
*调用接口
[UPPayPluginPro startPay:tn mode:self.tnMode viewController:self delegate:self];
*实现对应代理方法
\
#pragma mark UPPayPluginResult
- (void)UPPayPluginResult:(NSString \*)result
{
NSString\* msg = [NSString stringWithFormat:@
"%@"
, result];
NSLog(@
"msg%@"
,msg);
if
([result isEqualToString:@
"msgcancel"
]) {
NSLog(@
"取消银联支付..."
);
}
else
if
([result containsString:@
"success"
]){
NSLog(@
"支付成功"
);
}
}
③微信支付
微信支付工作之前的流程
https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419317780&token=ac5f0fd38fc8821171addbfdf5cc7d3af93cb305&lang=zh_CN
小记
可能遇到银联c++编译问题,把对应的viewcontroller切换成.mm,编译看看。若有CreateRSADataSigner arm64的,请将支付宝给的DataSigner改成.mm即可。
仔细读demo即可