1.下载支付宝SDK以及Demo

https://doc.open.alipay.com/doc2/detail?treeId=54&articleId=103419&docType=1

2.新建文件夹“AliSDK”,将压缩包内的文件拷贝到该文件夹下,完成后如下图所示:

3.将文件夹拷贝到项目中,

4.执行完第二步后项目目录里会出现蓝色的AliSDK分组。然后添加相应的库文件,添加完成后如下图所示:

5.拷贝完成后编译会出现如下错误:只需要在相应的类内添加:#import <Foundation/Foundation.h>即可解决

6.添加完成后编译仍然有错误:

解决办法:Targets->Build Settings->Header Search Path中添加1中建立的aliSDK文件夹的路径(找到alisdk路径拖拽到这儿就好了):

此时问题解决了。

7.整理项目目录,把添加的库文件移动的framework分组内,ali也移动到framework分组内,如下所示:

8.新建Product类,Product.h内如下所示:

#import <Foundation/Foundation.h>

@interface Product : NSObject{
@private
float _price;
NSString *_subject;
NSString *_body;
NSString *_orderId;
} @property (nonatomic, assign) float price;
@property (nonatomic, copy) NSString *subject;
@property (nonatomic, copy) NSString *body;
@property (nonatomic, copy) NSString *orderId; @end

9.viewController.h

