支付宝、微信支付 https://github.com/SMARTSMALL/MobilePayDemo
URL Schemes 配置如下
info.plist 白名单配置及网络配置
ps. 支付集成及注意事项 均在LZMobilePayManager.h中 有提到
/************支付宝支付****************/
/*
1.导入(AlipaySDK.bundle AlipaySDK.framework)到项目文件库下
2.在Build Phases选项卡的Link Binary With Libraries中,增加以下依赖:libc++.tbd、libz.tbd、SystemConfiguration.framework、CoreTelephony.framework、QuartzCore.framework、CoreText.framework、CoreGraphics.framework、UIKit.framework、Foundation.framework、CFNetwork.framework、CoreMotion.framework、AlipaySDK.framework
3.导入#import
- (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);
if (resultDic) {
[[NSNotificationCenter defaultCenter]postNotificationName:@"AlipayNotification" object:selfuserInfo:resultDic];
}
}];
//授权跳转支付宝钱包进行支付,处理支付结果
[[AlipaySDK defaultService] processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) {
NSLog(@"defaultService result = %@",resultDic);
//解析auth code
NSString *result = resultDic[@"result"];
NSString *authCode = nil;
if (result.length>0) {
NSArray *resultArr = [result componentsSeparatedByString:@"&"];
for (NSString *subResult in resultArr) {
if (subResult.length > 10 && [subResult hasPrefix:@"auth_code="]) {
authCode = [subResult substringFromIndex:10];
break;
}
}
}
NSLog(@"授权结果authCode = %@", authCode?:@"");
}];
}
}
return YES;
}
// NOTE: 9.0以后使用新API接口
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options
{
//支付跳转支付宝钱包进行支付,处理支付结果
[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
if (resultDic) {
[[NSNotificationCenter defaultCenter]postNotificationName:@"AlipayNotification" object:selfuserInfo:resultDic];
}
NSLog(@"result = %@",resultDic);
}];
//授权跳转支付宝钱包进行支付,处理支付结果
[[AlipaySDK defaultService] processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) {
NSLog(@"defaultService==result = %@",resultDic);
//解析auth code
NSString *result = resultDic[@"result"];
NSString *authCode = nil;
if (result.length>0) {
NSArray *resultArr = [result componentsSeparatedByString:@"&"];
for (NSString *subResult in resultArr) {
if (subResult.length > 10 && [subResult hasPrefix:@"auth_code="]) {
authCode = [subResult substringFromIndex:10];
break;
}
}
}
NSLog(@"授权结果authCode = %@", authCode?:@"");
}];
}
return YES;
}
4.、点击项目名称,点击“Info”选项卡,在“URL Types”选项中,点击“+”,在“URL Schemes”中输入“alisdkdemo”。“alisdkdemo”来自于文件“APViewController.m”的NSString *appScheme = @“alisdkdemo”;。
注意:这里的URL Schemes中输入的alisdkdemo,为测试demo,实际商户的app中要填写独立的scheme,建议跟商户的app有一定的标示度,要做到和其他的商户app不重复,否则可能会导致支付宝返回的结果无法正确跳回商户app。
5.注意'openssl/asn1.h' file not found在Build Setting下Header search paths添加"$(SRCROOT)/工程名/文件夹"
6.注意如果出现【rsa_private read error : private key is NULL】
1.修改RSADataSigner中方法formatPrivateKey中
[result appendString:@"-----BEGIN PRIVATE KEY-----\n"];
[result appendString:@"\n-----END PRIVATE KEY-----"];
为
[result appendString:@"-----BEGIN RSA PRIVATE KEY-----\n"];
[result appendString:@"\n-----END RSA PRIVATE KEY-----"];
2.
检查提供是私钥是否正确*/
如何使用 LZMobilePayManager
ps. 后面有时间集成银联支付功能