1、找到跟支付相關(guān)的SDK仰坦,在工程中導(dǎo)入相應(yīng)的庫
2、進(jìn)入支付平臺(tái)注冊應(yīng)用计雌,獲取partnerID
3悄晃、獲取私鑰(代碼中)? 公鑰(開發(fā)平臺(tái)中提交)
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ā)平臺(tái)中提交) ,如圖:
3.jpg
四鹃祖、實(shí)現(xiàn)相應(yīng)的功能:
4.jpg
五溪椎、支付寶客戶端加載,回調(diào)時(shí)設(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)支付寶錢包進(jì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)支付寶錢包進(jì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