前言、芝麻認證需要后臺傳給你一個 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回調 需要對接支付寶相關流程