1.将sdk文件先放到一个文件夹中,然后在程序中add进来
不然容易报错,说找不到某某某文件,解决方法,在headerpath那块写路径
2.添加各种乱其八糟的库
如果导入sdk后运行报错是OBJC_等等。。。一般是静态库导入有问题
3. 在appdelegate里面添加支付代码和回调参数
// 支付宝
#import "Order.h"
#import "DataSigner.h"
#import <AlipaySDK/AlipaySDK.h>
#import "ZKProduct.h"
// 跳转处理
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
//跳转支付宝钱包进行支付,处理支付结果
[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
//【由于在跳转支付宝客户端支付的过程中,商户 app 在后台很可能被系统 kill 了,所以 pay 接 口的 callback 就会失效,请商户对 standbyCallback 返回的回调结果进行处理,就是在这个方法 里面处理跟 callback 一样的逻辑】
NSLog(@"result1111 = %@",resultDic);
}];
return YES;
}
#pragma mark -
#pragma mark 支付宝
- (void)aliPayWithProduct:(ZKProduct *)product {
/*
*商户的唯一的parnter和seller。
*签约后,支付宝会为每个商户分配一个唯一的 parnter 和 seller。
*/
/*============================================================================*/
/*=======================需要填写商户app申请的===================================*/
/*============================================================================*/
NSString *partner = @"208812186873****";
NSString *seller = @"****@***.com";
NSString *privateKey = @"MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKqa2/bw8grvU5uL6rZpvhaOcbDh8SDtSrRNJzGXer8ACjVdW41doOMthBOqxg7mtSF6ktng+JgRNpIuHRAQFglt85WQy83hIS88Sw9MIsvGGIkSrelLR1hgMNaCkJj2uKW9qJlCfXw3E3Jx7u9mSt++Lk0UozqCqgt9mFJCdGkJAgMBAAECgYB2ceVdYJLqvJXTXCSsWGW8y1BrebIrJhPDcf1QFNcHXEO6IQK69tIIZ0VXUi0Hk20VvT/PPL3a9bhpbNKIoGJrLqKFoejUREq6U88kbhPvYUHmFoA6hHMFJEwS5NiauHUmFllqRgC7Q+BZOFo2gxlmobUU9nhKqPRws9vXnwOsAQJBAOAUVAiqazPKoTlhpyKhlCy1wE5aVU4gXb/ZgVB1bMSCYw8BBJoecoa+L4mvcArU+AQ497fjUA2VQATBMCmB6ukCQQDC6G/M9fuM9Va5PjTMN6k5Apl1Ri58O210BV9RagMHEdUPkOoGOYlb6sgdAQ0W6Mk2xoHKaXGBfKA2/HkFJXkhAkBqJLb5s+A8FEvypnNJUEikNSP2+YtXCrXd3uYGetke7LSHsu+/IZUWhph2HAhy2RbyyRlundqZ1I0Ss4Bg6Q2hAkEAtn9VT6BzLQT7cu/gF+d2N79LWRehpwkt7xioq16L/y6fRLf3qGRvTPWE8kNtsim9XeB43sHkWc4LZfD4j+0KgQJAU4zxxqzQqGdoSxSF7j8+2VkVqRms369AcV/xUKB9ppZdC6Ljln+jo2m/vxJFu2IY179/U5cvJ2f9C057******";
// 合作者身份ID(partner)
// 卖家支付宝用户号
// 私钥
/*============================================================================*/
/*============================================================================*/
/*============================================================================*/
//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 = product.orderId;//[self generateTradeNO]; //订单ID(由商家自行制定)
order.productName = product.subject; //商品标题
order.productDescription = product.body; //商品描述
// order.amount = [NSString stringWithFormat:@"%.2f", product.price]; //商品价格
order.amount = @"0.01";
order.notifyURL = @"http://pay.getwant.com:8080/switchplatform/alipay/returnfromApp "; //回调URL
/*==========================================需要你做修改=======================*/
order.service = @"mobile.securitypay.pay";
order.paymentType = @"1";
order.inputCharset = @"UTF-8";
order.itBPay = @"30m";
order.showUrl = @"m.alipay.com";
// URL types 一致
//应用注册scheme,在AlixPayDemo-Info.plist定义URL types
NSString *appScheme = @"SwitchPool";
//将商品信息拼接成字符串
NSString *orderSpec = [order description];
NSLog(@"orderSpec = %@",orderSpec);
//获取私钥并将商户信息签名,外部商户可以根据情况存放私钥和签名,只需要遵循RSA签名规范,并将签名字符串base64编码和UrlEncode
id<DataSigner> signer = CreateRSADataSigner(privateKey);
NSString *signedString = [signer signString:orderSpec];
// NSString *signedString = @"9999999";
//将签名成功字符串格式化为订单字符串,请严格按照该格式
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 *strMsg = nil;
switch ([[resultDic objectForKey:@"resultStatus"] integerValue]) {
case 9000:
strMsg = @"支付成功!";
break;
default:
strMsg = @"支付失败!";
break;
}
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:strMsg delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
if ([strMsg isEqualToString:@"支付成功!"]) {
alertView.tag = 999;
[[NSNotificationCenter defaultCenter]postNotificationName:@"paysucceeded" object:self];
}else
alertView.tag = 888;
[alertView show];
}];
}
}
//客户端提示信息
- (void)alert:(NSString *)title msg:(NSString *)msg {
UIAlertView *alter = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
alter.tag = 999;
[alter show];
}