最近在项目中做微信支付时遇到的一个问题。在iphone上已经支付成功,也已经扣钱了,但是之后会无限弹错误框。安卓手机上没问题。
百思不得其解,百度谷歌了1天,也没有任何收获。无奈只能对着代码一步步排除错误。最后发现是支付成功后window.location.reload();这句代码的影响。导致会无限发起支付请求。微信端貌似有check,重复的请求会报错。注释掉后就OK了。
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
"appId": "${appid}", //公众号名称,由商户传入
"timeStamp": "${timeStamp}", //时间戳,自1970年以来的秒数
"nonceStr": "${nonceStr}", //随机串
"package": "${packageValue}",
"signType": "MD5", //微信签名方式:
"paySign": "${paySign}" //微信签名
}, function (res) {
if (res.err_msg == "get_brand_wcpay_request:ok") {
alert("a5");
history.back();
//window.location.reload();
} else if (res.err_msg == "get_brand_wcpay_request:cancel") {
history.back();
alert(window.location);
//window.location.reload();
} else {
alert(res.err_msg);
history.back();
window.location.reload();
}
});
- WeixinJSBridge.invoke(
- 'getBrandWCPayRequest', {
- "appId": "${appid}", //公众号名称,由商户传入
- "timeStamp": "${timeStamp}", //时间戳,自1970年以来的秒数
- "nonceStr": "${nonceStr}", //随机串
- "package": "${packageValue}",
- "signType": "MD5", //微信签名方式:
- "paySign": "${paySign}" //微信签名
- }, function (res) {
- if (res.err_msg == "get_brand_wcpay_request:ok") {
- alert("a5");
- <a href="http://zpycloud.com/archives/tag/history/" title="查看与 history 相关的文章" target="_blank">history</a>.<a href="http://zpycloud.com/archives/tag/back/" title="查看与 back 相关的文章" target="_blank">back</a>();
- //window.location.reload();
- } else if (res.err_msg == "get_brand_wcpay_request:cancel") {
- <a href="http://zpycloud.com/archives/tag/history/" title="查看与 history 相关的文章" target="_blank">history</a>.<a href="http://zpycloud.com/archives/tag/back/" title="查看与 back 相关的文章" target="_blank">back</a>();
- alert(window.location);
- //window.location.reload();
- } else {
- alert(res.err_msg);
- history.back();
- window.location.reload();
- }
- });
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
"appId": "${appid}", //公众号名称,由商户传入
"timeStamp": "${timeStamp}", //时间戳,自1970年以来的秒数
"nonceStr": "${nonceStr}", //随机串
"package": "${packageValue}",
"signType": "MD5", //微信签名方式:
"paySign": "${paySign}" //微信签名
}, function (res) {
if (res.err_msg == "get_brand_wcpay_request:ok") {
alert("a5");
<a href="http://zpycloud.com/archives/tag/history/" title="查看与 history 相关的文章" target="_blank">history</a>.<a href="http://zpycloud.com/archives/tag/back/" title="查看与 back 相关的文章" target="_blank">back</a>();
//window.location.reload();
} else if (res.err_msg == "get_brand_wcpay_request:cancel") {
<a href="http://zpycloud.com/archives/tag/history/" title="查看与 history 相关的文章" target="_blank">history</a>.<a href="http://zpycloud.com/archives/tag/back/" title="查看与 back 相关的文章" target="_blank">back</a>();
alert(window.location);
//window.location.reload();
} else {
alert(res.err_msg);
history.back();
window.location.reload();
}
});
以上就是修改后的代码。按理说history.back();只是浏览器的后退,是不会刷新画面的。但是现在的效果是可以刷新。这一点暂时还没搞懂。