微信的demo如下,但是
function (res)里面的程序就是不執行,經過千辛萬苦終於查到原因,支付按鈕的OnClientClick="callpay()" 改為OnClientClick="javascript:callpay();return false;"
//調用微信JS api 支付 function jsApiCall() { WeixinJSBridge.invoke( 'getBrandWCPayRequest', <%=wxJsApiParam%>,//josn串 function (res) { //WeixinJSBridge.log(res.err_msg); //alert(res.err_code + res.err_desc + res.err_msg); //window.location.href="https://www.baidu.com"; alert("ok"); } ); }
function callpay() { if (typeof WeixinJSBridge == "undefined") { //alert("undefined"); if (document.addEventListener) { document.addEventListener('WeixinJSBridgeReady', jsApiCall, false); } else if (document.attachEvent) { document.attachEvent('WeixinJSBridgeReady', jsApiCall); document.attachEvent('onWeixinJSBridgeReady', jsApiCall); } } else { //alert("pay"); jsApiCall(); } }