美文网首页
支付宝/银联/微信

支付宝/银联/微信

作者: Mr丶炎 | 来源:发表于2016-09-19 19:09 被阅读241次

这是开头语
前不久做了一个项目,涉及到支付宝和银联支付,支付宝和银联都是业界的老大哥,文档、SDK都是很屌,屌的找不到,屌的看不懂,屌到没朋友(吐槽而已),本文将涉及到的最新可用SDK、文档,以及本人支付遇到的一些坑标记一下。
资料

• 支付宝 //文档idk都包含了安卓、iOS版 https://github.com/poholo/alipay
• 银 联 https://github.com/poholo/unionpay
• 银联官网资料 https://open.unionpay.com/upload/download/Development_kit85427986.rar
• Demo https://github.com/poholo/MCPayDemo
Demo给了一个订单号,做测试使用,若出现支付失败什么的,可能是已经被别人给支付了,或者是服务器订单过期了 ~

一、支付宝
1.1 请阅读支付宝文档和Demo
1.2 导入对应的库
将支付宝Demo中得这些东西全拷贝过来

1 localhost:alipay mac$ ls
2 APAuthV2Info.h Order.h libssl.a
3 APAuthV2Info.m Order.m openssl
4 AlipaySDK.bundle Util
5 AlipaySDK.framework libcrypto.a

导入系统

1.SystemConfiguration.framework

设置一下search paths

1 build setting ->搜索search path,然后你懂的完成后,编译一下,看有没有错,有错没错,还是下一步吧。

1.3 对接

支付宝对节前,你还是需要从服务器拿到一下一堆东西
支付宝接口文档中写了3p参数列表,--! 总结下我用的到,或者说是Demo中提到的,别的就超出范围了
1.合作者身份ID alipayPartner = @"2088一串数字";
2.接口名称 alipaySeller = @"edison1992@163.com";
3.签名 aliPayPrivateKey = @"很长很长的私钥";
4.公钥 alipayRSA_PUBLIC=@"一般长"; 客户端不用服务器都给我了--~!
5.服务器异步通知页面路径 alipayNotifServerURL = @"一个网址"; //支付结果,支付宝会通知服务器

其他一些参数(与购买产品相关,设计到业务了,客户端/服务器谁提供均可)直接贴order代码了,具体看我的Demo示例.

  1. Order *order = [[Order alloc] init];
  1. order.partner = alipayPartner ;
  2. order.seller = alipaySeller;
  3. order.tradeNO = tn; 订单ID(由商家自行制定)
  4. order.productName = [NSString stringWithFormat:@"汽车服务充值-%@",@"支付"]; 商品标题
  5. order.productDescription = [NSString stringWithFormat:@"%@:支付宝移动支付充值",@"xxxx"]; 商品描述
  6. order.amount = _txtCNY.text; 商品价格
  7. order.notifyURL = alipayNotifServerURL; 回调URL
  8. order.service = @"mobile.securitypay.pay";
    10.order.paymentType = @"1";
    11.order.inputCharset = @"utf-8";
    12.order.itBPay = @"30m";
    13.order.showUrl = @"m.alipay.com";
    14.应用注册scheme,在AlixPayDemo-Info.plist定义URL types
    15.NSString *appScheme = URLScheme;

调用支付宝

1.[[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme c
allback:^(NSDictionary *resultDic) {

  1. NSLog(@"reslut = %@",resultDic);
  2. if ([resultDic[@"resultStatus"] intValue]==9000) {
  3. 进入充值列表页面
  4. NSLog(@"支付成功"); }
  5. else{
  6. NSString *resultMes = resultDic[@"memo"];
  7. resultMes = (resultMes.length<=0?@"支付失 败":resultless);
    10.NSLog(@"%@",resultMes);
  8.                }
    
  9. }];
    

你可能会发现回调不行->设置回调shema

1 上面支付时已经传给了支付宝客户端回调shema名称
2 NSString *appScheme = URLScheme;
3 具体设置shema方法此处就不再累赘,这儿需要处理来自支付宝shema回调,才能完成上面方法的block回调
4 在APPDelegate -
5 - (BOOL)application:(UIApplication *)application
6 openURL:(NSURL *)url
7 sourceApplication:(NSString *)sourceApplication
8 annotation:(id)annotation {
9 跳转支付宝钱包进行支付,处理支付结果
10 [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
11 NSLog(@"result = %@",resultDic);
12 }];
13 return YES;
14 }

