开发在手机端的时候(客户端),我们主要负责客户端(手机端)的开发,所以那些繁琐的到支付宝官网填写商户信息可以留给后台去弄,后台只要把:

1回调地址,

2app的ID,

3商户的私钥(privateKey),

4商户ID(partner),

5支付宝账号(seller),提供给你就好了。

如果想学习怎么在支付宝填写商户信息的话可以官网按着步骤来:

https://b.alipay.com/signing/productDetail.htm?productId=I1011000290000001002 
秘钥的设置可以参考支付宝官网:
https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.kDer5c&treeId=58&articleId=103578&docType=1 
 
这里我主要讲支付宝SDK如何放到项目里(客户端):
1。首先下载支付宝SDK(dome也下载下来),准备好这些文件:

2.在项目里配置好支付宝SDK所需的框架

3.导入后,运行运行项目,会发现报错,这样你要按照支付宝提供的方法添加路径(因为项目中不能识别某个文件):#include<openssl/asn1.h>

点击项目名称,点击“Build Settings”选项卡,在搜索框中,以关键字“search”搜索,对“Header Search Paths”增加头文件路径:$(SRCROOT)/项目名称。如果头文件信息已增加,可不必再增加。

4,之后就要配置跳转的URL Types :

点击项目名称,点击“Info”选项卡,在“URL Types”选项中,点击“+”,在“URL Schemes”中输入“alisdkdemo”。“alisdkdemo”来自于文件“APViewController.m”的NSString *appScheme = @“alisdkdemo”;。

注意:这里的URL Schemes中输入的alisdkdemo,为测试demo,实际商户的app中要填写独立的scheme,建议跟商户的app有一定的标示度,要做到和其他的商户app不重复,否则可能会导致支付宝返回的结果无法正确跳回商户app。

5.最后要记得配置 支付宝白名单 ,在info.plist设置

这样配置就完成了,最后是代码的调用了。

6.1在appdelegate

  1. #import "AppDelegate.h"
  2. #import <AlipaySDK/AlipaySDK.h>
  3. #import "Product.h"
  4. #import "Order.h"
  5. #import "DataSigner.h"
  6. @interface AppDelegate ()
  7. @end
  8. @implementation AppDelegate
  9. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  10. // Override point for customization after application launch.
  11. return YES;
  12. }
  13. -(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options{
  14. [self alipayUrlAction:url];
  15. return YES;
  16. }
  17. -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
  18. //有多中支付方式,要用scheme 来进行判断,看是那种途径的url.
  19. [self alipayUrlAction:url];
  20. return YES;
  21. }
  22. -(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
  23. [self alipayUrlAction:url];
  24. return YES;
  25. }
  26. -(void)alipayUrlAction:(NSURL *)url{
  27. [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
  28. if ([[resultDic valueForKey:@"resultStatus"] intValue] == 9000) {
  29. if ([_aliDelegate respondsToSelector:@selector(alipydidSuccess)]) {
  30. [_aliDelegate alipydidSuccess];
  31. }
  32. }else{
  33. if ([_aliDelegate respondsToSelector:@selector(alipydidFaile)]) {
  34. [_aliDelegate alipydidFaile];
  35. }
  36. }
  37. }];
  38. }
  39. -(void)payByAlipay:(Product *)product{
  40. /*
  41. *商户的唯一的parnter和seller。
  42. *签约后,支付宝会为每个商户分配一个唯一的 parnter 和 seller。
  43. */
  44. /*============================================================================*/
  45. /*=======================需要填写商户app申请的===================================*/
  46. /*============================================================================*/
  47. NSString *partner = @"";        //商户id
  48. NSString *seller = @"";         //账户id  签约账号。
  49. NSString *privateKey = @"";     // md5
  50. //partner和seller获取失败,提示
  51. if ([partner length] == 0 ||
  52. [seller length] == 0 ||
  53. [privateKey length] == 0)
  54. {
  55. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
  56. message:@"缺少partner或者seller或者私钥。"
  57. delegate:self
  58. cancelButtonTitle:@"确定"
  59. otherButtonTitles:nil];
  60. [alert show];
  61. return;
  62. }
  63. /*
  64. *生成订单信息及签名
  65. */
  66. //将商品信息赋予AlixPayOrder的成员变量
  67. Order *order = [[Order alloc] init];
  68. order.partner = partner;
  69. order.sellerID = seller;
  70. order.outTradeNO = @"xxxxxx"; //订单ID(由商家自行制定)
  71. order.subject = product.productName; //商品标题
  72. order.body = product.productName; //商品描述
  73. order.totalFee = [NSString stringWithFormat:@"%.2f",product.price]; //商品价格
  74. order.notifyURL =  @"http://www.xxx.com"; //回调URL
  75. order.service = @"mobile.securitypay.pay";
  76. order.paymentType = @"1";
  77. order.inputCharset = @"utf-8";
  78. order.itBPay = @"30m";
  79. order.showURL = @"m.alipay.com";
  80. //应用注册scheme,在AlixPayDemo-Info.plist定义URL types
  81. NSString *appScheme = @"alisdkdemo";
  82. //将商品信息拼接成字符串
  83. NSString *orderSpec = [order description];
  84. NSLog(@"orderSpec = %@",orderSpec);
  85. //获取私钥并将商户信息签名,外部商户可以根据情况存放私钥和签名,只需要遵循RSA签名规范,并将签名字符串base64编码和UrlEncode
  86. id<DataSigner> signer = CreateRSADataSigner(privateKey);
  87. NSString *signedString = [signer signString:orderSpec];
  88. //将签名成功字符串格式化为订单字符串,请严格按照该格式
  89. NSString *orderString = nil;
  90. if (signedString != nil) {
  91. orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",
  92. orderSpec, signedString, @"RSA"];
  93. [[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
  94. NSLog(@"reslut = %@",resultDic);
  95. if ([[resultDic valueForKey:@"resultStatus"] intValue] == 9000) {  //成功
  96. if ([_aliDelegate respondsToSelector:@selector(alipydidSuccess)]) {
  97. [_aliDelegate alipydidSuccess];
  98. }
  99. }else{  //失败
  100. if ([_aliDelegate respondsToSelector:@selector(alipydidFaile)]) {
  101. [_aliDelegate alipydidFaile];
  102. }
  103. }
  104. }];
  105. }
  106. }
  107. @end

