最近本人項目中有集成支付寶這個需求趟了好多坑,希望大家不要繼續趟這些坑了。
首先支付寶有的人集成之後會報這個錯誤
1.#include <openssl/opensslconf.h> not find
需要在building setting --> header search paths中添加路徑($(SRCROOT)/項目名稱/文件的絕對地址)
配置URL Schemes
你可以直接在info.plist中直接添加,也可以在info URL types中設置兩者等價。
3.提示LaunchServices: ERROR: There is no registered handler for URL scheme alipay(這句話其實是在告訴你 設備上沒有安裝 支付寶的客戶端,此時會走網頁端)而有人會發現並沒有HTML5網頁彈出過一會,會發現服務器返回4000支付失敗,這可能是因爲html5界面被隱藏掉了。
id<DataSigner> signer =CreateRSADataSigner(privateKey);
NSString *signedString = [signer signString:orderSpec];
//將簽名成功字符串格式化爲訂單字符串,請嚴格按照該格式
NSString *orderString =nil;
if (signedString !=nil) {
orderString = [NSStringstringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",
orderSpec, signedString, @"RSA"];
//需要在發送支付請求之前加上這句話
NSArray *array = [[UIApplicationsharedApplication] windows];
UIWindow* win=[arrayobjectAtIndex:0];
[win setHidden:NO];
[[AlipaySDKdefaultService] payOrder:orderStringfromScheme:appScheme callback:^(NSDictionary *resultDic) {
NSLog(@"reslut = %@",resultDic);
NSLog(@"%@",resultDic[@"memo"]);
}];
}