3

“您的会话已过期。请重新启动您的交易。别担心......这发生在我们最好的人身上。” 当我尝试使用 android webview 从 CC Avenue 支付网关使用 paytm 钱包进行支付时,显示错误消息。

以下是我用于支付网关的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    progressBarPB = (ProgressBar) findViewById(R.id.progressBarPB);
    progressBarPB.setVisibility(View.VISIBLE);
    WebView webView = (WebView) findViewById(R.id.paymentGatewayWV);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    webView.setWebViewClient(new HelloWebViewClient());
    webView.clearCache(true);
    webView.clearHistory();
    clearCookies(this);
    webView.loadUrl("payment gateway url");
}


@SuppressWarnings("deprecation")
public static void clearCookies(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        CookieManager.getInstance().removeAllCookies(null);
        CookieManager.getInstance().flush();
    } else {
        CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
        cookieSyncMngr.startSync();
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncMngr.stopSync();
        cookieSyncMngr.sync();
    }
}

public class HelloWebViewClient extends WebViewClient {
    public HelloWebViewClient() {
        // do nothing
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        progressBarPB.setVisibility(View.GONE);
    }
}

有时付款成功,如果我再次尝试付款,则会显示上述错误。我正在清除浏览器中的所有 cookie 数据,即使我不明白为什么会显示此错误。请帮我一个好的解决方案。谢谢 :)。

4

0 回答 0