id="cproIframe_u2394728_1" width="728" height="90" src="http://pos.baidu.com/acom?adn=1&at=38&aurl=&cad=1&ccd=24&cec=UTF-8&cfv=19&ch=0&col=zh-CN&conOP=0&cpa=1&dai=1&dis=0<r=https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DHoEYvkz9nkC_KLMPvvLZWEepPrr4UG1joTG712zdJK5zZsXdNA5uLIorbhYs7lx1io8i1Ir8pmksBlsVEj_cchE_QlrBwig16vzD71jwX2zqoNnshKVTcfLhQrmRRRP1Rpqk2PGysSK3TZLXH6vlnX4wj7UXE0M3KVNEteg7PitMmlKHT_PgcbEjlq6_EFLD0nXaY7gl3lrjKABKtWbB8rPUo0rTo4Nve_SJo4EwwY_9oFpUFyaQDBGKP6gHmMPzCDNbsqYO99yTLcGZ9zcpbq%26wd%3D%26eqid%3Dc948e0f8000006da0000000356499e8e<u=http%3A%2F%2Fwww.mikel.cn%2F%25E5%25BC%2580%25E5%258F%2591%25E7%25AC%2594%25E8%25AE%25B0%2F%25E8%25BD%25AC%25E8%25BD%25BDios-%25E5%25A6%2582%25E4%25BD%2595%25E9%259B%2586%25E6%2588%2590%25E6%2594%25AF%25E4%25BB%2598%25E5%25AE%259D-%25E6%25B8%2585%25E6%25BE%2588saup-%25E5%258D%259A%25E5%25AE%25A2%25E5%259B%25AD.html&lunum=6&n=mikel_cpr&pcs=1366x579&pis=10000x10000&ps=242x112&psr=1366x768&pss=1366x287&qn=001d9f2a7d0463bf&rad=&rsi0=728&rsi1=90&rsi5=2&rss0=%23FFFFFF&rss1=%23FFFFFF&rss2=%230000FF&rss3=%23444444&rss4=%23008000&rss5=&rss6=%23e10900&rss7=&scale=&skin=&td_id=2394728&tn=text_default_728_90&tpr=1447665386893&ts=1&version=2.0&xuanting=0&dtm=BAIDU_DUP2_SETJSONADSLOT&dc=2&di=u2394728&ti=iOS%E5%BC%80%E5%8F%91%7C%20%5B%E8%BD%AC%E8%BD%BD%5DiOS-%20%E5%A6%82%E4%BD%95%E9%9B%86%E6%88%90%E6%94%AF%E4%BB%98%E5%AE%9D%20%E2%80%93%20%E6%B8%85%E6%BE%88Saup%20%E2%80%93%20%E5%8D%9A%E5%AE%A2%E5%9B%AD%20%7C%20Mikel&tt=1447665386857.39.143.149" align="center,center" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" allowtransparency="true" style="margin: 0px; padding: 0px;">
[转载]iOS- 如何集成支付宝 – 清澈Saup – 博客园.
现在不少app内都集成了支付宝功能
使用支付宝进行一个完整的支付功能,大致有以下步骤:
1>先与支付宝签约,获得商户ID(partner)和账号ID(seller)
(这个主要是公司的负责)
2>下载相应的公钥私钥文件(加密签名用)
里面提供了非常详细的文档、如何签约、如何获得公钥私钥、如何调用支付接口。
4>生成订单信息
5>调用支付宝客户端,由支付宝客户端跟支付宝安全服务器打交道
6>支付完毕后返回支付结果给商户客户端和服务器
SDK里有集成支付宝功能的一个Demo> 集成支付功能的具体操作方式,可以参考Demo
错误原因很简单,就是项目的部署版本设置太低了,从3.0改为4.3即可
要想集成支付功能,依赖以下文件夹的库文件(把这3个添加到你的客户端中)
调用支付接口可以参考AlixPayDemoViewController的下面方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
如何创建订单 ( 订单根据自己公司看是什么样的)
如何签名
如何调用支付接口
都在这个方法里面了
04 | - ( void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath |
09 | Product *product = [_products objectAtIndex:indexPath.row]; |
17 | NSString *partner = [[NSBundle mainBundle] objectForInfoDictionaryKey:@ "Partner" ]; |
18 | NSString *seller = [[NSBundle mainBundle] objectForInfoDictionaryKey:@ "Seller" ]; |
21 | if ([partner length] == 0 || [seller length] == 0) |
23 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@ "提示" |
24 | message:@ "缺少partner或者seller。" |
26 | cancelButtonTitle:@ "确定" |
27 | otherButtonTitles:nil]; |
38 | AlixPayOrder *order = [[AlixPayOrder alloc] init]; |
39 | order.partner = partner; |
40 | order.seller = seller; |
41 | order.tradeNO = [self generateTradeNO]; |
42 | order.productName = product.subject; |
43 | order.productDescription = product.body; |
44 | order.amount = [NSString stringWithFormat:@ "%.2f" ,product.price]; |
48 | NSString *appScheme = @ "AlixPayDemo" ; |
51 | NSString *orderSpec = [order description]; |
52 | NSLog(@ "orderSpec = %@" ,orderSpec); |
55 | id<DataSigner> signer = CreateRSADataSigner([[NSBundle mainBundle] objectForInfoDictionaryKey:@ "RSA private key" ]); |
56 | NSString *signedString = [signer signString:orderSpec]; |
59 | NSString *orderString = nil; |
60 | if (signedString != nil) { |
61 | orderString = [NSString stringWithFormat:@ "%@&sign=\"%@\"&sign_type=\"%@\"" , |
62 | orderSpec, signedString, @ "RSA" ]; |
65 | AlixPay * alixpay = [AlixPay shared]; |
66 | int ret = [alixpay pay:orderString applicationScheme:appScheme]; |
68 | if (ret == kSPErrorAlipayClientNotInstalled) { |
69 | UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@ "提示" |
70 | message:@ "您还没有安装支付宝快捷支付,请先安装。" |
72 | cancelButtonTitle:@ "确定" |
73 | otherButtonTitles:nil]; |
74 | [alertView setTag:123]; |
78 | else if (ret == kSPErrorSignError) { |
84 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; |
主要集成的关键就是下面几步:
02 | AlixPayOrder *order = [[AlixPayOrder alloc] init]; |
04 | NSString *orderSpec = [order description]; |
07 | id<DataSigner> signer = CreateRSADataSigner(@“私钥key”); |
09 | NSString *signedString = [signer signString:orderSpec]; |
13 | NSString *orderString = [NSString stringWithFormat:@ "%@&sign=\"%@\"&sign_type=\"%@\"" , |
14 | orderSpec, signedString, @ "RSA" ]; |
17 | AlixPay * alixpay = [AlixPay shared]; |
19 | int ret = [alixpay pay:orderString applicationScheme:appScheme]; |