支付宝流程&微信支付

1.支付宝
开发平台 (找不到iOS sdk)
http://open.alipay.com/index.htm(这个里面找不到sdk) 须要进入下面的连接

如今很多app内都集成了支付宝功能

使用支付宝进行一个完整的支付功能,大体有如下步骤:
1>先与支付宝签约,得到商户ID(partner)和帐号ID(seller)
(这个主要是公司的负责)

2>下载相应的公钥私钥文件(加密签名用)
3>下载支付宝SDK
官方sdk页面地址:(藏得很深)
https://b.alipay.com/order/productDetail.htm?productId=2014110308141993&tabId=4#ps-tabinfo-hash
里面提供了很是详细的文档、如何签约、如何得到公钥私钥、如何调用支付接口。

4>生成订单信息
5>调用支付宝客户端,由支付宝客户端跟支付宝安全服务器打交道
6>支付完毕后返回支付结果给商户客户端和服务器
SDK里有集成支付宝功能的一个Demo>  集成支付功能的具体操做方式,能够参考Demo






调用支付接口能够参考AlixPayDemoViewController的下面方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

如何建立订单 ( 订单根据本身公司看是什么样的)
如何签名
如何调用支付接口
都在这个方法里面了
01
//
02
//选中商品调用支付宝快捷支付
03
//
04
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
05
{
06
    /*
07
     *点击获取prodcut实例并初始化订单信息
08
     */
09
    Product *product = [_products objectAtIndex:indexPath.row];
10
     
11
    /*
12
     *商户的惟一的parnter和seller。
13
     *本demo将parnter和seller信息存于(AlixPayDemo-Info.plist)中,外部商户能够考虑存于服务端或本地其余地方。
14
     *签约后,支付宝会为每一个商户分配一个惟一的 parnter 和 seller。
15
     */
16
    //若是partner和seller数据存于其余位置,请改写下面两行代码
17
    NSString *partner = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"Partner"];
18
    NSString *seller = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"Seller"];
19
     
20
    //partner和seller获取失败,提示
21
    if ([partner length] == 0 || [seller length] == 0)
22
    {
23
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
24
                                                        message:@"缺乏partner或者seller。"
25
                                                       delegate:self
26
                                              cancelButtonTitle:@"肯定"
27
                                              otherButtonTitles:nil];
28
        [alert show];
29
        [alert release];
30
        return;
31
    }
32
     
33
    /*
34
     *生成订单信息及签名
35
     *因为demo的局限性,本demo中的公私钥存放在AlixPayDemo-Info.plist中,外部商户能够存放在服务端或本地其余地方。
36
     */
37
    //将商品信息赋予AlixPayOrder的成员变量
38
    AlixPayOrder *order = [[AlixPayOrder alloc] init];
39
    order.partner = partner;
40
    order.seller = seller;
41
    order.tradeNO = [self generateTradeNO]; //订单ID(由商家自行制定)
42
    order.productName = product.subject; //商品标题
43
    order.productDescription = product.body; //商品描述
44
    order.amount = [NSString stringWithFormat:@"%.2f",product.price]; //商品价格
45
    order.notifyURL =  @"http://www.xxx.com"; //回调URL
46
     
47
    //应用注册scheme,在AlixPayDemo-Info.plist定义URL types,用于快捷支付成功后从新唤起商户应用
48
    NSString *appScheme = @"AlixPayDemo";
49
     
50
    //将商品信息拼接成字符串
51
    NSString *orderSpec = [order description];
52
    NSLog(@"orderSpec = %@",orderSpec);
53
     
54
    //获取私钥并将商户信息签名,外部商户能够根据状况存放私钥和签名,只须要遵循RSA签名规范,并将签名字符串base64编码和UrlEncode
55
    id<DataSigner> signer = CreateRSADataSigner([[NSBundle mainBundle] objectForInfoDictionaryKey:@"RSA private key"]);
56
    NSString *signedString = [signer signString:orderSpec];
57
     
58
    //将签名成功字符串格式化为订单字符串,请严格按照该格式
59
    NSString *orderString = nil;
60
    if (signedString != nil) {
61
        orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",
62
                                 orderSpec, signedString, @"RSA"];
63
         
64
        //获取快捷支付单例并调用快捷支付接口
65
        AlixPay * alixpay = [AlixPay shared];
66
        int ret = [alixpay pay:orderString applicationScheme:appScheme];
67
         
68
        if (ret == kSPErrorAlipayClientNotInstalled) {
69
            UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"提示"
70
                                                                 message:@"您尚未安装支付宝快捷支付,请先安装。"
71
                                                                delegate:self
72
                                                       cancelButtonTitle:@"肯定"
73
                                                       otherButtonTitles:nil];
74
            [alertView setTag:123];
75
            [alertView show];
76
            [alertView release];
77
        }
78
        else if (ret == kSPErrorSignError) {
79
            NSLog(@"签名错误!");
80
        }
81
 
82
    }
83
 
84
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
85
}
主要集成的关键就是下面几步:
01
//.封装订单模型
02
AlixPayOrder *order = [[AlixPayOrder alloc] init];
03
// 生成订单描述
04
NSString *orderSpec = [order description];
05
 
06
//2.签名
07
id<DataSigner> signer = CreateRSADataSigner(@“私钥key”);
08
// 传入订单描述 进行 签名
09
NSString *signedString = [signer signString:orderSpec];
10
 
11
 
12
//3.生成订单字符串
13
NSString *orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",
14
                         orderSpec, signedString, @"RSA"];
15
 
16
//4.调用支付接口
17
AlixPay * alixpay = [AlixPay shared];
18
// appScheme:商户本身的协议头
19
int ret = [alixpay pay:orderString applicationScheme:appScheme];





2.微信支付
https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&lang=zh_CN
相关文章
相关标签/搜索