以前我們使用的回調是這個方法
支付寶錢包支付接口開發(fā)包2.0標準版(iOS 2.2.1)
補充:
最近很多人遇到的一個問題就是iOS9 之后廉丽,系統(tǒng)左上角增加了一個返回按鈕净响,說是這個時候沒有回調,由于我也沒有再做這一塊的白翻,無法測試到绅络,還望遇到這個問題的朋友出來說一下解決辦法:
我的猜測: SDK 有一個是notify_url 想必這個在預請求訂單消息的時候可以和后臺商量一下,加進去,在發(fā)送訂單交易的時候微信支付完成恩急,后臺完成對這個URL 的請求回調杉畜,APP,我想者應該能收到回調數據的衷恭,如果猜測正確此叠,還望朋友能夠及時聯系我,把這個文章補充完整随珠。謝謝朋友們的支持灭袁!
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
return YES;
}
最近稍微研究了一下這個,因為我也很少接觸這個窗看,幫朋友分析了一下茸歧,
系統(tǒng)目前提供使用新的方法
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url NS_DEPRECATED_IOS(2_0, 9_0, "Please use application:openURL:options:");
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation NS_DEPRECATED_IOS(4_2, 9_0, "Please use application:openURL:options:");
NS_DEPRECATED_IOS(4_2, 9_0, "Please use application:openURL:options:");
這個意思是使用版本是4.2,支持到版本9.0
目前支付寶的回調需要使用這個新方法也就是下面這種寫法,都加上注釋了显沈,
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
/*
9000 訂單支付成功
8000 正在處理中
4000 訂單支付失敗
6001 用戶中途取消
6002 網絡連接出錯
*/
if ([url.host isEqualToString:@"safepay"]) {
//這個是進程KILL掉之后也會調用软瞎,這個只是第一次授權回調,同時也會返回支付信息
[[AlipaySDK defaultService]processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) {
NSString * str = resultDic[@"result"];
NSLog(@"result = %@",str);
}];
//跳轉支付寶錢包進行支付拉讯,處理支付結果涤浇,這個只是輔佐訂單支付結果回調
[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
NSString * query = [[url query] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
id<DataVerifier> dataVeri = CreateRSADataVerifier(@"public");
//驗證簽名是否一致
if ([dataVeri verifyString:@"22" withSign:@"ee"]) {
}
NSLog(@"result = %@",resultDic);
NSString * str = resultDic[@"memo"];
NSLog(@"memo = %@",str);
}];
}else if ([url.host isEqualToString:@"platformapi"]){
//授權返回碼
[[AlipaySDK defaultService] processAuthResult:url standbyCallback:^(NSDictionary *resultDic) {
}];
}
return YES;
}
使用之前的handleopenurl 這個代理方法,我們百度的可能還有其他解決辦法魔慷,
一只锭、最有效的方法好像是把工程中得info文件中得
Main storyboard file base name
刪除后邊的value,就可以回調了
二院尔、第二種就是采用支付寶推薦的使用sourceApplication 這個方法進行回調蜻展,
模擬支付行為代碼
#pragma mark -
#pragma mark ==============點擊訂單模擬支付行為==============
//
//選中商品調用支付寶極簡支付
//
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
/*
*點擊獲取prodcut實例并初始化訂單信息
*/
Product *product = [self.productList objectAtIndex:indexPath.row];
/*
*商戶的唯一的parnter和seller。
*簽約后邀摆,支付寶會為每個商戶分配一個唯一的 parnter 和 seller纵顾。
*/
/*============================================================================*/
/*=======================需要填寫商戶app申請的===================================*/
/*============================================================================*/
NSString *partner = @"";
NSString *seller = @"";
NSString *privateKey = @"";
/*============================================================================*/
/*============================================================================*/
/*============================================================================*/
//partner和seller獲取失敗,提示
if ([partner length] == 0 ||
[seller length] == 0 ||
[privateKey length] == 0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
message:@"缺少partner或者seller或者私鑰。"
delegate:self
cancelButtonTitle:@"確定"
otherButtonTitles:nil];
[alert show];
return;
}
/*
*生成訂單信息及簽名
*/
//將商品信息賦予AlixPayOrder的成員變量
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"; //回調URL
order.service = @"mobile.securitypay.pay";
order.paymentType = @"1";
order.inputCharset = @"utf-8";
order.itBPay = @"30m";
order.showUrl = @"m.alipay.com";
//應用注冊scheme,在AlixPayDemo-Info.plist定義URL types
NSString *appScheme = @"alisdkdemo";
//將商品信息拼接成字符串
NSString *orderSpec = [order description];
NSLog(@"orderSpec = %@",orderSpec);
//獲取私鑰并將商戶信息簽名,外部商戶可以根據情況存放私鑰和簽名,只需要遵循RSA簽名規(guī)范,并將簽名字符串base64編碼和UrlEncode
id<DataSigner> signer = CreateRSADataSigner(privateKey);
NSString *signedString = [signer signString:orderSpec];
//將簽名成功字符串格式化為訂單字符串,請嚴格按照該格式
NSString *orderString = nil;
if (signedString != nil) {
orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",
orderSpec, signedString, @"RSA"];
[[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
NSLog(@"reslut = %@",resultDic);
}];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
授權信息
- (NSString *)description
{
if (self.appID.length != 16||self.pid.length != 16) {
return nil;
}
NSArray *decriptionArray = @[[NSString stringWithFormat:@"app_id=\"%@\"", self.appID],
[NSString stringWithFormat:@"pid=\"%@\"", self.pid],
[NSString stringWithFormat:@"apiname=\"%@\"", self.apiName?self.apiName:@"com.alipay.account.auth"],
[NSString stringWithFormat:@"app_name=\"%@\"", self.appName?self.appName:@"mc"],
[NSString stringWithFormat:@"biz_type=\"%@\"", self.bizType?self.bizType:@"openservice"],
[NSString stringWithFormat:@"product_id=\"%@\"", self.productID?self.productID:@"WAP_FAST_LOGIN"],
[NSString stringWithFormat:@"scope=\"%@\"", self.scope?self.scope:@"kuaijie"],
[NSString stringWithFormat:@"target_id=\"%@\"", self.targetID?self.targetID:@"20141225xxxx"],
[NSString stringWithFormat:@"auth_type=\"%@\"", self.authType?self.authType:@"AUTHACCOUNT"],
[NSString stringWithFormat:@"sign_date=\"%@\"", self.signDate?self.signDate:@"2014-12-25 00:00:00"],
[NSString stringWithFormat:@"service=\"%@\"", self.service?self.service:@"mobile.securitypay.pay"]];
return [decriptionArray componentsJoinedByString:@"&"];
}
對這個地方的寫法是不是新手都有疑問呢隧熙,說實話,我這也有疑問
//獲取私鑰并將商戶信息簽名,外部商戶可以根據情況存放私鑰和簽名,只需要遵循RSA簽名規(guī)范,并將簽名字符串base64編碼和UrlEncode
id<DataSigner> signer = CreateRSADataSigner(privateKey);
NSString *signedString = [signer signString:orderSpec];
對于id < DataSigner > 我的理解是對于生成的對象要遵循一種協議幻林,也是C的寫法贞盯,還希望大神看到回復解釋一下,這種原理沪饺,以前看百度地圖的時候看到過
還有個地方需要主要的躏敢,驗證公鑰,這里我只是隨便寫的,我最近看到公司項目這一塊了整葡,就記錄一下件余,以便能幫助更多新手,提高效率
//跳轉支付寶錢包進行支付,處理支付結果啼器,這個只是輔佐訂單支付結果回調
[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
NSString * query = [[url query] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
id<DataVerifier> dataVeri = CreateRSADataVerifier(@"public");
//驗證簽名是否一致
if ([dataVeri verifyString:@"22" withSign:@"ee"]) {
}
NSLog(@"result = %@",resultDic);
NSString * str = resultDic[@"memo"];
NSLog(@"memo = %@",str);
}];