您的位置:首页 > 移动开发 > 微信开发

解决在android中使用微信H5支付,提示商家参数格式有误

2017-10-18 14:01 561 查看

解决在APP中使用微信H5支付,提示“商家参数格式有误…”

昨天抽空研究了一下微信H5支付,发现的确很方便,如果只使用浏览器做H5支付,
没什么问题,市面上主流的手机浏览器应该都可以调起微信支付(虽然我只测试了UC和QQ浏览器 - -! )
[微信H5支付](https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=15_1)
但是当我接入到APP中的时候,一直出现“商家参数格式有误,请联系商家解决”,why?
我什么都没有修改啊。上网也找了很多文章,说是需要在WebView的shouldOverrideUrlLoading方法中写成这样:


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<>();
extraHeaders.put("Referer", "http://wxpay.wxutil.com");
view.loadUrl(url, extraHeaders);
}
return true;


我也尝试了,这样在华为Mate 9 pro 以及小米5 上的确可以(android7.0)
但是在华为CL10(android4.4.4)上面还是提示这个错误。。(¬_¬)

最终解决方案:


webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("weixin://wap/pay?")) {
//如果return false  就会先提示找不到页面,然后跳转微信
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
return true;
}
return false;
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
//此方法是为了处理在5.0以上Htts的问题,必须加上
handler.proceed();
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android 支付 微信
相关文章推荐