因为demo中支付金额是定死的,所以需要调整。
所以在使用的JS上添加了参数传入。这里的传入string类型的参数,直接使用是错误的,对于方法,会出现appid缺少参数的错误
//调用微信JS api 支付
function jsApiCall(jsStr) {
WeixinJSBridge.invoke(
'getBrandWCPayRequest',
jsStr,//存在问题的
//jsStr,//josn串
function (res) {
WeixinJSBridge.log(res.err_msg);
//由于官方申明:使用以上方式判断前端返回,微信团队郑重提示:res.err_msg将在用户支付成功后返回 ok,但并不保证它绝对可靠。
//所以在返回ok的时候,只进行成功提示(即使是支付失败,但是返回是ok)
$(".flsclose03").click();
if (res.err_msg == "get_brand_wcpay_request:ok") {
$(".cmact_blackbg1").stop(true, true).fadeIn("fast");
$("#tip_success").stop(true, true).fadeIn("fast");
} else {
$(".cmact_blackbg1").stop(true, true).fadeIn("fast");
$("#tip_fail").stop(true, true).fadeIn("fast");
}
}
);
} function callpay(jsStr) {
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', jsApiCall(jsStr), false);
}
else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', jsApiCall(jsStr));
document.attachEvent('onWeixinJSBridgeReady', jsApiCall(jsStr));
}
}
else {
jsApiCall(jsStr);
}
}
微信Demo中的模式是直接返回string parameters = jsApiParam.ToJson();字符串的,在前端<%=parameters%>直接调取的
项目中测试的时候,也是照着这种模式来的,只不过这个字符串,不是直接调用,而是作为js方法中的参数传入的。导致无法访问到这一串参数。一直报的是缺少参数appId,但就是不知道原因,改了访问目录,亦或是统一下单的参数,耗了几个小时。
百度查的时候,实际上最早就有这种说法,JSON格式问题,自然也试了一下,不过只是将传入的那一串打印出来罢了,并没有真正改。
知道后来实在没办法了,就报着试试的心态,将最近的一个数据放到js中
{
"appId": "",
"nonceStr":"",
"package": "",
"paySign": "",
"signType": "",
"timeStamp": ""
}
结果自然,成功了。因为不清楚到底是怎么产生变化的,所以干脆就如下写了,传个对象,总没有问题。
aaarticlea/png;base64,iVBORw0KGgo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