作者:@lp_马建成
这是开头语
前不久做了一个项目,涉及到支付宝和银联支付,支付宝和银联都是业界的老大哥,文档、SDK都是很屌,屌的找不到,屌的看不懂,屌到没朋友(吐槽而已),本文将涉及到的最新可用SDK、文档,以及本人支付遇到的一些坑标记一下。
资料
Demo给了一个订单号,做测试使用,若出现支付失败什么的,可能是已经被别人给支付了,或者是服务器订单过期了 ~
一、支付宝
1.1 请阅读支付宝文档和Demo
1.2 导入对应的库
将支付宝Demo中得这些东西全拷贝过来
|
1
2
3
4
5
|
localhost:alipay mac$ lsAPAuthV2Info.h Order.h libssl.aAPAuthV2Info.m Order.m opensslAlipaySDK.bundle UtilAlipaySDK.framework libcrypto.a |
导入系统库
|
1
|
SystemConfiguration.framework |
设置一下search paths
|
1
|
build setting ->搜索search path,然后你懂的 |
完成后,编译一下,看有没有错,有错没错,还是下一步吧。
1.3 对接
支付宝对节前,你还是需要从服务器拿到一下一堆东西
支付宝接口文档中写了3p参数列表,--! 总结下我用的到,或者说是Demo中提到的,别的就超出范围了
|
1
2
3
4
5
|
合作者身份ID alipayPartner = @"2088一串数字";接口名称 alipaySeller = @"tianticar@126.com";签名 aliPayPrivateKey = @"很长很长的私钥";//公钥 alipayRSA_PUBLIC=@"一般长"; 客户端不用服务器都给我了--~!服务器异步通知页面路径 alipayNotifServerURL = @"一个网址"; //支付结果,支付宝会通知服务器 |
其他一些参数(与购买产品相关,设计到业务了,客户端/服务器谁提供均可)直接贴order代码了,具体看我的Demo示例.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
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; |
调用支付宝
|
1
2
3
4
5
6
7
8
9
10
11
12
|
[[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
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
//上面支付时已经传给了支付宝客户端回调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;} |
二、银联
2.1 请去看银联文档和demo
2.2 导入对应的库
SDK说明
SDK分为以下两个版本:
① 支持纯无卡交易静态库,以下简称UPPayPlugin,包含文件:
|
1
2
3
|
UPPayPlugin.hUPPayPluginDelegate.hlibUPPayPlugin.a |
② 支持纯无卡交易和VIPOS音频口支付静态库,以下简称UPPayPluginPro,包含文件:
|
1
2
3
|
UPPayPluginPro.hUPPayPluginDelegate.hlibUPPayPluginPro.a |
大概这两个库就是上述那样(嗯,装懂了),具体问商务/后者后台,我们只需要知道
②需要将.m改成.mm (应该是用c++封装的音频...??)
添加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宏;
导入到工程,让服务器准备一下交易流水号信息 (什么他们不懂,让他们去看文档 银 联),休息一下,喝杯什么好了
2.3 对接
咱们的服务器也是挺给力的,一盏茶的功夫,就将交易流水号信息 给准备好了,嗯不错,速度对接一下。
|
1
2
3
4
|
+ (BOOL)startPay:(NSString*)tn mode:(NSString*)mode viewController:(UIViewController*)viewController delegate:(id)delegate; |
-------------参数说明(必填)-------------------
|
1
2
3
4
|
tn NSString* 交易流水号信息,银联后台生成,通过商户后台返回到客户端并传入支付控件; mode NSString* 接入模式设定,两个值:@"00":代表接入生产环境(正式版本需要);@"01":代表接入开发测试环境(测试版本需要);viewController UIViewController* 商户应用程序调用银联手机支付的当前UIViewController;delegate id 实现UPPayPluginDelegate方法的UIViewController; |
嗯,这些都是文档中的,请仔细看看[上线的时候一定药修改mode模式]。
mode在测试环境下可以银联给的测试号 tn=@"01" 测试环境
测试使用卡号、手机号信息(此类信息仅供测试,不会发生正式交易)招商银行预付费卡:
卡号:6226 4401 2345 6785
密码:111101
[这个居然无效]
再来一个:
银行卡号:6216261000000000018
身份证号:341126197709218366
手 机 号 :13552535506
验 证 码 :123456 【要点击获取验证码,不然提交会报错】
viewcontroller需要干这些事情
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
*引入头文件 \#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(@"支付成功"); } } |
微信支付
总体来说微信支付需要审核的比较麻烦,我也没有去弄一个号亲自测试一下,按照文档demo去走一般不会出什么问题。
小记
可能遇到银联c++编译问题,把对应的viewcontroller切换成.mm,编译看看。若有CreateRSADataSigner arm64的,请将支付宝给的DataSigner改成.mm即可。
原文:http://www.cnblogs.com/easyToCode/p/5196327.html