這是開頭語
前不久做了一個項目,涉及到支付寶和銀聯支付,支付寶和銀聯都是業界的老大哥,文檔、SDK都是很屌,屌的找不到,屌的看不懂,屌到沒朋友(吐槽而已),本文將涉及到的最新可用SDK、文檔,以及本人支付遇到的一些坑標記一下。
資料
Demo給了一個訂單號,做測試使用,若出現支付失敗什麼的,可能是已經被別人給支付了,或者是服務器訂單過期了 ~
一、支付寶
1.1 請閱讀支付寶文檔和Demo
1.2 導入對應的庫
將支付寶Demo中得這些東西全拷貝過來
1
2
3
4
5
|
localhost:alipay mac$ ls APAuthV2Info.h Order.h libssl.a APAuthV2Info.m Order.m openssl AlipaySDK.bundle Util AlipaySDK.framework libcrypto.a |
導入系統庫
1
|
SystemConfiguration.framework |
設置一下search paths
1
|
build setting ->搜索search path,然後你懂的 |
完成後,編譯一下,看有沒有錯,有錯沒錯,還是下一步吧。
1.3 對接
支付寶對節前,你還是需要從服務器拿到一下一堆東西
支付寶接口文檔中寫了3p參數列表,--! 總結下我用的到,或者說是Demo中提到的,別的就超出範圍了
1
2
3
4
5
|
合作者身份ID alipayPartner = @ "2088一串數字" ; 簽名 aliPayPrivateKey = @ "很長很長的私鑰" ; //公鑰 alipayRSA_PUBLIC=@"一般長"; 客戶端不用服務器都給我了--~! 服務器異步通知頁面路徑 alipayNotifServerURL = @ "一個網址" ; //支付結果,支付寶會通知服務器 |
其他一些參數(與購買產品相關,設計到業務了,客戶端/服務器誰提供均可)直接貼order代碼了,具體看我的Demo示例.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
Order \*order = [[Order alloc] init]; order.partner = alipayPartner ; order.seller = alipaySeller; order.tradeNO = tn; //訂單ID(由商家自行制定) order.productName = [NSString stringWithFormat:@ "汽車服務充值-%@" ,@ "支付" ]; //商品標題 order.productDescription = [NSString stringWithFormat:@ "%@:支付寶移動支付充值" ,@ "xxxx" ]; //商品描述 order.amount = _txtCNY.text; //商品價格 order.notifyURL = alipayNotifServerURL; //回調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 = URLScheme; |
調用支付寶
1
2
3
4
5
6
7
8
9
10
11
12
|
[[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) { NSLog(@ "reslut = %@" ,resultDic); if ([resultDic[@ "resultStatus" ] intValue]==9000) { //進入充值列表頁面 NSLog(@ "支付成功" ); } else { NSString *resultMes = resultDic[@ "memo" ]; resultMes = (resultMes.length<=0?@ "支付失敗" :resultMes); NSLog(@ "%@" ,resultMes); } }]; |
你可能會發現回調不行->設置回調shema
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
//上面支付時已經傳給了支付寶客戶端回調shema名稱 NSString *appScheme = URLScheme; //具體設置shema方法此處就不再累贅,這兒需要處理來自支付寶shema回調,才能完成上面方法的block回調 在APPDelegate - - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { //跳轉支付寶錢包進行支付,處理支付結果 [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) { NSLog(@ "result = %@" ,resultDic); }]; return YES; } |
二、銀聯
2.1 請去看銀聯文檔和demo
2.2 導入對應的庫
SDK說明
SDK分爲以下兩個版本:
① 支持純無卡交易靜態庫,以下簡稱UPPayPlugin,包含文件:
1
2
3
|
UPPayPlugin.h UPPayPluginDelegate.h libUPPayPlugin.a |
② 支持純無卡交易和VIPOS音頻口支付靜態庫,以下簡稱UPPayPluginPro,包含文件:
1
2
3
|
UPPayPluginPro.h UPPayPluginDelegate.h libUPPayPluginPro.a |
大概這兩個庫就是上述那樣(嗯,裝懂了),具體問商務/後者後臺,我們只需要知道
②需要將.m改成.mm (應該是用c++封裝的音頻...??)
添加SDK包
a) 根據商戶選擇的SDK版本,將sdk/inc目錄和sdk/libs目錄下對應版本的三個文件添加到UPPayDemo工程中;
b) 如果你選擇的是UPPayPlugin版本,添加QuartzCore.framework、Security.framework到工程中;
c) 如果你選擇的是UPPayPluginPro版本,添加QuartzCore.framework、AudioToolbox.framework, CoreAudio.framework、 MediaPlayer.framework, AVFoundation.framework和Security.framework到工程中;
d) 在工程的Build Settings中找到Other Linker Flags中添加-ObjC宏;
導入到工程,讓服務器準備一下交易流水號信息 (什麼他們不懂,讓他們去看文檔 銀 聯),休息一下,喝杯什麼好了
2.3 對接
咱們的服務器也是挺給力的,一盞茶的功夫,就將交易流水號信息 給準備好了,嗯不錯,速度對接一下。
1
2
3
4
|
+ (BOOL)startPay:(NSString*)tn mode:(NSString*)mode viewController:(UIViewController*)viewController delegate:(id)delegate; |
-------------參數說明(必填)-------------------
1
2
3
4
|
tn NSString* 交易流水號信息,銀聯後臺生成,通過商戶後臺返回到客戶端並傳入支付控件; mode NSString* 接入模式設定,兩個值:@ "00" :代表接入生產環境(正式版本需要);@ "01" :代表接入開發測試環境(測試版本需要); viewController UIViewController* 商戶應用程序調用銀聯手機支付的當前UIViewController; delegate id 實現UPPayPluginDelegate方法的UIViewController; |
嗯,這些都是文檔中的,請仔細看看[上線的時候一定藥修改mode模式]。
mode在測試環境下可以銀聯給的測試號 tn=@"01" 測試環境
-
測試使用卡號、手機號信息(此類信息僅供測試,不會發生正式交易)招商銀行預付費卡:
-
卡號:6226 4401 2345 6785
-
密碼:111101
-
[這個居然無效]
-
再來一個:
-
銀行卡號:6216261000000000018
-
身份證號:341126197709218366
-
手 機 號 :13552535506
-
驗 證 碼 :123456 【要點擊獲取驗證碼,不然提交會報錯】
viewcontroller需要幹這些事情
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
*引入頭文件 \ #import "UPPayPluginPro.h" *調用接口 [UPPayPluginPro startPay:tn mode:self.tnMode viewController:self delegate:self]; *實現對應代理方法 \ #pragma mark UPPayPluginResult - (void)UPPayPluginResult:(NSString \*)result { NSString\* msg = [NSString stringWithFormat:@ "%@" , result]; NSLog(@ "msg%@" ,msg); if ([result isEqualToString:@ "msgcancel" ]) { NSLog(@ "取消銀聯支付..." ); } else if ([result containsString:@ "success" ]){ NSLog(@ "支付成功" ); } } |
微信支付
總體來說微信支付需要審覈的比較麻煩,我也沒有去弄一個號親自測試一下,按照文檔demo去走一般不會出什麼問題。
小記
可能遇到銀聯c++編譯問題,把對應的viewcontroller切換成.mm,編譯看看。若有CreateRSADataSigner arm64的,請將支付寶給的DataSigner改成.mm即可。