ps:先來支付寶的。首先集成支付寶的SDK镰禾,這個(gè)真心是運(yùn)氣加上技術(shù)相結(jié)合才行~有時(shí)候一樣的工程吴侦,就是給你報(bào)錯(cuò)~你能耐他何坞古?然后第二天運(yùn)行同樣的工程痪枫,錯(cuò)誤消失了~就是這么的神奇!詳細(xì)的集成流程就不說了捧挺,簡單大致提一下首先第一步要去與支付寶簽約尿瞭,獲得商戶ID也就是合作者身份声搁,之后就開始下載官方文檔與示例damo了,一步步按著官方文檔來就行了.
PS:好了,運(yùn)行之后就應(yīng)該剩下一個(gè)報(bào)錯(cuò)了遏匆,這個(gè)報(bào)錯(cuò)有點(diǎn)麻煩幅聘,需要導(dǎo)入路徑窃植,讓系統(tǒng)找到這個(gè)文件還是先把報(bào)錯(cuò)放出來吧
PS:下面是解決辦法
PS:如果運(yùn)行后openssl這個(gè)錯(cuò)誤還是存在的話巷怜,那就不好意思了~重新導(dǎo)入吧~或者睡上一覺擼上一局吧~反正我是真切體會過的延塑,晚上集成了幾次都是剩下這個(gè)錯(cuò),第二個(gè)重新運(yùn)行胖替,居然就可以了~就是真么的神奇豫缨。然后到獲取以及上傳公鑰和私鑰的問題了好芭。
PS:然后是下載下來就是這個(gè)樣子的
然后就搞定了啊~~由于現(xiàn)在網(wǎng)上的支付寶Demo都是在工程中簽名加密的~所以這里我就不展示了~而且沒用,現(xiàn)在的公司根本不會把簽名加密放在工程當(dāng)中了。所以我就以后臺簽名加密為例子累榜。首先和后臺商量如何給我返回?cái)?shù)據(jù)摆尝,先上接口煎殷。
支付寶APP支付申請加簽
調(diào)用接口(post)
www.401VN.com
請求參數(shù)
key (會員登錄令牌)
pay_sn 支付編號
subject 訂單主題描述信息
amount 訂單金額
返回?cái)?shù)據(jù)
resulr (參數(shù)字符串-加簽之后的結(jié)果串)
apedcome
支付寶APP支付結(jié)果驗(yàn)簽
調(diào)用接口(post)
www.401VN.com
請求參數(shù)
key (會員登錄令牌)
alipay_resp 支付結(jié)果內(nèi)的response數(shù)據(jù)串
resultStatus 結(jié)果狀態(tài)碼
sign_type 簽名類型
sign 簽名數(shù)據(jù)
返回?cái)?shù)據(jù)
'1' 支付結(jié)果:成功
第一條接口是申請加簽的接口第岖,這條接口我們需要把訂單的信息傳給后臺,讓后臺進(jìn)行簽名。然后給我們返回加簽的結(jié)果杠纵。
首先這個(gè)第一條接口寫在點(diǎn)擊支付寶支付的那個(gè)按鈕的點(diǎn)擊方法哪里。
[NetWorkingpostWithUrlString:zhifubao_Signaparameters:prccsuccess:^(iddata) {
NSLog(@"網(wǎng)絡(luò)請求成功");
[HUDhideAnimated:YES];
NSMutableDictionary* dict = [NSMutableDictionarydictionaryWithCapacity:10];
dict = [NSJSONSerializationJSONObjectWithData:dataoptions:NSJSONReadingAllowFragments|NSJSONReadingMutableLeaveserror:nil];
NSLog(@"支付寶加簽后返回的數(shù)據(jù)==%@",dict);
//NSLog(@"打斷之后的數(shù)據(jù)=%@",arr);
if([dict[@"msg"]isEqualToString:@"1"]) {
//應(yīng)用注冊scheme,在AliSDKDemo-Info.plist定義URL types
NSString*appScheme =@"alipay2016111902989697";
// NOTE:將簽名成功字符串格式化為訂單字符串,請嚴(yán)格按照該格式
NSString*orderString = dict[@"datas"][@"retstr"];
// NOTE:調(diào)用支付結(jié)果開始支付
[[AlipaySDKdefaultService]payOrder:orderStringfromScheme:appSchemecallback:^(NSDictionary*resultDic) {
NSLog(@"支付寶回調(diào)后給我返回的數(shù)據(jù)源==%@",resultDic);
}];
}
}failure:^(NSError*error) {
NSLog(@"網(wǎng)絡(luò)請求失敗");
[HUDhideAnimated:YES];
}];
然后就是調(diào)用支付寶SDK的方法了。也就是下面的方法。
//該方法9.0以前的API接口
- (BOOL)application:(UIApplication*)application
openURL:(NSURL*)url
sourceApplication:(NSString*)sourceApplication
annotation:(id)annotation
{
if([url.hostisEqualToString:@"safepay"]) {
//支付跳轉(zhuǎn)支付寶錢包進(jìn)行支付,處理支付結(jié)果
[[AlipaySDKdefaultService]processOrderWithPaymentResult:urlstandbyCallback:^(NSDictionary*resultDic) {
NSLog(@"APPDelegate里面的result = %@",resultDic);
//9000代表是成功的意思院喜,這是支付寶官方認(rèn)定的,別問為什么元咙!還有一點(diǎn),這個(gè)9000是支付寶給你返回的支付成功信息,強(qiáng)烈不建議前端直接就以這個(gè)9000為標(biāo)準(zhǔn)判斷支付成功,應(yīng)該把這個(gè)字典傳給后臺颈走,讓后臺記錄判斷之后,再給前端返回锐膜!前端再顯示結(jié)果給用戶知道。切記切記!I琛!
if([resultDic[@"resultStatus"]isEqualToString:@"9000"]) {
//然后和后臺商量,支付寶給我們返回的一個(gè)字典要怎么傳給后臺弄抬,是直接就傳了,還是說要再做點(diǎn)什么修改依啰,我這里就修改了,麻煩的一比。
NSString* str =resultDic[@"result"];
NSString*d5 = [strstringByReplacingOccurrencesOfString:@"\""withString:@""];
NSString* d6 = [d5stringByReplacingOccurrencesOfString:@"{"withString:@""];
NSString* d7 = [d6stringByReplacingOccurrencesOfString:@"}"withString:@""];
NSString* d8 = [d7stringByReplacingOccurrencesOfString:@"alipay_trade_app_pay_response:"withString:@""];
NSUserDefaults* user = [NSUserDefaultsstandardUserDefaults];
NSDictionary* dic = [userobjectForKey:@"sss"];
NSString* kkk = dic[@"datas"][@"key"];
NSMutableDictionary* prcc = [NSMutableDictionarydictionaryWithCapacity:10];
[prccsetValue:kkkforKey:@"key"];
[prccsetValue:[NSStringstringWithFormat:@"%@",d8]forKey:@"alipay_resp"];
[prccsetValue:resultDic[@"resultStatus"]forKey:@"resultStatus"];
[prccsetValue:@"RSA"forKey:@"sign_type"];
[prccsetValue:@"sX6/UzkKOjiCNbUPiXX1jMEdCggqGIOwnCzDEgBndSATW/9Q9rke7ubhxNxHbRhMLAtiCQchG15hw93A+pH1w3vZ60/DLh99JD7NUEqE9qOiHnV5INZ+zFzNVkuR4S9xZovSp8MAkmEVlsD6sT7fhOxPi1VRSkBM/wD3iUA/iEY="forKey:@"sign"];
//然后這里就調(diào)用了第二條接口。返回結(jié)果如果成功了,就直接調(diào)用通知父腕,跳轉(zhuǎn)到指定的界面。
[NetWorkingpostWithUrlString:zhifubao_Resultparameters:prccsuccess:^(iddata) {
NSLog(@"網(wǎng)絡(luò)請求成功");
NSMutableDictionary* dict = [NSMutableDictionarydictionaryWithCapacity:10];
dict = [NSJSONSerializationJSONObjectWithData:dataoptions:NSJSONReadingAllowFragments|NSJSONReadingMutableLeaveserror:nil];
NSLog(@"成功了嗎!!>翰!幕垦!%@",dict);
if([dict[@"msg"]isEqualToString:@"1"]) {
NSLog(@"的確是1111");
//創(chuàng)建通知
NSNotification*notification =[NSNotificationnotificationWithName:@"tongzhi"object:niluserInfo:dict];
//通過通知中心發(fā)送通知
[[NSNotificationCenterdefaultCenter]postNotification:notification];
UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:@"支付結(jié)果"message:@"支付成功"delegate:selfcancelButtonTitle:nilotherButtonTitles:@"確定",nil];
[alertshow];
}else{
NSLog(@"支付結(jié)果上傳服務(wù)器失敗");
UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:@"支付結(jié)果"message:@"支付失敗"delegate:selfcancelButtonTitle:nilotherButtonTitles:@"確定",nil];
[alertshow];
}
}failure:^(NSError*error) {
NSLog(@"網(wǎng)絡(luò)請求失敗");
}];
}else{
//創(chuàng)建通知
NSNotification*notificatio =[NSNotificationnotificationWithName:@"DefeatZhifubao"object:niluserInfo:nil];
//通過通知中心發(fā)送通知
[[NSNotificationCenterdefaultCenter]postNotification:notificatio];
UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:@"支付結(jié)果"message:@"支付失敗"delegate:selfcancelButtonTitle:nilotherButtonTitles:@"確定",nil];
[alertshow];
}
}];
//授權(quán)跳轉(zhuǎn)支付寶錢包進(jìn)行支付仇奶,處理支付結(jié)果
[[AlipaySDKdefaultService]processAuth_V2Result:urlstandbyCallback:^(NSDictionary*resultDic) {
NSLog(@"result = %@",resultDic);
//解析auth code
NSString*result = resultDic[@"result"];
NSString*authCode =nil;
if(result.length>0) {
NSArray*resultArr = [resultcomponentsSeparatedByString:@"&"];
for(NSString*subResultinresultArr) {
if(subResult.length>10&& [subResulthasPrefix:@"auth_code="]) {
authCode = [subResultsubstringFromIndex:10];
break;
}
}
}
NSLog(@"授權(quán)結(jié)果authCode = %@", authCode?:@"");
}];
}
//下面的這個(gè)是微信調(diào)用的方法衅枫!沒錯(cuò)论皆!微信就是這么一小句話就調(diào)用起來了!
return[WXApihandleOpenURL:urldelegate:self];
returnYES;
}
//下面這個(gè)方法是9.0以后的API的接口
- (BOOL)application:(UIApplication*)app openURL:(NSURL*)url options:(NSDictionary *)options
{
if([url.hostisEqualToString:@"safepay"]) {
//支付跳轉(zhuǎn)支付寶錢包進(jìn)行支付,處理支付結(jié)果
[[AlipaySDKdefaultService]processOrderWithPaymentResult:urlstandbyCallback:^(NSDictionary*resultDic) {
NSLog(@"9.0以后的新接口API:result = %@",resultDic);
NSLog(@"1111111111");
//9000代表是成功的意思,這是支付寶官方認(rèn)定的锐墙,別問為什么!還有一點(diǎn)之拨,這個(gè)9000是支付寶給你返回的支付成功信息,強(qiáng)烈不建議前端直接就以這個(gè)9000為標(biāo)準(zhǔn)判斷支付成功颖变,應(yīng)該把這個(gè)字典傳給后臺,讓后臺記錄判斷之后衔峰,再給前端返回!前端再顯示結(jié)果給用戶知道穴肘。切記切記2础J坛住!
if([resultDic[@"resultStatus"]isEqualToString:@"9000"]) {
//然后和后臺商量,支付寶給我們返回的一個(gè)字典要怎么傳給后臺唬滑,是直接就傳了,還是說要再做點(diǎn)什么修改稻艰,我這里就修改了,麻煩的一比躯保。
NSString* str =resultDic[@"result"];
NSString*d5 = [strstringByReplacingOccurrencesOfString:@"\""withString:@""];
NSString* d6 = [d5stringByReplacingOccurrencesOfString:@"{"withString:@""];
NSString* d7 = [d6stringByReplacingOccurrencesOfString:@"}"withString:@""];
NSString* d8 = [d7stringByReplacingOccurrencesOfString:@"alipay_trade_app_pay_response:"withString:@""];
NSUserDefaults* user = [NSUserDefaultsstandardUserDefaults];
NSDictionary* dic = [userobjectForKey:@"sss"];
NSString* kkk = dic[@"datas"][@"key"];
NSMutableDictionary* prcc = [NSMutableDictionarydictionaryWithCapacity:10];
[prccsetValue:kkkforKey:@"key"];
[prccsetValue:[NSStringstringWithFormat:@"%@",d8]forKey:@"alipay_resp"];
[prccsetValue:resultDic[@"resultStatus"]forKey:@"resultStatus"];
[prccsetValue:@"RSA"forKey:@"sign_type"];
[prccsetValue:@"sX6/UzkKOjiCNbUPiXX1jMEdCggqGIOwnCzDEgBndSATW/9Q9rke7ubhxNxHbRhMLAtiCQchG15hw93A+pH1w3vZ60/DLh99JD7NUEqE9qOiHnV5INZ+zFzNVkuR4S9xZovSp8MAkmEVlsD6sT7fhOxPi1VRSkBM/wD3iUA/iEY="forKey:@"sign"];
//然后這里就調(diào)用了第二條接口。返回結(jié)果如果成功了召烂,就直接調(diào)用通知,跳轉(zhuǎn)到指定的界面匙头。
[NetWorkingpostWithUrlString:zhifubao_Resultparameters:prccsuccess:^(iddata) {
NSLog(@"網(wǎng)絡(luò)請求成功");
NSMutableDictionary* dict = [NSMutableDictionarydictionaryWithCapacity:10];
dict = [NSJSONSerializationJSONObjectWithData:dataoptions:NSJSONReadingAllowFragments|NSJSONReadingMutableLeaveserror:nil];
NSLog(@"成功了嗎u逦觥!0踌簟!蔫缸!%@",dict);
if([dict[@"msg"]isEqualToString:@"1"]) {
//創(chuàng)建通知
NSNotification*notificationn =[NSNotificationnotificationWithName:@"tongzhinine"object:niluserInfo:dict];
//通過通知中心發(fā)送通知
[[NSNotificationCenterdefaultCenter]postNotification:notificationn];
UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:@"支付結(jié)果"message:@"支付成功"delegate:selfcancelButtonTitle:nilotherButtonTitles:@"確定",nil];
[alertshow];
}else{
NSLog(@"支付結(jié)果上傳服務(wù)器失敗");
UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:@"支付結(jié)果"message:@"支付失敗"delegate:selfcancelButtonTitle:nilotherButtonTitles:@"確定",nil];
[alertshow];
}
}failure:^(NSError*error) {
NSLog(@"網(wǎng)絡(luò)請求成功");
}];
}else{
//創(chuàng)建通知
NSNotification*notificati =[NSNotificationnotificationWithName:@"DefeatZhifubaonine"object:niluserInfo:nil];
//通過通知中心發(fā)送通知
[[NSNotificationCenterdefaultCenter]postNotification:notificati];
UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:@"支付結(jié)果"message:@"支付失敗"delegate:selfcancelButtonTitle:nilotherButtonTitles:@"確定",nil];
[alertshow];
}
}];
//授權(quán)跳轉(zhuǎn)支付寶錢包進(jìn)行支付唇撬,處理支付結(jié)果
[[AlipaySDKdefaultService]processAuth_V2Result:urlstandbyCallback:^(NSDictionary*resultDic) {
NSLog(@"result = %@",resultDic);
//解析auth code
NSString*result = resultDic[@"result"];
NSString*authCode =nil;
if(result.length>0) {
NSArray*resultArr = [resultcomponentsSeparatedByString:@"&"];
for(NSString*subResultinresultArr) {
if(subResult.length>10&& [subResulthasPrefix:@"auth_code="]) {
authCode = [subResultsubstringFromIndex:10];
break;
}
}
}
NSLog(@"授權(quán)結(jié)果authCode = %@", authCode?:@"");
}];
}
//下面的這個(gè)是微信調(diào)用的方法告希!沒錯(cuò)喝噪!微信就是這么一小句話就調(diào)用起來了!
return[WXApihandleOpenURL:urldelegate:self];
returnYES;
}
下面輪到微信支付了晚唇。微信比支付寶簡單的太多太多了赫舒。因?yàn)槲⑿欧窒砣绻闶鞘褂昧薙hare SDK的話接癌,那你做微信支付的時(shí)候,根本就不需要再集成什么SDK了弯汰,直接就用分享的那個(gè)SDK就OK了摔吏!
所以這里直接就上硬菜了据某!
和后臺商量之后癣籽,直接只需要一條接口就OK了
微信支付APP預(yù)支付申請,含加簽
調(diào)用接口(post)
www.baidu.com
請求參數(shù)
key (會員登錄令牌)
pay_sn 支付編號
subject 訂單主題描述信息
amount 訂單金額
返回?cái)?shù)據(jù)
app 支付請求數(shù)據(jù)集合(包含sign)
微信只有一條接口瓶籽,也是在微信支付按鈕的點(diǎn)擊方法那里寫
[NetWorkingpostWithUrlString:weixinzhifu_Signaparameters:prccsuccess:^(iddata) {
NSLog(@"網(wǎng)絡(luò)請求成功");
[HUDhideAnimated:YES];
NSMutableDictionary* dict = [NSMutableDictionarydictionaryWithCapacity:10];
dict = [NSJSONSerializationJSONObjectWithData:dataoptions:NSJSONReadingAllowFragments|NSJSONReadingMutableLeaveserror:nil];
NSLog(@"微信加簽后返回的數(shù)據(jù)==%@",dict);
//NSLog(@"打斷之后的數(shù)據(jù)=%@",arr);
if([dict[@"msg"]isEqualToString:@"1"]) {
//調(diào)起微信支付
PayReq*request = [[PayReqalloc]init];
request.partnerId= dict[@"datas"][@"app"][@"partnerid"];
request.prepayId= dict[@"datas"][@"app"][@"prepayid"];
request.package=dict[@"datas"][@"app"][@"package"];
request.nonceStr= dict[@"datas"][@"app"][@"noncestr"];
request.timeStamp= [dict[@"datas"][@"app"][@"timestamp"]intValue];
//這里要注意key里的值一定要填對塑顺,微信官方給的參數(shù)名是錯(cuò)誤的严拒,不是第二個(gè)字母大寫
NSMutableDictionary*signParams = [NSMutableDictionarydictionary];
[signParamssetObject:@"wx5942cca2360ff745"forKey:@"appid"];
[signParamssetObject: dict[@"datas"][@"app"][@"partnerid"]forKey:@"partnerid"];
[signParamssetObject: request.nonceStrforKey:@"noncestr"];
[signParamssetObject: request.packageforKey:@"package"];
[signParamssetObject: dict[@"datas"][@"app"][@"timestamp"]forKey:@"timestamp"];
[signParamssetObject: request.prepayIdforKey:@"prepayid"];
//生成簽名
NSString*sign= dict[@"datas"][@"app"][@"sign"];
//添加簽名
request.sign= sign;
//調(diào)起微信開始支付?氵搿预鬓!
[WXApisendReq:request];
NSLog(@"這是微信的打印");
}
}failure:^(NSError*error) {
NSLog(@"網(wǎng)絡(luò)請求失敗");
[HUDhideAnimated:YES];
}];
因?yàn)槲⑿诺闹Ц兜姆椒ǘ际且粯拥母穸傅氖?.0以前的9.0以后的都是那2個(gè)方法竣蹦,而且微信只需要一句話痘括,所以我這里我就不在寫那2個(gè)方法了挠日。但是還有微信一個(gè)9.0以前的方法,雖然無用,但是也寫出來,顯得全面一點(diǎn)入桂,可以忽略的。
//就是下面的這個(gè)方法了
- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url
{
NSLog(@"11111WQEQ");
return[WXApihandleOpenURL:urldelegate:self];
}
最后一步就是就是微信給我們返回的信息的接收方法
-(void) onResp:(BaseResp*)resp
{
NSString*strMsg = [NSStringstringWithFormat:@"errcode:%d", resp.errCode];
NSString*strTitle;
if([respisKindOfClass:[SendMessageToWXRespclass]])
{
strTitle =@"發(fā)送媒體消息結(jié)果";
}
if([respisKindOfClass:[PayRespclass]]){
//支付返回結(jié)果勺届,實(shí)際支付結(jié)果需要去微信服務(wù)器端查詢
strTitle = [NSStringstringWithFormat:@"支付結(jié)果"];
switch(resp.errCode) {
caseWXSuccess:{
strMsg =@"恭喜您,支付成功!";
//[MYNotificationCenter postNotificationName:@"weixinPaystatusSuccess" object:nil userInfo:@{@"status":@"success"}];
NSLog(@"%@",strMsg);
break;
}
caseWXErrCodeUserCancel:{
strMsg =@"已取消支付!";
//[MYNotificationCenter postNotificationName:@"weixinPaystatusSuccess" object:nil userInfo:@{@"status":@"cancle"}];
NSLog(@"%@",strMsg);
break;
}
default:{
strMsg = [NSStringstringWithFormat:@"支付失敗!"];
//[MYNotificationCenter postNotificationName:@"weixinPaystatusSuccess" object:nil userInfo:@{@"status":@"cancle"}];
NSLog(@"%@",strMsg);
break;
}
}
//創(chuàng)建通知
NSNotification*notificationnn =[NSNotificationnotificationWithName:@"weixinbaotongzhi"object:niluserInfo:nil];
//通過通知中心發(fā)送通知
[[NSNotificationCenterdefaultCenter]postNotification:notificationnn];
UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:strTitlemessage:strMsgdelegate:selfcancelButtonTitle:nilotherButtonTitles:@"確定",nil];
[alertshow];
}
}