#import "ViewController.h"
#import "Product.h"
#import "Order.h"
#import "AliSDK/Util/DataSigner.h"
#import <AlipaySDK/AlipaySDK.h>
@interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)clickPay:(UIButton *)sender {
[self testPay];
} -(void)testPay{
/*
*点击获取prodcut实例并初始化订单信息
*/
Product *product = [[Product alloc]init];
/*
*商户的唯一的parnter和seller。
*签约后,支付宝会为每个商户分配一个唯一的 parnter 和 seller。
*/ /*============================================================================*/
/*=======================需要填写商户app申请的===================================*/
/*============================================================================*/
NSString *partner = @"";
NSString *seller = @"";
NSString *privateKey = @"";
/*============================================================================*/
/*============================================================================*/
/*============================================================================*/ //partner和seller获取失败,提示
if ([partner length] == ||
[seller length] == ||
[privateKey length] == )
{
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.sellerID = seller;
order.outTradeNO = [self generateTradeNO]; //订单ID(由商家自行制定)
order.subject = product.subject; //商品标题
order.body = product.body; //商品描述
order.totalFee = [NSString stringWithFormat:@"%.2f",product.price]; //商品价格
order.notifyURL = @"http://www.xxx.com"; //回调URL order.service = @"mobile.securitypay.pay";
order.paymentType = @"";
order.inputCharset = @"utf-8";
order.itBPay = @"30m";
order.showURL = @"m.alipay.com"; //应用注册scheme,在AlixPayDemo-Info.plist定义URL types
NSString *appScheme = @"alisdkdemo"; //将商品信息拼接成字符串
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);
}]; } }
/*
生成订单信息
*/
- (NSString *)generateTradeNO
{
static int kNumber = ; NSString *sourceStr = @"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
NSMutableString *resultStr = [[NSMutableString alloc] init];
srand((unsigned)time());
for (int i = ; i < kNumber; i++)
{
unsigned index = rand() % [sourceStr length];
NSString *oneStr = [sourceStr substringWithRange:NSMakeRange(index, )];
[resultStr appendString:oneStr];
}
return resultStr;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

10.appdelegate.m中添加如下代码:

- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation { if ([url.host isEqualToString:@"safepay"]) {
//跳转支付宝钱包进行支付,处理支付结果
[[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<NSString*, id> *)options
{
if ([url.host isEqualToString:@"safepay"]) {
//跳转支付宝钱包进行支付,处理支付结果
[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
NSLog(@"result = %@",resultDic);
}];
}
return YES;
}

大功告成!!

iOS--支付宝环境集成的更多相关文章

  1. iOS支付宝支付集成

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

  2. ios 支付宝支付集成

    支付宝支付: 下载官方demo,把需要的framwork下载下来,在自己的工程中,新建文件夹,然后全部塞进去,到build phases中把需要的全部导入,其中xcode7以上需要多导入两个.a文件, ...

  3. iOS 支付宝支付集成获取私钥

    http://doc.open.alipay.com/doc2/apiList?docType=4 登录到支付宝开放平台,下载相关支付宝支付的demo.解压出来有3个文件夹.(服务端demo,客户端 ...

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

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

  5. 李洪强iOS开发支付集成之支付宝支付

    iOS开发支付集成之支付宝支付 下载支付宝SDK 首先是开发包下载,还是比较难发现的,网上以前文章中的链接都打不开,我找了好久才找到的.最新的地址在这里(注意的是下载出来的SDK包里面并没有传说中的开 ...

  6. iOS开发支付集成之支付宝支付

    项目中要用到支付功能,需要支付宝,微信,银联三大支付,所以打算总结一下,写两篇文章,方便以后的查阅, 大家在做的时候也能稍微参考下,用到的地方避免再次被坑.这是第二篇支付宝集成,第一篇银联支付在这里. ...

  7. 转-android 支付宝SDK集成

    http://blog.csdn.net/kroclin/article/details/40746779 一.前言 最近做的项目刚好要集成支付宝,上网找了很多资料,介绍得感觉不是很全面,所以我经过这 ...

  8. 李洪强iOS开发支付集成之银联支付

    iOS开发支付集成之银联支付 银联官网在这里,这里能下载SDK或者是看文档.最新的版本写的简单了很多,看文档一直做下去基本上就没问题了. 首先,SDK在这里下载,里面包含需要的库文件和详细的文档. 银 ...

  9. 李洪强iOS开发支付集成之微信支付

    iOS开发支付集成之微信支付 微信支付也是需要签名的,也跟支付宝一样,可以在客户端签名,也可以在后台签名(当然,为了安全还是推荐在服务器上做签名,逻辑也比较好理解). 1 - 集成前首先要看看文档 开 ...

  10. 使用 Jenkins 搭建 iOS/Android 持续集成打包平台【转】

    背景描述 根据项目需求,现要在团队内部搭建一个统一的打包平台,实现对iOS和Android项目的打包.而且为了方便团队内部的测试包分发,希望在打包完成后能生成一个二维码,体验用户(产品.运营.测试等人 ...

随机推荐

  1. Uliweb之 ORM基本使用(Sqlalchemy)

    参考:http://limodou.github.io/uliweb-doc/zh_CN/db/orm.html#title_1-2 ORM基本使用¶ 使用要求¶ 需要安装sqlalchemy 0.7 ...

  2. ko内核模块文件以及载入模块命令modprobe insmod

    原文链接:https://blog.csdn.net/evenness/article/details/7655921?utm_source=blogxgwz5 modprobe: Load modu ...

  3. BZOJ 5334--[Tjoi2018]数学计算(线段树)

    5334: [Tjoi2018]数学计算 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 220  Solved: 147[Submit][Status ...

  4. php主要用于哪几方面

    1,服务端脚本,网站和web应用程序,web服务器,php解析器,web浏览器 2,命令行脚本 3,编写桌面应用程序

  5. echart 遇到的点

    1,图表随着外部container变化而变化: window.onresize = myChart.resize (拿着resize在api文档中搜就看到了)

  6. Docker容器(三)

    一.创建容器 容器是Docker另一个核心的概念,简单来说,容器是镜像的一个运行实例,所不同的是,镜像是静态的只读文件,而容器带有运行时需要的可写文件层 1.1. 新建容器 使用docker crea ...

  7. 屏蔽百度及其广告的部分Host

    127.0.0.44 www.baidu.com127.0.0.44 cpro.baidu.com127.0.0.44 hm.baidu.com127.0.0.44 bdimg.share.baidu ...

  8. An assembly specified in the application dependencies manifest

    .Net Core 运行的时候报错 An assembly specified in the application dependencies manifest (xxx.deps.json) was ...

  9. 移植C/C++代码的十个技巧

    这篇文章是我翻译自Top 10 tips for code porting c/c++的一篇小短文,以下是翻译全文,如有错误请留言或查阅原文. 代码的可移植性基本上是指使得源代码能够在不同的平台上编译 ...

  10. @JsonView注解的使用

    看到一个新的注解以前没有用过,记录一下使用方法. 注意是:com.fasterxml.jackson.annotation.JsonView @JsonView可以过滤pojo的属性,使Control ...