【问题标题】:Android webview for payment gateway redirection is not working用于支付网关重定向的 Android webview 不起作用
【发布时间】:2017-08-16 23:16:07
【问题描述】:

我正在 webview 中加载一个 URL,该 URL 将重定向到支付网关屏幕。我的网址是:

 https://**hostname**/pgway/gateway/payment/paymentDebitwithPin.jsp?PaymentID=8501798561070830&trandata=b0cb7bcf4cb2f52b355fa4eb3f66905721323d2dfbbb00682dafe34bfca9948a&id=10100125

当加载这个 url 时,它会被重定向到下面的 url

https://**hostname**/pgway/gateway/payment/TransactionError.jsp

我用来加载这个网址的代码是

    pgWebview = (WebView)findViewById(R.id.pgWebview);
    pgWebview.getSettings().setUseWideViewPort(true);
    pgWebview.getSettings().setLoadWithOverviewMode(true);
    pgWebview.setWebViewClient(
            new SSLTolerentWebViewClient()
    );
    pgWebview.loadUrl(webURL);

重定向的屏幕将消息显示为

Unauthorized Transaction. Your request cannot be process as the transaction is already initiated.

我也尝试过 shouldOverrideUrlLoading 方法,但无论我得到相同的错误。谁能帮我解决这个问题?

【问题讨论】:

    标签: android webview payment-gateway


    【解决方案1】:

    当您通过扩展 calss 在 webview 中设置 webclient 时,此解决方案适用于我:WebViewClient()

     override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
        Log.d(TAG, "shouldOverrideUrlLoading")
        Log.d(TAG, "actualURL: $url")
        Log.d(TAG, "NewURL: $url")
        val parsedUrl = URL(url)
    
        val hitTestResult = view.hitTestResult
        //hitTestResult==null solve the redirect problem
        if (!TextUtils.isEmpty(url) && hitTestResult == null) {
            view.loadUrl(url)
            return true
        }
        //your handling logic here 
    }
    

    【讨论】:

      【解决方案2】:

      更好的方法可能是检查 onPageFinished()

      中的重定向 URL

      代码

      @Override
              public void onPageFinished(WebView view, String url) {
                  Log.d("Final URL", url);
              }
      

      【讨论】:

        【解决方案3】:

        通过这种方式检查你会知道加载url时发生的事情,移动浏览器中是否发生了url重定向?

        webView.loadUrl(actualURL);
        
        public class AppWebViewClients extends WebViewClient {
        
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
        
                Log.d(TAG, "shouldOverrideUrlLoading");
                Log.d(TAG, "actualURL: " + actualURL);
                Log.d(TAG, "NewURL: " + url);
        
                if (changedUrl && !url.equals(actualURL)) {
                    // page has been clicked
                    //TODO- load the page after redirection happens
                      view.loadUrl(url);
        
                    return true;
                } else {
                    // Designate Urls that you want to load in WebView still.
                    view.loadUrl(url);
        
                    return true;
                }
            }
        
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                //SHOW LOADING IF IT ISNT ALREADY VISIBLE
                Log.d(TAG, "onPageStarted");
            }
        
            public void onPageFinished(WebView view, String url) {
        
            }
        
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        
                Log.d(TAG, "Error Description: " + description);
                Log.d(TAG, "failingUrl: " + failingUrl);
            }
        
            @Override
            public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
                try{
                    final AlertDialog.Builder builder = new AlertDialog.Builder(WebViewActivity.this);
                    builder.setMessage(R.string.notification_error_ssl_cert_invalid);
                    builder.setPositiveButton("continue", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            handler.proceed();
                        }
                    });
                    builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            handler.cancel();
                        }
                    });
                    final AlertDialog dialog = builder.create();
                    dialog.show();
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
        

        【讨论】:

        • 你能告诉我那个实用程序吗?无法解决
        • 是的 url 重定向发生在移动浏览器中。我将在哪里获得 changeUrl?
        【解决方案4】:

        您需要为其启用 javascript。在加载 url 之前添加这些行:-

        pgWebview.getSettings().setJavaScriptEnabled(true);
        pgWebview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        

        【讨论】:

        • chrome 应用上也出现这种情况吗?
        • 在 Chrome 上也一样
        • 那么这个问题与android无关。它的服务器逻辑存在一些问题,请咨询您的 Web 开发人员。
        • 我联系了我的支付网关团队,但他们说他们这边一切都很完美,错误来自 android。
        • 同样的问题发生在我身上,但我的 url 在 chrome 应用程序上运行,但不在我的 webview 中
        猜你喜欢
        • 2022-06-16
        • 2017-10-06
        • 2012-09-12
        • 1970-01-01
        • 2016-02-21
        • 2016-12-28
        • 2021-09-27
        • 2015-03-27
        • 1970-01-01
        相关资源
        最近更新 更多