h5微信支付报错:商家参数格式有误,请联系商家解决
解决官方给的解决方案是:https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=15_4
因为我用的是 react native,改的话需要去改 node_modules里面的 react-native-webview 包的源码。
网上也有人说,直接这样设置:
{ // 此处可以拿到我从h5传过来的参数 console.log('====>' + event.nativeEvent.data) }} />
但是我亲测,这样设置 Referer 没有生效。
所以,我就按照官方文档改源码咯
安卓路径:node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
final RNCWebView rncWebView = (RNCWebView) view;
final boolean isJsDebugging = ((ReactContext) view.getContext()).getJavascriptContextHolder().get() == 0;
// -------开始-------
Map extraHeaders = new HashMap();
extraHeaders.put("Referer", "https://e.cmvalue.cn");
if (url.startsWith("weixin://")) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
view.getContext().startActivity(intent);
return true;
}
view.loadUrl(url, extraHeaders);
// -------结束-------
if (!isJsDebugging && rncWebView.mCatalystInstance != null) {
...
}
}
ios路径:``



