支付寶極簡版登陸SDK文檔地址
先根據(jù)支付寶文檔集成SDK
AppController.mm文件中添加如下內(nèi)容
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
{
NSLog(@"OpenURL options !!!");
if ([url.host isEqualToString: @"apmqpdispatch" ]) {
[AFServiceCenter handleResponseURL:url withCompletion:^(AFServiceResponse *response)
{
NSLog(@"openURL options Call!!!");
// 該接口上的block只有在跳轉(zhuǎn)錢包授權(quán)過程中壓后臺app被系統(tǒng)kill掉時才會被回調(diào)
if (AFResSuccess == response.responseCode) {
NSLog ( @"%@" , response.result);
NSString *authCode = response.result[@"auth_code"];
NSLog(@"AliPayAuthRequest authCode : %@",authCode);
//發(fā)送回JS
[CallJS callJsEngineCallBack:@"window.JAVACallBack.AliPayAuthCodeBack" :authCode];
}
}];
return YES ;
}
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
if ([url.host isEqualToString: @"apmqpdispatch" ])
{
NSLog(@"openURL sourceApplication Call!!!");
[AFServiceCenter handleResponseURL:url withCompletion:^(AFServiceResponse *response) {
// 該接口上的block只有在跳轉(zhuǎn)錢包授權(quán)過程中壓后臺app被系統(tǒng)kill掉時才會被回調(diào)
if (AFResSuccess == response.responseCode) {
NSLog ( @"%@" , response.result);
NSString *authCode = response.result[@"auth_code"];
NSLog(@"AliPayAuthRequest authCode : %@",authCode);
//發(fā)送回JS
[AppController callJsEngineCallBack:@"window.JAVACallBack.AliPayAuthCodeBack" :authCode];
}
}];
return YES ;
}
}
+(void) AlipayAuthCode
{
NSLog(@"拉起支付寶授權(quán)");
NSString *url = @"https://authweb.alipay.com/auth?auth_type=PURE_OAUTH_SDK&app_id=你的AppID&scope=auth_user&state=init"; //登陸授權(quán)或別的需要跳轉(zhuǎn)到支付寶完成操作的Url
NSDictionary *params = @{kAFServiceOptionBizParams: @{
@"url": url//@""
},
kAFServiceOptionCallbackScheme: @"你的工程名",
};
[AFServiceCenter callService:AFServiceAuth withParams:params andCompletion:^(AFServiceResponse *response)
{
NSLog(@"授權(quán)結(jié)果:%@", response.result);
if(AFResSuccess == response.responseCode)
{
NSString *authCode = response.result[@"auth_code"];
NSLog(@"AliPayAuthRequest authCode : %@",authCode);
//發(fā)送回JS
[CallJS callJsEngineCallBack:@"window.JAVACallBack.AliPayAuthCodeBack" :authCode];
}
}];
}
在Info.plist文件中(info欄加入)
URL為你的工程名(填其他的會拉不起),支付寶極簡版登陸完成
獲取code后提交給服務(wù)器就完事了