使用支付宝进行一个完整的支付功能,大致有以下步骤:
1>先与支付宝签约,获得商户ID(partner)和账号ID(seller)(这个主要是公司的负责)2>下载相应的公钥私钥文件(加密签名用)3>下载支付宝SDK(登录网站:http://club.alipay.com/)里面提供了非常详细的文档、如何签约、如何获得公钥私钥、如何调用支付接口4>生成订单信息5>调用支付宝客户端,由支付宝客户端跟支付宝安全服务器打交道6>支付完毕后返回支付结果给商户客户端和服务器。SDK里有集成支付宝功能的一个Demo>集成支付功能的具体操作方式,可以参考Demo
如何创建订单 ( 订单根据自己公司看是什么样的)
要想集成支付功能,依赖以下文件夹的库文件(把这3个添加到你的客户端中)
调用支付接口可以参考AlixPayDemoViewController的下面方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
如何签名
如何调用支付接口
都在这个方法里面了
-
-
-
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
-
-
- Product *product = [_products objectAtIndex:indexPath.row];
-
-
-
-
-
-
-
- NSString *partner = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"Partner"];
- NSString *seller = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"Seller"];
-
-
- if ([partner length] == 0 || [seller length] == 0)
- {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
- message:@"缺少partner或者seller。"
- delegate:self
- cancelButtonTitle:@"确定"
- otherButtonTitles:nil];
- [alert show];
- return;
- }
-
-
-
-
-
-
- AlixPayOrder *order = [[AlixPayOrder alloc] init];
- order.partner = partner;
- order.seller = seller;
- order.tradeNO = [self generateTradeNO];
- order.productName = product.subject;
- order.productDescription = product.body;
- order.amount = [NSString stringWithFormat:@"%.2f",product.price];
- order.notifyURL = @"http://www.xxx.com"; //回调URL
-
-
- NSString *appScheme = @"AlixPayDemo";
-
-
- NSString *orderSpec = [order description];
- NSLog(@"orderSpec = %@",orderSpec);
-
-
- id<DataSigner> signer = CreateRSADataSigner([[NSBundle mainBundle] objectForInfoDictionaryKey:@"RSA private key"]);
- NSString *signedString = [signer signString:orderSpec];
-
-
- NSString *orderString = nil;
- if (signedString != nil) {
- orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",
- orderSpec, signedString, @"RSA"];
-
-
- AlixPay * alixpay = [AlixPay shared];
- int ret = [alixpay pay:orderString applicationScheme:appScheme];
-
- if (ret == kSPErrorAlipayClientNotInstalled) {
- UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"提示"
- message:@"您还没有安装支付宝快捷支付,请先安装。"
- delegate:self
- cancelButtonTitle:@"确定"
- otherButtonTitles:nil];
- [alertView setTag:123];
- [alertView show];
- }
- else if (ret == kSPErrorSignError) {
- NSLog(@"签名错误!");
- }
-
- }
-
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- }
-
-
- AlixPayOrder *order = [[AlixPayOrder alloc] init];
-
- NSString *orderSpec = [order description];
-
-
- id<DataSigner> signer = CreateRSADataSigner(@“私钥key”);
-
- NSString *signedString = [signer signString:orderSpec];
-
-
-
- NSString *orderString = [NSString stringWithFormat:@'%@&sign='%@'&sign_type='%@'',
- orderSpec, signedString, @'RSA'];
-
-
- AlixPay * alixpay = [AlixPay shared];
-
- int ret = [alixpay pay:orderString applicationScheme:appScheme];
-