iOS中 最新支付宝支付(AliPay) 韩俊强的博客
Posted lytwajue
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS中 最新支付宝支付(AliPay) 韩俊强的博客相关的知识,希望对你有一定的参考价值。
每日更新关注:http://weibo.com/hanjunqiang
新浪微博
如今的支付方式一般有三种, 支付宝, 微信, 网银. 个人认为最简单易用的还是支付宝, 微信尽管看起来币支付宝要简单,可是后端太麻烦了, 网银就不说了.
先放出官方文档,免得还有人找不到文档:
https://doc.open.alipay.com/doc2/detail?treeId=59&articleId=103563&docType=1
环境搭建
-
下载AliPayDK,官方链接,更新时间:2016/01/28 : http://aopsdkdownload.cn-hangzhou.alipay-pub.aliyun-inc.com/demo/WS_MOBILE_PAY_SDK_BASE.zip?spm=0.0.0.0.y0oP1q&file=WS_MOBILE_PAY_SDK_BASE.zip
假设下载失败,请换个浏览器(至少我用QQ浏览器没有下载成功) -
所需文件导入
1.按下面路径
~/支付宝钱包支付接口开发包2.0标准版(20160120)/DEMO/clientdemo/支付宝钱包支付接口开发包2.0标准版(ios 15.0.6)
找到库文件AlipaySDK.framework和资源包AlipaySDK.bundle拖入到你的project中,
2.AliSDKDemo中libcrypto.a和libssl.a导入到你的project
3.~/AliSDKDemo/AliSDKDemo下的openssl目录,Util目录,Order.h,Order.m拖入project
4.导入下面库
假设是Xcode 7.0之后的版本号,须要加入libc++.tbd、libz.tbd;
假设是Xcode 7.0之前的版本号,须要加入libc++.dylib、libz.dylib
-
project设置改动
-
每日更新关注:http://weibo.com/hanjunqiang 新浪微博
1.info.plist配置
假设是iOS9.0之后(Xcode7.0)在info.plist中添加下面字典
(也能够单独配置,有须要的请看官方文档)
设置Schemes
在info下 URL Types设置你的Schemes
2.Build Settings配置
以keyword“search”搜索,对“Header Search Paths”添加头文件路径:$(SRCROOT)/项目名称
3.这时候编译会报错,错误信息是
Cannot find interface declaration for ‘NSObject‘, superclass of ‘Base64‘
那么须要打开报错了的文件,添加头文件。
import <Foundation/Foundation.h>
再编译,就ok了
每日更新关注:http://weibo.com/hanjunqiang 新浪微博
iOS开发人员交流QQ群:
446310206
支付信息配置
在须要支付的文件里导入头文件
<code class="language-Objective-C hljs vala has-numbering"><span class="hljs-preprocessor">#import <AlipaySDK/AlipaySDK.h></span> <span class="hljs-preprocessor">#import "DataSigner.h"</span> <span class="hljs-preprocessor">#import "Order.h"</span></code>
配置订单信息
这些都是演示样例信息,这些事不能完毕支付的,要以实际信息为准才干完毕支付
<code class="language-Objective-C hljs objectivec has-numbering"><span class="hljs-comment">//商户ID</span> <span class="hljs-built_in">NSString</span> *partner = @<span class="hljs-string">""</span>; <span class="hljs-comment">//收款账户</span> <span class="hljs-built_in">NSString</span> *seller = @<span class="hljs-string">""</span>; <span class="hljs-comment">//私钥</span> <span class="hljs-built_in">NSString</span> *privateKey = @<span class="hljs-string">""</span>; <span class="hljs-keyword">if</span> (partner<span class="hljs-variable">.length</span> == <span class="hljs-number">0</span> || seller<span class="hljs-variable">.length</span> ==<span class="hljs-number">0</span> || privateKey<span class="hljs-variable">.length</span> == <span class="hljs-number">0</span>) { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@<span class="hljs-string">"提示"</span> message:@<span class="hljs-string">"缺少partner或者seller或者私钥。"</span> preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction *action = [UIAlertAction actionWithTitle:@<span class="hljs-string">"确定"</span> style:(UIAlertActionStyleDefault) handler:<span class="hljs-literal">nil</span>]; [alert addAction:action]; [<span class="hljs-keyword">self</span> presentViewController:alert animated:<span class="hljs-literal">YES</span> completion:<span class="hljs-literal">nil</span>]; } <span class="hljs-comment">//订单类</span> Order *order = [[Order alloc]init]; order<span class="hljs-variable">.partner</span> = partner; order<span class="hljs-variable">.seller</span> = seller; order<span class="hljs-variable">.tradeNO</span> = @<span class="hljs-string">"234927348"</span>;<span class="hljs-comment">//订单号</span> order<span class="hljs-variable">.productName</span> = @<span class="hljs-string">"商品名称"</span>; order<span class="hljs-variable">.productDescription</span> = @<span class="hljs-string">"商品描写叙述"</span>; order<span class="hljs-variable">.amount</span> = [<span class="hljs-built_in">NSString</span> stringWithFormat:@<span class="hljs-string">"%.2f"</span>, <span class="hljs-number">0.01</span>];<span class="hljs-comment">//价格</span> order<span class="hljs-variable">.notifyURL</span> = @<span class="hljs-string">"http://blog.csdn.net/fish_yan_?viewmode=list"</span>; <span class="hljs-comment">//回调网址</span> order<span class="hljs-variable">.service</span> = @<span class="hljs-string">"mobile.securitypay.pay"</span>; order<span class="hljs-variable">.paymentType</span> = @<span class="hljs-string">"1"</span>; order<span class="hljs-variable">.inputCharset</span> = @<span class="hljs-string">"utf-8"</span>; order<span class="hljs-variable">.itBPay</span> = @<span class="hljs-string">"30m"</span>; order<span class="hljs-variable">.showUrl</span> = @<span class="hljs-string">"m.alipay.com"</span>; <span class="hljs-built_in">NSString</span> *appScheme = @<span class="hljs-string">"xueyan"</span>; <span class="hljs-comment">//将商品信息拼接成字符串</span> <span class="hljs-built_in">NSString</span> *orderSpec = [order description]; <span class="hljs-comment">//获取私钥并将商户信息签名,外部商户能够依据情况存放私钥和签名,仅仅须要遵循RSA签名规范,并将签名字符串base64编码和UrlEncode</span> <span class="hljs-keyword">id</span><DataSigner> signer = CreateRSADataSigner(privateKey); <span class="hljs-built_in">NSString</span> *signedString = [signer signString:orderSpec]; <span class="hljs-comment">//将签名成功字符串格式化为订单字符串,请严格依照该格式</span> <span class="hljs-built_in">NSString</span> *orderString = <span class="hljs-literal">nil</span>; <span class="hljs-keyword">if</span> (signedString != <span class="hljs-literal">nil</span>) { orderString = [<span class="hljs-built_in">NSString</span> stringWithFormat:@<span class="hljs-string">"%@&sign=\"%@\"&sign_type=\"%@\""</span>, orderSpec, signedString, @<span class="hljs-string">"RSA"</span>]; [[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(<span class="hljs-built_in">NSDictionary</span> *resultDic) { <span class="hljs-comment">//【callback处理支付结果】</span> <span class="hljs-built_in">NSLog</span>(@<span class="hljs-string">"reslut = %@"</span>,resultDic); }]; }</code>
就这么多,假设手机装有支付宝client, 则直接调用client,假设没有client则调用网页版
每日更新关注:http://weibo.com/hanjunqiang
新浪微博
每日更新关注:http://weibo.com/hanjunqiang 新浪微博
上一版本号支付宝支付博文具体解释:http://blog.csdn.net/qq_31810357/article/details/50374378
以上是关于iOS中 最新支付宝支付(AliPay) 韩俊强的博客的主要内容,如果未能解决你的问题,请参考以下文章
iOS支付宝支付(Alipay)详细接入流程以及项目中遇到的问题分析