6.1ViewController

  1. #import "ViewController.h"
  2. #import "Product.h"
  3. #import "Order.h"
  4. #import <AlipaySDK/AlipaySDK.h>
  5. #import "AppDelegate.h"
  6. @interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
  7. @property (weak, nonatomic) IBOutlet UITableView *myTableView;
  8. @property(nonatomic, strong)NSMutableArray *productList;
  9. @end
  10. @implementation ViewController
  11. - (void)viewDidLoad {
  12. [super viewDidLoad];
  13. [self generateData];
  14. }
  15. #pragma mark -
  16. #pragma mark   ==============产生随机订单号==============
  17. - (NSString *)generateTradeNO
  18. {
  19. static int kNumber = 15;
  20. NSString *sourceStr = @"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  21. NSMutableString *resultStr = [[NSMutableString alloc] init];
  22. srand((unsigned)time(0));
  23. for (int i = 0; i < kNumber; i++)
  24. {
  25. unsigned index = rand() % [sourceStr length];
  26. NSString *oneStr = [sourceStr substringWithRange:NSMakeRange(index, 1)];
  27. [resultStr appendString:oneStr];
  28. }
  29. return resultStr;
  30. }
  31. #pragma mark -
  32. #pragma mark   ==============产生订单信息==============
  33. - (void)generateData{
  34. //    NSArray *subjects = @[@"1",
  35. //                          @"2",@"3",@"4",
  36. //                          @"5",@"6",@"7",
  37. //                          @"8",@"9",@"10"];
  38. NSArray *body = @[@"我是测试数据",
  39. @"我是测试数据",
  40. @"我是测试数据",
  41. @"我是测试数据",
  42. @"我是测试数据",
  43. @"我是测试数据",
  44. @"我是测试数据",
  45. @"我是测试数据",
  46. @"我是测试数据",
  47. @"我是测试数据"];
  48. self.productList = [[NSMutableArray alloc] init];
  49. for (int i = 0; i < [body count]; ++i) {
  50. Product *product = [[Product alloc] init];
  51. product.productName = [body objectAtIndex:i];
  52. product.price = 0.01f+pow(10,i-2);
  53. [self.productList addObject:product];
  54. }
  55. }
  56. #pragma mark -
  57. #pragma mark UITableViewDelegate
  58. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  59. {
  60. return 55.0f;
  61. }
  62. #pragma mark -
  63. #pragma mark UITableViewDataSource
  64. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  65. {
  66. return [self.productList count];
  67. }
  68. //
  69. //用TableView呈现测试数据,外部商户不需要考虑
  70. //
  71. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  72. {
  73. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
  74. reuseIdentifier:@"Cell"];
  75. Product *product = [self.productList objectAtIndex:indexPath.row];
  76. cell.textLabel.text = product.productName;
  77. cell.detailTextLabel.text = [NSString stringWithFormat:@"一口价:%.2f",product.price];
  78. return cell;
  79. }
  80. #pragma mark -
  81. #pragma mark   ==============点击订单模拟支付行为==============
  82. //
  83. //选中商品调用支付宝极简支付
  84. //
  85. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  86. {
  87. /*
  88. *点击获取prodcut实例并初始化订单信息
  89. */
  90. Product *product = [self.productList objectAtIndex:indexPath.row];
  91. AppDelegate *appdele = (AppDelegate *)[UIApplication sharedApplication].delegate;
  92. [appdele payByAlipay:product];
  93. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  94. }
  95. - (void)didReceiveMemoryWarning {
  96. [super didReceiveMemoryWarning];
  97. // Dispose of any resources that can be recreated.
  98. }
  99. @end
6.3 Product.h
  1. #import <Foundation/Foundation.h>
  2. @interface Product : NSObject
  3. @property (nonatomic, copy)   NSString* productName;
  4. @property (nonatomic, assign) float price;
  5. @end

