我正在尝试在webview中加载我的Android应用程序中的ccavenue页面,但是我没有获得空白屏幕的ccavenue网页。当我正确地传递一切时,我无能为力。 请检查我的代码,让我知道我在哪里做错了。
StringBuffer params = new StringBuffer();
params.append(ServiceUtility.addToPostParams(AvenuesParams.ACCESS_CODE,mainIntent.getStringExtra(AvenuesParams.ACCESS_CODE)));
params.append(ServiceUtility.addToPostParams(AvenuesParams.MERCHANT_ID,mainIntent.getStringExtra(AvenuesParams.MERCHANT_ID)));
params.append(ServiceUtility.addToPostParams(AvenuesParams.ORDER_ID,mainIntent.getStringExtra(AvenuesParams.ORDER_ID)));
params.append(ServiceUtility.addToPostParams(AvenuesParams.REDIRECT_URL,mainIntent.getStringExtra(AvenuesParams.REDIRECT_URL)));
params.append(ServiceUtility.addToPostParams(AvenuesParams.CANCEL_URL,mainIntent.getStringExtra(AvenuesParams.CANCEL_URL)));
params.append(ServiceUtility.addToPostParams(AvenuesParams.ENC_VAL, encVal));
String vPostParams = params.substring(0, params.length() - 1);
try {
String postData = URLEncoder.encode(vPostParams, "UTF-8");
webview.postUrl(Constants.TRANS_URL, postData.getBytes());
Log.d("webview test", "testing");
Log.d("webview test",vPostParams);
} catch (Exception e) {
showToast("Exception occured while opening webview.");
}
字符串vPostParams的值是,
access_code=AVBJ63DA70BU19JBUB&merchant_id=86529&order_id=2383911&redirect_url=http://52.11.225.96&cancel_url=http://52.11.225.96&enc_val=FE9+b0quu5a8GBqGPG0yGA6bnqJLi34iW2hdxwKTo0sPfZRJDQwQxOzCAoN06CYB1n+gUQz5knNNfNcD5IBcbRs5aJtMs0pc9Beekj5lk9bFMd8BGgUse9oHeKqhOQc5WBLDOETAO/Hu9YNS4MTHNweieCP10PHj9eMzDEOgzjkbNwc8vhU4arYvSjwqT3JKtQKpVlwWL47StVNB/6SsVutmyudbesNGx626ZK9VbcTrpqabFWHQ2p2aQH9tW5YcApbUnLChbfmEyCTZ7YyO0jafQcbDWsRa4XT8XTXGY4KvZBn1VkeYBSJ91zIjT2yR+XMgahbrGVtUcOK8midvJA==
答案 0 :(得分:0)
此代码可供我查看。
public class CCAvenue extends ActionBarActivity {
WebView webView1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ccavenue);
webView1 = (WebView) findViewById(R.id.webView1);
String url = "http://www.example.com/controllers/user/cckit/ccavRequestHandler.php";
webView1.setWebViewClient(new MyBrowser());
webView1.getSettings().setLoadsImagesAutomatically(true);
webView1.getSettings().setJavaScriptEnabled(true);
webView1.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView1.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");
webView1.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url)
{
/* This call inject JavaScript into the page which just finished loading. */
webView1.loadUrl("javascript:window.HTMLOUT.processHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
}
});
String postData = "merchant_id=12345&order_id=12345678912&amount=1¤cy=INR" +
"&cancel_url=http://www.example.com/" +
"&redirect_url=http://www.example.com/controllers/user/cckit/ccavResponseHandler.php" +
"&language=EN";
webView1.postUrl(url,EncodingUtils.getBytes(postData, "BASE64"));
//webView1.loadUrl(url);
}
private class MyBrowser extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
class MyJavaScriptInterface
{
@JavascriptInterface
public void processHTML(String html)
{
// here you can handel response from CCAvenue.
System.out.println("Response : " + html);
}
}
答案 1 :(得分:-2)
在应用的build.gradle中添加useLibrary 'org.apache.http.legacy'
并添加此代码
StringBuffer params = new StringBuffer();
params.append(ServiceUtility.addToPostParams(AvenuesParams.ACCESS_CODE,mainIntent.getStringExtra(AvenuesParams.ACCESS_CODE)));
params.append(ServiceUtility.addToPostParams(AvenuesParams.MERCHANT_ID,mainIntent.getStringExtra(AvenuesParams.MERCHANT_ID)));
params.append(ServiceUtility.addToPostParams(AvenuesParams.ORDER_ID,mainIntent.getStringExtra(AvenuesParams.ORDER_ID)));
params.append(ServiceUtility.addToPostParams(AvenuesParams.REDIRECT_URL,mainIntent.getStringExtra(AvenuesParams.REDIRECT_URL)));
params.append(ServiceUtility.addToPostParams(AvenuesParams.CANCEL_URL,mainIntent.getStringExtra(AvenuesParams.CANCEL_URL)));
params.append(ServiceUtility.addToPostParams(AvenuesParams.ENC_VAL, URLEncoder.encode(encVal)));
String vPostParams = params.substring(0, params.length() - 1);
try {
String postData = URLEncoder.encode(vPostParams, "UTF-8");
webview.postUrl(Constants.TRANS_URL, EncodingUtils.getBytes(vPostParams, "UTF-8"));
Log.d("webview test", "testing");
Log.d("webview test",postData);
} catch (Exception e) {
showToast("Exception occured while opening webview.");
}