CocosCreatoriOS接入支付宝极简版登陆

支付宝极简版登陆SDK文档地址
先根据支付宝文档集成SDK

AppController.mm文件中添加如下内容

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options
{
    NSLog(@"OpenURL options !!!");
    if  ([url.host isEqualToString: @"apmqpdispatch" ]) {
        [AFServiceCenter handleResponseURL:url withCompletion:^(AFServiceResponse *response)
        {
            NSLog(@"openURL options Call!!!");
           // 该接口上的block只有在跳转钱包授权过程中压后台app被系统kill掉时才会被回调
           if  (AFResSuccess == response.responseCode) {
               NSLog ( @"%@" , response.result);
               NSString *authCode = response.result[@"auth_code"];
               NSLog(@"AliPayAuthRequest authCode : %@",authCode);
               //发送回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只有在跳转钱包授权过程中压后台app被系统kill掉时才会被回调
           if  (AFResSuccess == response.responseCode) {
               NSLog ( @"%@" , response.result);
               NSString *authCode = response.result[@"auth_code"];
               NSLog(@"AliPayAuthRequest authCode : %@",authCode);
               //发送回JS
               [AppController callJsEngineCallBack:@"window.JAVACallBack.AliPayAuthCodeBack" :authCode];
          }
        }];
         return   YES ;
    }
}

+(void) AlipayAuthCode
{
    NSLog(@"拉起支付宝授权");
    NSString *url = @"https://authweb.alipay.com/auth?auth_type=PURE_OAUTH_SDK&app_id=你的AppID&scope=auth_user&state=init";  //登陆授权或别的需要跳转到支付宝完成操作的Url
    NSDictionary *params = @{kAFServiceOptionBizParams: @{
                                     @"url": url//@""
                                     },
                             kAFServiceOptionCallbackScheme: @"你的工程名",
                             };
    
    [AFServiceCenter callService:AFServiceAuth withParams:params andCompletion:^(AFServiceResponse *response)
    {
        NSLog(@"授权结果:%@", response.result);
        if(AFResSuccess == response.responseCode)
        {
            NSString *authCode = response.result[@"auth_code"];
            NSLog(@"AliPayAuthRequest authCode : %@",authCode);
            //发送回JS
            [CallJS callJsEngineCallBack:@"window.JAVACallBack.AliPayAuthCodeBack" :authCode];
        }
    }];
}

在Info.plist文件中(info栏加入)


image.png

URL为你的工程名(填其他的会拉不起),支付宝极简版登陆完成
获取code后提交给服务器就完事了

你可能感兴趣的:(CocosCreatoriOS接入支付宝极简版登陆)