把SDK的AlipaySDK.bundle,AlipaySDK.framework 与demo里面的几个文件托人 完成后如下图
iOS7 之前有后缀差别
运行一下如果出现openssl.h not found 则在自己工程文件夹里建一个文件夹,把支付宝所需要的东西都拷贝进去,然后倒入工程 在Build Settings 里面找到header search paths 把文件夹拖入进去 即可 不行多试几次
运行没问题后 在你需要调用的支付宝的界面引入
#import <AlipaySDK/AlipaySDK.h>
#import "Order.h"
#import "DataSigner.h"
NSString *partner =@"";
NSString *seller =@"";
NSString *privateKey =@"";
//如果partner和seller获取失败,提示用户
if ([partner length] ==0 ||
[seller length] == 0 ||
[privateKey length] == 0)
{
UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:@"提示"
message:@"缺少partner或者seller或者私钥。"
delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
return;
}
//2.创建订单对象
Order *order=[[Orderalloc]init];
order.partner=partner;
order.seller=seller;
order.tradeNO=@"201591734927845485340"; //订单ID
order.productName=@"iphone 6s" ; //商品标题
order.productDescription =@"超高配置 2个内存配A9处理器 其性能是iphone6的1.8倍";//商品描述
order.amount = @"0.01" ;//商品价格
order.notifyURL = @"http://www.xxx.com"; //回调URL
order.service =@"mobile.securitypay.pay";
order.paymentType = @"1";
order.inputCharset = @"utf-8";
order.itBPay = @"30m";
order.showUrl =@"m.alipay.com";
NSString *appScheme = @"thinklion";
//将商品信息拼接成字符串 商品信息也是服务器返回的
NSString *orderSpec = [order description];
//此数据是服务器返回的证书类型
//获取私钥并将商户信息签名,外部商户可以根据情况存放私钥和签名,只需要遵循RSA签名规范,并将签名字符串base64编码和UrlEncode
id<DataSigner> signer =CreateRSADataSigner(privateKey);
//此签名信息是Util和openssl里面的文件生成的数据 其实应该是我们服务器端给我们返回的
NSString *signedString = [signer signString:orderSpec];
NSLog(@"orderSpec = %@",orderSpec);
NSString *orderString = [NSStringstringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",
orderSpec, signedString, @"RSA"];
//如果有签名字符串才打开支付
if(signedString!=nil){
[[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
NSLog(@"reslut = %@",resultDic);
}];
//回调方法
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
//如果极简 SDK不可用,会跳转支付宝钱包进行支付,需要将支付宝钱包的支付结果回传给 SDK if ([url.host isEqualToString:@"safepay"]) {
[[AlipaySDKdefaultService] processOrderWithPaymentResult:urlstandbyCallback:^(NSDictionary *resultDic) {
NSLog(@"result = %@",resultDic);
}];
if ([url.hostisEqualToString:@"platformapi"]){//支付宝钱包快登授权返回 authCode
[[AlipaySDKdefaultService] processAuthResult:urlstandbyCallback:^(NSDictionary *resultDic) {
NSLog(@"result = %@",resultDic);
}];
}
return YES;
}