iOS--支付寶支付

1、找到跟支付相關(guān)的SDK,在工程中導(dǎo)入相應(yīng)的庫

2、進入支付平臺注冊應(yīng)用,獲取partnerID

3、獲取私鑰(代碼中)? 公鑰(開發(fā)平臺中提交)

4、Xcode配置

1)設(shè)置boudle id

2) 設(shè)置 partnerID sellerID privatekey

3) 生成訂單信息

4) 私鑰簽名

5)拼接訂單字符串

6)發(fā)送支付請求

7)在appdelegate里處理客戶端返回的數(shù)據(jù)

步驟:

一、從https://openhome.alipay.com/platform/home.htm上下載相應(yīng)的 SDK

,并配置相應(yīng)的文件。如圖:

1.jpg

二、導(dǎo)入相應(yīng)的庫:

2.png

三、獲取私鑰(代碼中)? 公鑰(開發(fā)平臺中提交) ,如圖:

3.jpg

四、實現(xiàn)相應(yīng)的功能:

4.jpg

五、支付寶客戶端加載,回調(diào)時設(shè)置,如圖:

5.jpg

六、支付寶客戶端加載,回調(diào)處理

代碼如下:

#import "AppDelegate.h" #import "Order.h"#import "DataSigner.h" #import@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


pragma mark**支付調(diào)用參數(shù)*

//1、 parterID

NSString *parterID? =@"2088602289788156";//2、 sellerIDNSString *sellerID = @".........";//3、privateKeyNSString *privateKey = “......";

//4、生成訂單信息

Order *order = [[Order alloc] init];

//5、支付四要素

order.partner = parterID; //商戶

order.sellerID = sellerID;? //賬號

order.outTradeNO = @"123456";? //訂單號

order.totalFee = @"1.00";? //金額

//6、必要參數(shù)

order.service = @"mobile.securitypay.pay"; //支付接口

order.inputCharset = @"utf-8"; //編碼

order.notifyURL = @"www.XXX.com";? //回調(diào)URL


pragma mark**簽名**

//1、代簽名字符串

NSString*orderSpec = order.description;

//2、使用RSA加密

id singer = CreateRSADataSigner(privateKey);

NSString*singerStr = [singer signString:orderSpec];

//3、生成訂單字符串

NSString*orderStr = [NSStringstringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",? ? ? ? ? ? ? ? ? ? ? orderSpec, singerStr,@"RSA"];

pragma mark ** 支付 *

//1、開始支付

[[AlipaySDK defaultService] payOrder:orderStr fromScheme:@"mypay" callback:^(NSDictionary *resultDic) {

//2、返回支付信息

NSLog(@"%@", resultDic);

}];

return YES;

}

//支付寶客戶端加載

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication

annotation:(id)annotation {

if ([url.host isEqualToString:@"safepay"]) {

//跳轉(zhuǎn)支付寶錢包進行支付,處理支付結(jié)果

[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {

NSLog(@"result = %@",resultDic);

}];

}

return YES;

}

// NOTE: 9.0以后使用新API接口

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary*)options

{

if ([url.host isEqualToString:@"safepay"]) {

//跳轉(zhuǎn)支付寶錢包進行支付,處理支付結(jié)果

[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {

NSLog(@"result = %@",resultDic);

}];

}

return YES;

}

【鏈接】iOS集成微信支付【轉(zhuǎn)載】

http://www.cnblogs.com/g-ios/p/4609341.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容