1添加支付宝源文件和库文件AlipayOrder.h AlipayOrder.m AlipayResult.h AlipayResult.m AlixLibService.h PartnerConfig.h AlipayRsaLib.a Alixpay.bundle AlixPaylib_arc.a libcrypto.a libssl.a
2添加json类库和demo中的rsa签名 json文件夹和RSA文件夹
3添加相关类库 CoreGraphics.framework Foundation.framework UIKit.framework CFNetwork.framework SystemConfiguration.framework
4在delegate文件中加入支付回调函数
//独立客户端回调函数
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
[self parse:url application:application];
return YES;
}
- (void)parse:(NSURL *)url application:(UIApplication *)application {
//结果处理
AlixPayResult* result = [selfhandleOpenURL:url];
if (result)
{
if (result.statusCode == 9000)
{
/*
*用公钥验证签名 严格验证请使用result.resultString与result.signString验签
*/
//交易成功
NSString* key = @"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRAFljhNhgPdyPuBV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQEB/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5KsiNG9zpgmLCUYuLkxpLQIDAQAB";
id<DataVerifier> verifier;
verifier = CreateRSADataVerifier(key);
if ([verifier verifyString:result.resultStringwithSign:result.signString])
{
//验证签名成功,交易结果无篡改
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"提示"
message:result.statusMessage
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alertView show];
alertView.delegate = self;
//验签错误
else {
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"提示"
message:@"签名错误"
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alertView show];
}
}
//如果支付失败,可以通过result.statusCode查询错误码
else {
UIAlertView * alertView = [[UIAlertViewalloc] initWithTitle:@"提示"
message:result.statusMessage
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alertView show];
}
}
else
{
//交易失败
}
NSLog(@"1111%i",result.statusCode);
NSLog(@"222%@",result.description);
NSLog(@"333%@",result);
NSLog(@"444%@",result.resultString);
}
- (AlixPayResult *)resultFromURL:(NSURL *)url {
NSString * query = [[url query] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
#if ! __has_feature(objc_arc)
return [[[AlixPayResult alloc] initWithString:query] autorelease];
#else
return [[AlixPayResult alloc] initWithString:query];
#endif
}
- (AlixPayResult *)handleOpenURL:(NSURL *)url {
AlixPayResult * result = nil;
if (url != nil && [[url host] compare:@"safepay"] == 0) {
result = [self resultFromURL:url];
}
return result;
}
5设置url 在target中的info中,添加URL Types