IOS --支付宝SDK 分解讲解的更多相关文章

  1. iOS支付宝SDK回调那坑

    支付宝钱包支付接口开发包2.0标准版(iOS 2.2.1) ,回调不出来,demo给出的方法是: - (BOOL)application:(UIApplication *)application op ...

  2. IOS 支付宝 SDK 申请

    https://b.alipay.com/order/productDetail.htm?productId=2013080604609654&tabId=4#ps-tabinfo-hash

  3. 基于IOS下的支付宝SDK的学习与使用——实现产品支付(二)

    首先本篇为作者原创,仅供学习使用,以后会不断完善,精炼.阅读之前请参考  上一篇 上一篇 中详细说明了结合官方支付宝SDK,对工程环境进行的一些配置,实现了支付,本篇重点说明一下,注意事项和原理,主要 ...

  4. iOS开发——高级篇——如何集成支付宝SDK

    一.什么是支付宝 第三方支付平台 和内购非常相似内购是用户将钱付款给苹果,之后苹果分成给商户支付宝是用户将钱付款给支付宝,之后支付宝将钱转入我们的账户 使用支付宝前提购买的物品必须是和应用程序无关的. ...

  5. cocos2d-x + Lua接入iOS原生SDK的实现方案[转]

    相信很多朋友在使用cocos2d-x+lua开发游戏时都遇到过接入iOS原生SDK的问题,比如常见的接应用内支付SDK,广告SDK或是一些社交平台SDK等等,我也没少接过这类SDK.这篇文章主要是对我 ...

  6. iOS支付宝集成详细流程

    实现支付宝支付的准备工作: 1.向支付宝签约,成为支付宝的商户 签约完成后,支付宝会提供一些必要的数据给我们 商户ID:partner 账号ID:seller 即支付宝账号 签约需要营业执照 2.获取 ...

  7. [原创]cocos2d-x + Lua接入iOS原生SDK的实现方案

    相信很多朋友在使用cocos2d-x+lua开发游戏时都遇到过接入iOS原生SDK的问题,比如常见的接应用内支付SDK,广告SDK或是一些社交平台SDK等等,我也没少接过这类SDK.这篇文章主要是对我 ...

  8. iOS支付宝支付集成

    概述 iOS支付宝支付集成 详细 代码下载:http://www.demodashi.com/demo/10729.html 支付宝和微信都是业界的老大哥,相信大家都有所觉得文档.SDK都是各种坑吧( ...

  9. iOS - 集成SDK问题

    1.大部分社交平台接口不支持https协议. 问题描述:在iOS9下,系统默认会拦截对http协议接口的访问,因此无法获取http协议接口的数据.对ShareSDK来说,具体表现可能是,无法授权.分享 ...

随机推荐

  1. [SaltStack] 基础介绍

    今天有时间把以前研究过的saltstack梳理总结下 -:) salt是干什么的我就不多说了, 大家Google下资料很多的, 简单来说就是func+puppet: 配置文件管理 远程命令调用 Cro ...

  2. 三个div向左浮动不在同一行,向右浮动在同一行的解决办法

    前几天在写代码的时候发现了一个问题,问题的大致描述如下: 在一个大的div中,同一行有三个小的div,当三个小的div均向左浮动时,会出现换行问题,均向右浮动时却在同一行. 解决这个问题的方法是在:在 ...

  3. springBoot yml 和 properties

    加载顺序不一致,application.yml 在前,application.properties 在后. yml 文件内容 server: port: 8081 spring: redis: dat ...

  4. POJ3086 Treats for the Cows(区间DP)

    题目链接  Treats for the Cows 直接区间DP就好了,用记忆化搜索是很方便的. #include <cstdio> #include <cstring> #i ...

  5. Ansible文本操作实例

    以下三个demo是最常见的anbible编辑文件的场景. demo1: 在文本文件某个标记前添加一段内容,如果已经添加,第二次执行不会重复添加. - name: demo1 change the xm ...

  6. Maximum Product Subarray - LeetCode

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  7. Factory Method 和AbstractFactory

    对应慕课视频的连接:https://www.imooc.com/video/5316 1,工厂模式的应用场景 有一组类似的对象需要被创建 在编码时不能预见需要被创建哪种类的实例 在系统需要考虑扩展性的 ...

  8. ylb:SQL 存储过程(Procedure)

    ylbtech-SQL Server: SQL Server-SQL 存储过程(Procedure) 1,存储过程(Procedure)-基本创建与操作 2,存储过程(Procedure)-入参 3, ...

  9. 社区管理有捷径!Wish3D Earth社区网格化管理案例重磅上线

    社区网格化是精细化.全覆盖.高效率的社区管理模式,便捷有效的社区网格化管理平台是社区网格化管理的关键. Wish3D Earth全新上线三维社区网格化管理平台,使用实景三维模型作为地图,地形地貌真实展 ...

  10. 【FUN】——英文版面青年教育网站策划&GUI设计

    写在前面:这个教育网页一共分为四个页面,首页.课程.活动.空间.是我在学习网页设计与策划的时候作为知识应用练习做的,主要使用Photoshop软件设计构图,其中图片素材与部分灵感来源于网络. 一.网站 ...