手机网站支付唤起支付宝app

                       

商家在网页中调用支付宝提供的网页支付接口调起支付宝客户端内的支付模块,商家网页会跳转到支付宝中完成支付,支付完后跳回到商家网页内,最后展示支付结果。若无法唤起支付宝客户端,则在一定的时间后会自动进入网页支付流程。

注意:

  • 若接入的是新版本手机网站支付接口(alipay.trade.wap.pay),用户在安装支付宝钱包的情况下,调用手机网站支付接口默认会唤起钱包支付;若接入的是手机网站支付老版本(alipay.wap.create.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)navigationType{    // NOTE: ------  对alipays:相关的scheme处理 -------    // NOTE: 若遇到支付宝相关scheme,则跳转到本地支付宝App    NSString* reqUrl = request.URL.absoluteString;    if ([reqUrl hasPrefix:@"alipays://"] || [reqUrl hasPrefix:@"alipay://"]) {        // 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 = @"https://itunes.apple.com/cn/app/zhi-fu-bao-qian-bao-yu-e-bao/id333206289?mt=8";    NSURL *downloadUrl = [NSURL URLWithString:urlStr];    [[UIApplication sharedApplication]openURL:downloadUrl];}
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

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("https://d.alipay.com");       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;  }
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
           
要在HTML5中唤起支付宝APP进行支付,您可以使用支付宝的scheme链接来达到目的。以下是一个简单的示例代码: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>支付宝APP支付</title> </head> <body> <button onclick="openAlipay()">点击支付</button> <script> function openAlipay() { var schemeUrl = 'alipays://platformapi/startapp?saId=10000007&qrcode=https%3A%2F%2Fqr.alipay.com%2FXXXXXXXXXXXXXXXXXXXXXXXX'; window.location.href = schemeUrl; } </script> </body> </html> ``` 在上述示例中,我们创建了一个按钮,当用户点击该按钮时,会调用`openAlipay()`函数。在该函数中,我们使用`window.location.href`将页面重定向到支付宝的scheme链接。 这里的`schemeUrl`是支付宝的scheme链接格式,其中的`saId`参数表示跳转到支付宝APP的特定页面(10000007表示付款页面),`qrcode`参数是您的支付二维码链接,使用URL编码进行了转义。 请注意,实际使用时,您需要将`qrcode`参数替换为您自己的支付二维码链接。 当用户点击按钮时,如果用户已经在手机上安装了支付宝APP,并且APP支持处理该scheme链接,则会自动跳转到支付宝APP,并打开付款页面。 如果用户未安装支付宝APPAPP版本不支持处理该scheme链接,则页面将保持不变。您可以考虑在页面中提供备用的支付方式或提示用户安装支付宝APP。 希望以上代码对您有所帮助!如果有任何疑问,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值