前言、芝麻认证需要后台传给你一个 url,后台去蚂蚁金服上看的文档写的有iOS和安卓要实现的代码!
一、请求接口,返回url
[self doVerify:jsonDict[@"data"][@"biz_no"]];
二、相关代码
#pragma mark - 芝麻认证
- (void)doVerify:(NSString *)url {
NSString *alipayUrl = [NSString stringWithFormat:@"alipays://platformapi/startapp?appId=20000067&url=%@", [self URLEncodedStringWithUrl:url]];
if ([self canOpenAlipay]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:alipayUrl] options:@{} completionHandler:nil];
} else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"是否下载并安装支付宝完成认证?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"好的", nil];
[alertView show];
}
}
-(NSString *)URLEncodedStringWithUrl:(NSString *)url {
NSString *encodedString = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef)url,NULL,(CFStringRef) @"!*'();:@&=+$,%#[]|",kCFStringEncodingUTF8));
return encodedString;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
NSString *appstoreUrl = @"itms-apps://itunes.apple.com/app/id333206289";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appstoreUrl] options:@{} completionHandler:nil];
}
}
- (BOOL)canOpenAlipay {
return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"alipays://"]];
}
三、认证成功或者失败,返回自己app回调 需要对接支付宝相关流程