支付宝 IOS

来源:互联网 发布:站内搜索优化方案 编辑:程序博客网 时间:2024/05/22 10:18

1.支付宝官网下载sdk

https://b.alipay.com/order/productDetail.htm?productId=2013080604609654&tabId=4#ps-tabinfo-hash


2.根据帮助文档可知

a.将两个压缩包加入项目

AlipaySDK.bundleAlipaySDK.framework


b.配置请求信息

 

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.notifyURL = @"http://www.xxx.com"; //回调URLorder.service = @"mobile.securitypay.pay";order.paymentType = @"1";
order.inputCharset = @"utf-8";

order.itBPay = @"30m";

//应用注册scheme,AlixPayDemo-Info.plist定义URL typesNSString *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 = [NSStringstringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",

                   orderSpec, signedString, @"RSA"];

[[AlipaySDK defaultService] payOrder:orderString fromScheme:appSchemecallback:^(NSDictionary *resultDic) {

          NSLog(@"reslut = %@",resultDic);

}];

[tableView deselectRowAtIndexPath:indexPath animated:YES];} 


c. 配置支付宝客户端返回url处理方法

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)urlsourceApplication:(NSString *)sourceApplication annotation:(id)annotation{

//如果极简SDK 不可用,会跳转支付宝钱包进行支付,需要将支付宝钱包的支付结果回传给SDKif ([url.host isEqualToString:@"safepay"]) {

[[AlipaySDK defaultService] processOrderWithPaymentResult:urlstandbyCallback:^(NSDictionary *resultDic) {

          NSLog(@"result = %@",resultDic);       }];

}

if ([url.host isEqualToString:@"platformapi"]){//支付宝钱包快登授权返回authCode

[[AlipaySDK defaultService] processAuthResult:urlstandbyCallback:^(NSDictionary *resultDic) {

          NSLog(@"result = %@",resultDic);       }];

}

return YES;} 

3.针对签名问题





0 0