1. 程式人生 > >iOS中 支付寶錢包具體解釋/第三方支付 韓俊強的博客

iOS中 支付寶錢包具體解釋/第三方支付 韓俊強的博客

rod 一次 也有 rip icontrol data tar content mic

每日更新關註:http://weibo.com/hanjunqiang 新浪微博!

iOS開發人員交流QQ群: 446310206

一、在app中成功完畢支付寶支付的過程

1、申請支付寶錢包。參考網址:

https://b.alipay.com/order/productDetail.htm?productId=2014110308141993&tabId=4#ps-tabinfo-hash
這是使用支付寶支付的第一步,合作申請通過之後,會集成一個開發文件。即使不申請也能夠下載,僅僅是demo中會缺少幾個必須的參數: 在demo中的 PartnerConfig.h 文件裏能夠看到

//合作身份者id。以2088開頭的16位純數字

#define PartnerID @""

//收款支付寶賬號

#define SellerID @""

//安全校驗碼(MD5)密鑰。以數字和字母組成的32位字符

#define MD5_KEY @""

//商戶私鑰,自助生成

#define PartnerPrivKey

//支付寶公鑰(老板給你的)

#define AlipayPubKey @"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRAFljhNhgPdyPuBV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQEB/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5KsiNG9zpgmLCUYuLkxpLQIDAQAB"


僅僅有這幾個參數備齊之後,demo才幹夠完畢支付,所以接下來第二步


2、生成RSA 這個須要在windows系統下生成,開發文檔中也有生成的步驟。我是直接問後臺要了這幾個參數,所以這一步僅僅能簡單寫到這。 3、導入框架 依據集成文件的開發文檔,導入框架。能夠參考demo。

當四個參數都備齊之後能夠先在demo上試一下能不能成功支付。然後再往自己的程序中導入。
每日更新關註:http://weibo.com/hanjunqiang 新浪微博

二、代碼的使用 1、支付須要的參數 在demo中的ViewController.h中能夠看到有這麽一段代碼

@interface Product :NSObject{

@private

float _price;

NSString *_subject;

NSString *_body;

NSString *_orderId;

}


@property (nonatomic,assign) float price;

@property (nonatomic,retain) NSString *subject;

@property (nonatomic,retain) NSString *body;

@property (nonatomic,retain) NSString *orderId;


@end


這個就是所支付產品須要的幾個必要的字段。在開發文檔中能夠看到須要好多參數,但在真正用時。僅僅須要特別註意這幾個即可。demo中有自己主動拼接的方法,到時候直接調用即可。


2、app和支付寶client之間的跳轉

NSString *appScheme = @"AlipaySdkDemo"; //應用跳轉的URL

*這裏要和plist文件裏URL types 以下的字段保持一致


3、支付結果的入口

首先是WAP端的入口。在ViewController.m文件裏能夠找到,這裏返回支付結果,比較簡單。不多說。

獨立端的入口,在AppDelegate裏面,我試著在viewcontroller中找這個,但最後沒找到。最後僅僅能設置一個觀察者,把支付結果發送過來再進行處理。


三、總結

第一次接觸支付方面的東西,剛開始非常迷茫,不明確當中財務方面是怎麽對上號的。

那些都是在後臺進行處理的,iOS開發時須要做的,就是完畢這個支付流程。


==================================詳細看以下流程====================================

第一步:引入框架

技術分享


每日更新關註:http://weibo.com/hanjunqiang 新浪微博


第二步:註意框架及拉進相關文件

技術分享


每日更新關註:http://weibo.com/hanjunqiang 新浪微博


第三步:上代碼

直接建立根視圖:

#import "RootViewController.h"
#import <AlipaySDK/AlipaySDK.h>
#import "Order.h"
#import "DataSigner.h"
@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *button = [UIButton buttonWithType:(UIButtonTypeSystem)];
    [button addTarget:self action:@selector(buttonAction :) forControlEvents:(UIControlEventTouchUpInside)];
    button.frame = CGRectMake(100, 200, 100, 100);
    [button setTitle:@"支付" forState:(UIControlStateNormal)];
    [button setBackgroundColor:[UIColor yellowColor]];
    [self.view addSubview:button];
    self.view.backgroundColor = [UIColor greenColor];

    
}
每日更新關註:http://weibo.com/hanjunqiang 新浪微博


點擊事件:

- (void)buttonAction : (UIButton *)sender
{
//    NSLog(@"支付");
    
    /*
     *點擊獲取prodcut實例並初始化訂單信息
     */
//    Product *product = [self.productList objectAtIndex:indexPath.row];
    
    /*
     *商戶的唯一的parnter和seller。
     *簽約後,支付寶會為每一個商戶分配一個唯一的 parnter 和 seller。
     */
    
    /*============================================================================*/
    /*=======================須要填寫商戶app申請的===================================*/
    /*============================================================================*/
    // 16位的純數字
    NSString *partner = @"2088。

。公司唯一ID"; // 收款賬戶 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 = @"123456"; //訂單ID(由商家自行制定) order.productName = @"太空杯"; //商品標題 order.productDescription = @"耐摔的太空杯"; //商品描寫敘述 order.amount = [NSString stringWithFormat:@"%.2f",0.01]; //商品價格 order.notifyURL = @"http://www.lanou3g.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 = @"xiaohange"; //將商品信息拼接成字符串 NSString *orderSpec = [order description]; NSLog(@"orderSpec = %@",orderSpec); //獲取私鑰並將商戶信息簽名,外部商戶能夠依據情況存放私鑰和簽名,僅僅須要遵循RSA簽名規範,並將簽名字符串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); }]; } } //選中商品調用支付寶極簡支付 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { }

每日更新關註:http://weibo.com/hanjunqiang 新浪微博


終於效果:

技術分享

每日更新關註:http://weibo.com/hanjunqiang 新浪微博

iOS開發人員交流QQ群: 446310206



iOS中 支付寶錢包具體解釋/第三方支付 韓俊強的博客