⼿机⽹站⽀付唤起⽀付宝app
商家在⽹页中调⽤⽀付宝提供的⽹页⽀付接⼝调起⽀付宝客户端内的⽀付模块,商家⽹页会跳转到⽀付宝中完成⽀付,⽀付完后跳回到商家⽹页内,最后展⽰⽀付结果。若⽆法唤起⽀付宝客户端,则在⼀定的时间后会⾃动进⼊⽹页⽀付流程。
注意:
若接⼊的是新版本⼿机⽹站⽀付接⼝(ade.wap.pay),⽤户在安装⽀付宝钱包的情况下,调⽤⼿机⽹站⽀付接⼝默认会唤起钱包⽀付;若接⼊的是⼿机⽹站⽀付⽼版本(ate.direct.pay.by.user ),那么需要在请求参数中加⼊app_pay参数并赋值为Y,详情参见 ⼿机⽹站⽀付⽼版本⽂档;
开发者需要关注安装了⽀付宝和未安装⽀付宝的两种测试场景,对于在⼿机浏览器唤起H5页⾯的模式下,如果安装了⽀付宝却没有唤起,⼤部分原因是当前浏览器不在⽀付宝配置的⽩名单内;
对于商户app内嵌webview中的⽀付场景,建议集成⽀付宝App⽀付产品。或者您可以使⽤⼿机⽹站⽀付转Native⽀付的⽅案,不建议在您的APP中直接接⼊⼿机⽹站⽀付。
⽬前在⼿机⽹站⽀付时,通过唤起⽀付宝app收银台的⽅式去⽀付,可以⼤⼤提⾼⽀付成功率,故不建议
禁⽌唤起⽀付宝app,⽬前对外也没有提供禁⽌唤起⽀付宝app的⽅法。
商户APP的WebView处理alipays协议。
iOS
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigation Type
{
// NOTE: ------  对alipays:相关的scheme处理 -------
// NOTE: 若遇到⽀付宝相关scheme,则跳转到本地⽀付宝App
NSString* reqUrl = request.URL.absoluteString;
if ([reqUrl hasPrefix:@"alipays://"] || [reqUrl hasPrefix:@"alipay://"]) {
网页app// NOTE: 跳转⽀付宝App
BOOL bSucc = [[UIApplication sharedApplication]openURL:request.URL];
// NOTE: 如果跳转失败,则跳转itune下载⽀付宝App
if (!bSucc) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提⽰"
message:@"未检测到⽀付宝客户端,请安装后重试。"
delegate:self
cancelButtonTitle:@"⽴即安装"
otherButtonTitles:nil];
[alert show];
}
return NO;
}
return YES;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
// NOTE: 跳转itune下载⽀付宝App
NSString* urlStr = @"itunes.apple/cn/app/zhi-fu-bao-qian-bao-yu-e-bao/id333206289?mt=8";
NSURL *downloadUrl = [NSURL URLWithString:urlStr];
[[UIApplication sharedApplication]openURL:downloadUrl];
}
Android
public boolean shouldOverrideUrlLoading(final WebView view, String url) {
// 获取上下⽂, H5PayDemoActivity为当前页⾯
final Activity context = H5PayDemoActivity.this;
// ------  对alipays:相关的scheme处理 -------
if(url.startsWith("alipays:") || url.startsWith("alipay")) {
try {
context.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(url)));    } catch (Exception e) {
new AlertDialog.Builder(context)
.setMessage("未检测到⽀付宝客户端,请安装后重试。")
.setPositiveButton("⽴即安装", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Uri alipayUrl = Uri.parse("d.alipay");
context.startActivity(new Intent("android.intent.action.VIEW", alipayUrl));
}
}).setNegativeButton("取消", null).show();
}
return true;
}
// ------- 处理结束 -------
if (!(url.startsWith("http") || url.startsWith("https"))) {
return true;
}
view.loadUrl(url);
return true;
}