二、银联
2.1 请去看银联文档和demo
2.2 导入对应的库
SDK说明
SDK分为以下两个版本:

1.UPPayPlugin.h
2.UPPayPluginDelegate.h
3.libUPPayPlugin.a

② 支持纯无卡交易和VIPOS音频口支付静态库,以下简称UPPayPluginPro,包含文件:

1.UPPayPluginPro.h
2.UPPayPluginDelegate.h
3.libUPPayPluginPro.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到工程中

导入到工程,让服务器准备一下交易流水号信息 (什么他们不懂,让他们去看文档 银 联https://github.com/poholo/unionpay),休息一下,喝杯什么好了
2.3 对接
咱们的服务器也是挺给力的,一盏茶的功夫,就将交易流水号信息 给准备好了,嗯不错,速度对接一下。

1.+ (BOOL)startPay:(NSString)tn
2.mode:(NSString
)mode
3.viewController:(UIViewController*)viewController
4.delegate:(id)delegate;

-------------参数说明(必填)-------------------

1.tn NSString* 交易流水号信息,银联后台生成,通过商户后台返回到客户端并传入支付控件;
2.mode NSString* 接入模式设定,两个值:@"00":代表接入生产环境(正式版本需要);@"01":代表接入开发测试环境(测试版本需要);
3.viewController UIViewController* 商户应用程序调用银联手机支付的当前UIViewController;
4.delegate id 实现UPPayPluginDelegate方法的UIViewController;嗯,这些都是文档中的,请仔细看看[上线的时候一定药修改mode模式]。
• mode在测试环境下可以银联给的测试号 tn=@"01" 测试环境

• 测试使用卡号、手机号信息(此类信息仅供测试,不会发生正式交易)招商银行预付费卡:
• 卡号:6226 4401 2345 6785
• 密码:111101
• [这个居然无效]
• 再来一个:
• 银行卡号:6216261000000000018
• 身份证号:341126197709218366
• 手 机 号 :13552535506
• 验 证 码 :123456 【要点击获取验证码,不然提交会报错】
viewcontroller需要干这些事情

1.引入头文件 #import "UPPayPluginPro.h"
2.
调用接口
3.[UPPayPluginPro startPay:tn mode:self.tnMode viewController:self delegate:self];
4.*实现对应代理方法
5.#pragma mark UPPayPluginResult
6.- (void)UPPayPluginResult:(NSString *)result
7.{

  1. NSString* msg = [NSString stringWithFormat:@"%@", result];
  2. NSLog(@"msg%@",msg);
  3. if ([result isEqualToString:@"msgcancel"]) {
  4.    NSLog(@"取消银联支付...");
    
  5. }
  6. else if([result containsString:@"success"]){
  7.    NSLog(@"支付成功");
    
  8. }
    16.}

微信支付
微信支付工作之前的流程

https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419317780&token=ac5f0fd38fc8821171addbfdf5cc7d3af93cb305&lang=zh_CN

微信支付文档

https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_1

微信sdk

https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_1

总体来说微信支付需要审核的比较麻烦,我也没有去弄一个号亲自测试一下,按照文档demo去走一般不会出什么问题。
小记

可能遇到银联c++编译问题,把对应的viewcontroller切换成.mm,编译看看。若有CreateRSADataSigner arm64的,请将支付宝给的DataSigner改成.mm即可。
其他可以参照我的demo
https://github.com/poholo/MCPayDemo

相关文章

网友评论

      本文标题:支付宝/银联/微信

      本文链接:https://www.haomeiwen.com/subject/vcynettx.html