zoukankan      html  css  js  c++  java
  • ios 支付宝支付集成

    支付宝支付:

    下载官方demo,把需要的framwork下载下来,在自己的工程中,新建文件夹,然后全部塞进去,到build phases中把需要的全部导入,其中xcode7以上需要多导入两个.a文件,详情参考官方文档
    
    

    需要注意的是:

    • 如果是Xcode 7.0之后的版本,需要添加libc++.tbd、libz.tbd;
    • 如果是Xcode 7.0之前的版本,需要添加libc++.dylib、libz.dylib(如下图)

    //应用注册scheme,在AlixPayDemo-Info.plist定义URL types
    NSString *appScheme = @"alisdkdemo";
    当支付完成后,支付结果需要返回自身APP,需要在plist文件中添加如下设置:
    
    

    两个回调block都统一定义为typedef void(^CompletionBlock)(NSDictionary *resultDic);
    返回了一个字典,但是SDK里完全没有提示有哪些key。。
    你可以在文档里找到,或者自己实际试一下,返回的信息如下:

    • resultStatus,状态码,SDK里没对应信息,第一个文档里有提到:
      • 9000 订单支付成功
      • 8000 正在处理中
      • 4000 订单支付失败
      • 6001 用户中途取消
      • 6002 网络连接出错
    • memo, 提示信息,比如状态码为6001时,memo就是“用户中途取消”。但千万别完全依赖这个信息,如果未安装支付宝app,采用网页支付时,取消时状态码是6001,但这个memo是空的。。(当我发现这个问题的时候,我就决定,对于这么不靠谱的SDK,还是尽量靠自己吧。。)
    • result,订单信息,以及签名验证信息。如果你不想做签名验证,那这个字段可以忽略了。。

    如果你对支付的安全性不那么在意或重视的话,到这里就可以完成支付宝的集成了。
    如果想更加安全,还是需要增加下面的签名验证的。




    下面是详细的调用代码,需要导入头文件:
    #import <AlipaySDK/AlipaySDK.h>
    #import order.h
    等等。。剩下的就是UI界面的配置了~~~~


    -(void)zhiFuBaoPay { Product *product=[[Product alloc]init]; float a =allMoney; float finalPoints=0; if (_currentDJQBtn.selected == YES) { float KDDJQ = [self.model.max_points_fare floatValue]; float KYDJQ = [self.model.points floatValue]; if (KDDJQ>=KYDJQ) { a = a-KYDJQ; finalPoints = KYDJQ; } else{ a =a - KDDJQ; finalPoints = KDDJQ; } } product.price= a; product.subject=@"我连网商品支付"; /*============================================================================*/ /*=======================需要填写商户app申请的===================================*/ /*============================================================================*/ NSString *partner = @"2088501449587500"; NSString *seller = @"1028646629@qq.com"; NSString *privateKey = @"MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAOVv3ZBiCbjBIlUHwFSF0sEm11TXoJRmn1846g5TaWlsSokJK7MO5pPECe4U5jUdw3BvYnarJTtbLAFEaD8POf1xji0BVqQOfEh77aTK/LhEFFfh345Z+Rhqttx2aWya2HU2qADE5MCbRZfk0fMBUj5NBI9sbBU46BZQJ+GWvNtPAgMBAAECgYEA5FLduCiIKi8w/lN3Z+XBJWyEz67B48z4fueBrP3/IeWdix/wOAH1Hknx49cyfNuAuexunU+V/qqtcRllcJOzjQyr2tX1DlIYaaZTgNg0q9zTTjNjUCZVtm1Mx7TK4/Fu30L30dCWPuHjS/dD3TIL59ht0wljjdZGqN6dZEJWMGECQQD4IBmn0+RqW3AdzQoQh1FeZZkaDyaZpiBy7Gi2oy1dZADZ9nFq1tJQpzKGFqQ26loL1p2oIcA3aD09uUdOTME/AkEA7LfuS9DmIqTF/KC4Mz5zySU9fAQIJEjiuHfVcCsTW8s1F4HOb8PA+F1c/MoyxMvYIdV1u3zXUwpSZWQRXSpR8QJAPJCxUnrxTVjGdC/BXil5nh4UkfzSwjx/vS2hnbsU7q/jWVDDfH21VoSJW5uZN+JaWntnfkvGvH+QO0nHcwBfRwJBALTIh9opEQkWNAqKqAKiyISuxzUmUx16+IOPKVd/3kn1eHeacBFVO9OyYejBd2Jql4bHYiGs5zmJIYJDmStAvdECQQCYrmHRSWueQahM9VuBF53tDTp0gqjC0mGGE5SbXtfsdaq9d0Iu2gScY623YSaH6SIg3UM7c6oa6xYUqQH2UDyA"; /*============================================================================*/ /*============================================================================*/ /*============================================================================*/ //partner和seller获取失败,提示 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]; return; } /* *生成订单信息及签名 */ //将商品信息赋予AlixPayOrder的成员变量 Order *order = [[Order alloc] init]; order.partner = partner; order.seller = seller; order.tradeNO = _dingDanHaoLabel.text; //订单ID(由商家自行制定) order.productName = product.subject; //商品标题 order.productDescription = product.body; //商品描述 order.amount = [NSString stringWithFormat:@"%.2f",product.price]; //商品价格 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); //获取私钥并将商户信息签名,外部商户可以根据情况存放私钥和签名,只需要遵循RSA签名规范,并将签名字符串base64编码和UrlEncode 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); if ([resultDic[@"resultStatus"] isEqualToString:@"6001"]) { ZFcgViewController *controller=[[ZFcgViewController alloc]init]; [controller setPayWith:2]; [self.navigationController pushViewController:controller animated:YES]; } else if ([resultDic[@"resultStatus"] isEqualToString:@"9000"]) { //支付成功 if (finalPoints==0) { [self ZFCGJIEKOUWithPWay:@"1" andPoint:@""]; } else { [self ZFCGJIEKOUWithPWay:@"1" andPoint:[NSString stringWithFormat:@"%f",finalPoints]]; } } }]; } }

      

  • 相关阅读:
    ffmpeg 编译IOS静态库
    冲刺总结——第一篇
    openssl基础知识以及部分命令详解
    电子公文传输系统
    第五组课程设计—小组总结
    学习经验总结
    QtCreator:没CDB二进制档可用为二进制格式在'x86windowsmsvc2008pe32bit'"
    printf格式化输出
    DELL T110 安装windows server 2003
    visualSVN+花生壳实现外网访问局域网内SVN
  • 原文地址:https://www.cnblogs.com/damnbird/p/5046723.html
Copyright © 2011-2022 走看看