Android calls the micro-channel pay H5 pit encountered

       Development process, we may need to access the micro-channel payment is H5, but you may experience some pit access process, make you very irritable, I encountered some time ago, when today's finishing things stumbled think, then you want to write about sharing it! Encountered such a situation is: normal time can pull up the payment, and the payment is successful, but it is possible after one day will suddenly find that on another pay phone when the show pulled after a long time: the system is busy, please wait try again! Then you start the online search solutions, and most of them are found to say right keys and other parameters, and then you start trying very hard to check and found that is correct, but can not afford to pay is to pull, this time you are going to feel explode! Today I talk about how I encountered the pit is resolved.

        First, you need to know how to call micro-channel pay h5, I'm using here is demo, as follows:     

        webView = findViewById(R.id.webview);
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setDefaultTextEncodingName("UTF-8");
        webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        webView.setWebChromeClient(new WebChromeClient());
        WebViewClient webViewClient = new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // 此处log 最终让我发现了问题根源
                Log.i("AAAAAA", "shouldOverrideUrlLoading: ---url = "+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<String, String> extraHeaders = new HashMap<String, String>();
                    // 此处连接为申请微信H5支付的时候填写的域名
                    extraHeaders.put("Referer", "http://wxpay.wxutil.com");
                    view.loadUrl(url, extraHeaders);
                }
                return true;
            }

            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, android.net.http.SslError error) { // 重写此方法可以让webview处理https请求
                handler.proceed();
            }
        };
        webView.setWebViewClient(webViewClient);
        webView.loadUrl("https://wxpay.wxutil.com/mch/pay/h5.v2.php");

       Then, after observing the following method to add shouldOverrideUrlLoading log, find the link inside the parameters of the intercepted package missing values, and here I want to Tucao about, after repeated verification, found that the package even if the value is empty most of the time there are also pull up micro-channel pay, and successful payment, but another machine or over a period of time may fail at this very pit, after investigation and background classmates, then every time you connect all the package after the value of the parameter is returned and found secure in properly properly succeed every time to pull the payment and the payment is successful, then change the machine no problem, so this feeling is not a bug wx ah!

       This is the pit I meet, share your reference

Released eight original articles · won praise 20 · views 10000 +

Guess you like

Origin blog.csdn.net/u012850536/article/details/104040182