支付寶集成
支付寶開放平臺(tái):https://openhome.alipay.com/platform/home.htm
集成支付寶
-
支付寶功能流程
1.png 主要集成步驟
下載最新的SDK
https://openhome.alipay.com/platform/document.htm#down
- 1.導(dǎo)入相關(guān)框架
Snip20150911_2.png
- 可能會(huì)遇到的問(wèn)題
- 1.導(dǎo)入系統(tǒng)依賴框架
SystemConfiguration.framework - 2.添加依賴路徑
$(SRCROOT)/支付寶集成/Classes/Alipay
- 1.導(dǎo)入系統(tǒng)依賴框架
Snip20150911_3.png
- 主要集成code
- (void)buyProduct:(NYProduct *)product
{
/**
* 1.簽約后獲取商戶ID/賬號(hào)ID/私鑰
*/
NSString *partner = @"";
NSString *seller = @"";
NSString *privateKey = @"";
/**
2.創(chuàng)建訂單
*/
Order *order = [[Order alloc]init];
order.partner = partner;
order.seller = seller;
order.tradeNO = @"";//商戶自己決定
order.productName = product.name;
order.productDescription = product.detail;
order.amount = [NSString stringWithFormat:@"%.2f",product.price];
order.notifyURL = @"";//回調(diào)地址
order.service = @"mobile.securitypay.pay";
order.paymentType = @"1";
order.inputCharset = @"utf-8";
order.itBPay = @"30m";
order.showUrl = @"m.alipay.com";
/**
* 應(yīng)用注冊(cè)scheme, 在info.plist定義
*/
NSString *appScheme = @"zhifubaojicheng";
NSString *orderSpec = [order description];
/**
獲取私鑰并將商戶信息簽名,外部商戶可以根據(jù)情況存放私鑰和簽名,只需要遵循RSA簽名規(guī)范,并將簽名字符串base64編碼和UrlEncode
*/
id<DataSigner>singer = CreateRSADataSigner(privateKey);
NSString *signedString = [singer signString:orderSpec];
// 格式化訂單,嚴(yán)格按照格式
NSString *orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",
orderSpec, signedString, @"RSA"];
// 開始支付(網(wǎng)頁(yè)/打開支付寶客戶端)
[[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
// 只有是通過(guò)網(wǎng)頁(yè)支付的時(shí)候才會(huì)回調(diào)該位置
NSLog(@"reslut = %@",resultDic);
}];
}
- 注意 在appDelegate.m中注意回調(diào)
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
//跳轉(zhuǎn)支付寶錢包進(jìn)行支付,處理支付結(jié)果
[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
// 如果是通過(guò)客戶端支付,是回調(diào)該位置
NSLog(@"result = %@",resultDic);
}];
return YES;
}
以上參照支付寶demo
并附上自己的demo
https://github.com/nealwangzi/alipaydemo.git