Home Article webview跳转微信支付【商家参数错误】等错误解决方案

webview跳转微信支付【商家参数错误】等错误解决方案

Release time:2018-08-06 20:44:09 Author:小键键 Reading volume:467

最近要webview实现微信在线支付,原本的方案是:


 @Override
            public boolean shouldOverrideUrlLoading(WebView webView, String url) {
               if(url.startsWith("https") || url.startsWith("http")){
                    webView.loadUrl(url);
                }else{
                    try {
                        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                        intent.setAction(Intent.ACTION_VIEW);
                        intent.setData(Uri.parse(url));
                        startActivity(intent);
                        return true;
                    } catch (ActivityNotFoundException e) {
                        // TODO: handle exception
                    }
                }
                return true;
            }
该配置,支付宝支付跳转OK。但是微信支付显示商家参数错误 搜索百度解决方案
 @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // 如下方案可在非微信内部WebView的H5页面中调出微信支付
                if (url.startsWith("weixin://wap/pay?")) {
                    Intent intent = new Intent();
                    intent.setAction(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(url));
                    startActivity(intent);
                    return true;
                } else {
                    Map extraHeaders = new HashMap();
                    extraHeaders.put("Referer", "商户注册域名");
                    view.loadUrl(url, extraHeaders);
                }
                return true;
            }
从这个方案看,只能跳转自己的支付接口,但是UC浏览器,QQ浏览器等是可以任意跳转,这是为什么,看来解决方案并非如此 最终解决方案:
 @Override
            public boolean shouldOverrideUrlLoading(WebView webView, String url) {
                Log.e("hh",url);
                if(url.startsWith("weixin://wap/pay?")){
                    try{
                        Intent intent = new Intent();
                        intent.setAction(Intent.ACTION_VIEW);
                        intent.setData(Uri.parse(url));
                        startActivity(intent);

                    }catch (ActivityNotFoundException e){
                    }

                }else if(url.startsWith("https://wx.tenpay.com")){
                    return false;
                }else if(url.startsWith("https") || url.startsWith("http")){
                    webView.loadUrl(url);
                }else{
                    try {
                        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                        intent.setAction(Intent.ACTION_VIEW);
                        intent.setData(Uri.parse(url));
                        startActivity(intent);
                        return true;
                    } catch (ActivityNotFoundException e) {
                        // TODO: handle exception
                    }
                }
                return true;
            }

对于“https://wx.tenpay.com”设定不处理即可

  
I want to comment

Search

classification

Leave a message
http://blog.yujianweb.cn/index.php/
User login
You have not written any reviews yet!
You have commented!
Can only praise once!
You have a collection!