美文网首页
Alipay--支付宝支付

Alipay--支付宝支付

作者: Goldfish_jinyu | 来源:发表于2016-06-22 16:57 被阅读232次

我是使用的cocoapods来做的,这样就省了手动添加这一步。没有安装 cocoapods的同学请点击这里
一般看官方文档接入的话确实会走不少弯路,其实过程很简单要自己摸索着一步步来,好了我们开始。
http://blog.csdn.net/wtt692732757/article/details/50966893
http://www.jianshu.com/p/32cea46e74cd

客户端:负责使用服务端传来的订单信息调用支付宝支付接口,及根据SDK同步返回的支付结果展示结果页。

  • 支付宝移动支付接入我们的app的时候,首先是要先与支付宝签约,然后得到我们的
    partner//签约的支付宝账号唯一ID
    seller//卖家支付宝账号
    privateKey//私钥

    一般这三个都是放在服务端 
生成私钥
  • 私钥公钥一定是要对应的
    生成私钥的方法

RSA密钥生成命令
1. 进入终端,输入
“openssl”
2. 生成RSA私钥
openssl>genrsa -out rsa_private_key.pem 1024
3. 生成RSA公钥
openssl>rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem
4. 将RSA私钥转换成PKCS8格式
openssl>pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM -nocrypt

注意:“>”符号后面的才是需要输入的命令。
  • 得到公钥私钥之后在你的账户合作伙伴密钥里填写公钥(私钥放在你的项目中或者服务器端)
支付宝设置公钥私钥截图
  • 这里是支付宝SDK的下载页面。我就是官方地址
    或者使用cocoa pods直接安装。(我是使用的cocoa pods安装的)

我们下载的官方demo中

文件

在配置订单信息之前,因为要遵循RSA签名规范,所以我们还要把文档里的libcrypto.a , libssl.a , openssl , Util , Order.h , Order.m APAuthV2Info.h APAuthV2Info.m 拖入工程。

之后项目会报错说找不到<openssl/opensslconf.h> 这时不要慌我们找到 Targets -> Build Settings 下的 Header Search Paths 然后添加

$(SRCROOT)/项目名称/文件的绝对地址

这样就不会报错了

  • 现在我们可以开始写代码了
    头文件
添加头文件
//点击支付
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    /*============================================================================*/
    /*=======================需要填写商户app申请的===================================*/
    /*============================================================================*/
    NSString *partner = @"";//签约的支付宝账号唯一ID
    NSString *seller = @"";//卖家支付宝账号
    NSString *privateKey =@"";//私钥

    if ([partner length] == 0 ||
        [seller length] == 0 ||
        [privateKey length] == 0)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                        message:@"缺少partner或者seller或者私钥。"
                                                       delegate:self
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil];
        [alert show];
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        return;
    }
    
    
//    生成订单和签名
    
    Order * order = [[Order alloc]init];
    order.partner = partner;
    order.seller  = seller;
    order.tradeNO = @"1234567810";
    order.productName = @"测试数据1";
    order.productDescription = @"四月五号下午";
    order.amount = @"0.01";
    order.notifyURL = @"http:www.xxx.com";//回调给服务器的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 = @"alisdkdemo";
    
    
    NSString * orderSpec = [order description];
    NSLog(@"orderspec = %@",orderSpec);
    
    
    id<DataSigner> signer = CreateRSADataSigner(privateKey);
    NSString * signedstring = [signer signString:orderSpec];
    
    //将签名成功字符串格式化为订单字符串,请严格按照该格式
    NSString *orderString = nil;
    if (signedstring != nil) {
        orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",
                       orderSpec, signedstring, @"RSA"];
        
        [[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
            NSLog(@"reslut = %@",[resultDic objectForKey:@"memo"]);
        }];
    }
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

最后说一句 在AppDelegate.m里面写的回调方法,我一直没搞懂有什么作用文档说要写就写了好像并没有什么用 但是为了保险还是写上比较好

-(BOOL)application:(UIApplication *)app openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<NSString *,id> *)options{
   if([url.host isEqualToString:@"safepay"]){
       [[AlipaySDK defaultService]processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
           NSLog(@"resultshi =   %@",[resultDic objectForKey:@"memo"]);
       }];
   }
   return YES;
}

相关文章

  • Alipay--支付宝支付

    我是使用的cocoapods来做的,这样就省了手动添加这一步。没有安装 cocoapods的同学请点击这里一般看官...

  • Android支付宝支付集成

    Android支付宝支付 标签: android Android支付宝支付使用的流程介绍 支付宝流程介绍 支付宝流...

  • ## [iOS 支付宝支付]

    [iOS开发系列-支付宝支付] 概述 开发中支付通常都会集成支付宝支付,下面讲解支付宝的整体流程。 集成支付宝支付...

  • 三方支付流程总结

    支付宝支付和微信支付 支付宝支付流程图: 支付宝支付: 当我们选择点击了支付宝支付按钮开始 1.app选择商品进行...

  • iOS支付

    支付宝支付 支付宝支付支付宝补充 微信支付 微信支付 内购 iOS开发 内购流程

  • 奖品合集

    支付宝44.44x12 支付宝200x1 支付宝121x1 支付宝111x1 支付宝100x1 支付宝88x1 支...

  • 对接支付宝支付接口开发笔记

    支付宝对接学习笔记: 功能介绍: 支付宝对接 支付宝回调 查询支付状态(略过不讲) 要求: 熟悉支付宝对接核心文档...

  • iOS集成支付宝支付

    一、支付宝支付,首先利用CocoaPods,导入支付宝SDK 二、 创建支付宝支付管理类 AlipayManag...

  • 历害word哥,支付宝AR红包风靡朋友圈

    支付宝又来搞事情,2016年12月22日,支付宝又出新玩法:支付宝AR红包! 支付宝用户可以利用支付宝的红包功能:...

  • iOS支付宝功能集成

    iOS快速集成支付宝详解/支付宝集成获取私钥与公钥 在集成支付宝功能前,我们必须了解下什么支付宝流程,下图是支付宝...

网友评论

      本文标题:Alipay--支付宝支付

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