支付寶終于更新了SDK,減少了許多讓人無(wú)語(yǔ)的錯(cuò)誤。由于以后經(jīng)常會(huì)用到,所以記錄一下自己的集成流程。
一,導(dǎo)入SDK

在客戶端組裝請(qǐng)求信息需要導(dǎo)入這些,如果在服務(wù)器完成就只用導(dǎo)入.bundle和.framework。(雖然在支付寶加簽有風(fēng)險(xiǎn),但服務(wù)器不做也只能自己搞)
二,添加依賴庫(kù)

三,運(yùn)行注意
1 , "Cannot find interface declaration for 'NSObject', superclass of 'Base64'"類似這種錯(cuò)誤。在報(bào)錯(cuò)文件添加Foundation頭文件。(現(xiàn)在不會(huì)報(bào)這個(gè)錯(cuò)了)
2."openssl not found "需要設(shè)置路徑。在target>build setting>header Search Paths中添加路徑。方法:點(diǎn)擊openssl文件showinfinder ,command+i在簡(jiǎn)介里查看文件路徑。
$(SRCROOT)/加文件路徑
3.Allow Arbitrary Loads
4.添加 URL Schemes
點(diǎn)擊項(xiàng)目名稱,點(diǎn)擊“Info”選項(xiàng)卡,在“URL Types”選項(xiàng)中,點(diǎn)擊“+”,在“URL Schemes”中輸入“alisdkdemo”?!癮lisdkdemo”來(lái)自于文件“APViewController.m”的NSString *appScheme = @“alisdkdemo”;。名字隨便起,但不要與其他的重復(fù)
四,代碼導(dǎo)入
1.appDelegate.m中
支付回調(diào),在使用支付寶客戶端是在這里回調(diào),使用h5支付時(shí)在支付文件里回調(diào)
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options
{
// 當(dāng)用戶通過(guò)支付寶客戶端進(jìn)行支付時(shí),會(huì)回調(diào)該block:standbyCallback
[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
NSLog(@"result = %@",resultDic);
NSLog(@"---%@",[resultDic objectForKey:@"memo"]);
if ([[resultDic objectForKey:@"resultStatus"]isEqualToString:@"9000"]) {
//支付成功操作
}
else
{
//支付失敗操作
}
self.alipayNav = nil;
}];
return YES;
}
2,支付文件中
不支持在客戶端配置,如果你的后臺(tái)愿意給的話。。。。。。。order是舊版本的,不過(guò)現(xiàn)在仍然可以用。新的版本可去官網(wǎng)下載。
NSString *partner = @"Your partnerID";
NSString *seller = @"Your sellerID";
// NSString *privateKey = @"4grcwb2et493dr0p0qhaoksgvvijdsus";
NSString *privateKey = @"Your privateKey";
Order *order = [[Order alloc] init];
order.partner = partner;
order.sellerID = seller;
order.outTradeNO = ???; //訂單ID(由商家?自?行制定)
order.subject = ???; //商品標(biāo)題
order.body = ???; //商品描述
order.totalFee = [NSString stringWithFormat:@"%.2f",[price floatValue]]; //商品價(jià)格
order.notifyURL = ???; //回調(diào)URL
order.service = @"mobile.securitypay.pay";
order.paymentType = @"1";
order.inputCharset = @"utf-8";
order.itBPay = @"30m";//時(shí)間
order.showURL = @"m.alipay.com";
//應(yīng)用注冊(cè)scheme,在AlixPayDemo-Info.plist定義URL types
NSString *appScheme = @"alipay";
//將商品信息拼接成字符串
NSString *orderSpec = [order description];
NSLog(@"orderSpec = %@",orderSpec);
//獲取私鑰并將商戶信息簽名,外部商戶可以根據(jù)情況存放私鑰和簽名,只需要遵循RSA簽名規(guī)范,并將簽名字符串base64編碼和UrlEncode
id<DataSigner> signer = CreateRSADataSigner(privateKey);
NSString *signedString = [signer signString:orderSpec];
//將簽名成功字符串格式化為訂單字符串,請(qǐng)嚴(yán)格按照該格式
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處理支付結(jié)果】
NSLog(@"reslut = %@",resultDic);
}];
}