支付宝iOSsdk官方下载sdk地址:https://b.alipay.com/order/productDetail.htm?productId=2013080604609654&tabId=4#ps-tabinfo-hashphp
快捷支付(无线)是一种程序式的支付方式,在手机、掌上电脑等无线设备的应用程序内,买家可经过支付宝进行付款购买特定服务或商品,资金即时到帐。java
第一步:c++
1 公司帐户:企业支付宝帐号就申请 注册企业帐号,若是是我的帐户,就申请个体工商户。api
服务端 负责生成订单及签名,及接受支付异步通知。
客户端 负责使用服务端传来的订单信息调用支付宝支付接口,及根据SDK同步返回的支付结果展现结果页。服务器
私钥必须放在服务端,签名过程必须放在服务端。微信
步骤1:启动IDE(如Xcode),把iOS包中的压缩文件中如下文件拷贝到项目文件夹下,并导入到项目工程中。app
1
2
|
AlipaySDK.bundle
AlipaySDK.framework
|
在Build Phases选项卡的Link Binary With Libraries中,增长如下依赖:dom
其中,须要注意的是:异步
步骤2:在须要调用AlipaySDK的文件中,增长头文件引用。测试
1
|
#
import
<AlipaySDK/AlipaySDK.h>
|
若是你的app基于9.0编译,那么为了适配iOS9.0中的App Transport Security(ATS)对http的限制,这里须要对支付宝的请求地址alipay.com、alipayobjects.com作例外,在app对 应的info.list中添加以下配置(文中以XML格式描述)。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>alipay.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<
true
/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<
true
/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.
0
</string>
<key>NSTemporaryExceptionRequiresForwardSecrecy</key>
<
false
/>
</dict>
<key>alipayobjects.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<
true
/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<
true
/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.
0
</string>
<key>NSTemporaryExceptionRequiresForwardSecrecy</key>
<
false
/>
</dict>
</dict>
</dict>
|
说明:
若是商户配置了以下的配置:
1
2
3
4
|
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><
true
/>
</dict>
|
则上述的NSAppTransportSecurity能够不配置。
步骤3:对接,对接以前,须要索取后台的不少信息
//合做身份者id,以2088开头的16位纯数字
#define PartnerID @"2088一串数字"
//收款支付宝帐号/接口名称
#define SellerID @"2944983890@qq.com"
//支付宝公钥
#define AlipayPubKey @"MIGf一串很长很长信息"
//商户私钥,自助生成
#define PartnerPrivKey @"很长很长很长"
//服务器异步通知页面路径/支付结果,支付宝会通知服务器
alipayNotifServerURL = @
"一个网址"
;
步骤4:配置请求信息。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
Order *order = [[Order alloc] init];
order.partner = partner;
order.seller = seller;
order.tradeNO = [self generateTradeNO];
//订单ID(由商家?自?行制定)
order.productName = product.subject;
//商品标题
order.productDescription = product.body;
//商品描述
order.amount = [NSString stringWithFormat:@
"%.2f"
,product.price];
//商
品价格
order.service = @
"mobile.securitypay.pay"
;
order.paymentType = @
"1"
;
order.inputCharset = @
"utf-8"
;
order.itBPay = @
"30m"
;
//应用注册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) {
//【callback处理支付结果】
NSLog(@
"reslut = %@"
,resultDic);
}];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
|
详细可参见Demo中示例文件
步骤5:调用支付宝
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 对接
在须要调用支付控件的源文件内引用头文件 UPPayPlugin.h 或 UPPayPluginPro.h(注意:若是工程的 compile source as 选项的值不是 Objective–C++,则引用此头文件的文件类型都要改成.mm)
经过调用一下startPay方法
1
2
3
4
|
+ (BOOL)startPay:(NSString*)tn
mode:(NSString*)mode
viewController:(UIViewController*)viewController
delegate:(id)delegate;
|
-------------2个参数说明(必填)-------------------
1
2
3
4
|
tn NSString* 交易流水号信息,银联后台生成,经过商户后台返回到客户端并传入支付控件;
mode NSString* 接入模式设定,两个值:@
"00"
:表明接入生产环境(正式版本须要);@
"01"
:表明接入开发测试环境(测试版本须要);
viewController UIViewController* 商户应用程序调用银联手机支付的当前UIViewController;
delegate id 实现UPPayPluginDelegate方法的UIViewController;
|
嗯,这些都是文档中的,请仔细看看[上线的时候必定要修改mode模式]。
mode在测试环境下,银联给的测试号 tn=@"01" 测试环境
测试使用卡号、手机号信息(此类信息仅供测试,不会发生正式交易)招商银行预付费卡:
银行卡号:6216261000000000018
身份证号:341126197709218366
手 机 号 :13552535506
验 证 码 :123456 【要点击获取验证码,否则提交会报错】
viewcontroller须要干这些事情
*引入头文件 \
#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(@
"支付成功"
);
}
}
3、微信支付
微信sdk下载网址:https://pay.weixin.qq.com/wiki/doc/api/app.php?chapter=11_1
3.1 请去看微信文档和demo
微信支付工做以前的流程: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.php?chapter=8_1
3.2 导入对应的库
1.开发微信APP支付,须要先去微信开放平台申请移动应用,并开通微信支付功能,经过审核后方可进行开发;
2.用XCode打开项目,【项目属性】-【Info】-【URL Schemes】设置微信开放平台申请的应用APPID,如图文件夹下"设置appid.jpg"所示。若是这的APPID设置不正确将没法调起微信支付;
3.须要调用代码注册APPID:[WXApi registerApp:APP_ID withDescription:@"demo 2.0”];项目该APPID需与步骤2中APPID保持一致;
4.支付请求:WXApiRequestHandler.m中的jumpToBizPay方法实现了唤起微信支付;
5.支付完成回调:WXApiManager.m中的onResp方法中接收返回支付状态。
但愿各位多多指教。