zoukankan      html  css  js  c++  java
  • iOS----支付(微信支付、支付宝支付、银联支付控件集成支付)(转)

    资料

    Demo给了一个订单号,做测试使用,若出现支付失败什么的,可能是已经被别人给支付了,或者是服务器订单过期了 ~

    一、支付宝

    1.1 请阅读支付宝文档和Demo

    1.2 导入对应的库

    将支付宝Demo中得这些东西全拷贝过来

    1
    2
    3
    4
    5
    localhost:alipay mac$ ls
    APAuthV2Info.h        Order.h            libssl.a
    APAuthV2Info.m        Order.m            openssl
    AlipaySDK.bundle    Util
    AlipaySDK.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.h
    UPPayPluginDelegate.h
    libUPPayPlugin.a

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

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

    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(@"支付成功");
                }
          }

    微信支付

    微信支付工作之前的流程

    微信支付文档

    微信sdk

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

    小记

    可能遇到银联c++编译问题,把对应的viewcontroller切换成.mm,编译看看。若有CreateRSADataSigner arm64的,请将支付宝给的DataSigner改成.mm即可。

    其他可以参照demo

  • 相关阅读:
    决定你人生高度的,不是你的才能,而是你的态度
    享受六一的最后几分钟
    DB9 公头母头引脚定义及连接
    bzoj3207--Hash+主席树
    bzoj1901 [ Zju2112 ] --树状数组套主席树
    bzoj1723 [ Usaco2009 Feb ] --前缀和(水题)
    bzoj3932 [ CQOI2015 ] --可持久化线段树
    bzoj3037--贪心
    bzoj3388 [ Usaco2004 Dec ] (神奇的解法)
    bzoj2693--莫比乌斯反演+积性函数线性筛
  • 原文地址:https://www.cnblogs.com/LifeTechnologySupporter/p/5026029.html
Copyright © 2011-2022 走看看