https://www.jianshu.com/p/155757d2b9eb
<!-- wxPay --SDK--> <script src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script> goWXPay(obj){ //wxpay var pays_appId = GetQueryString("appId"); var pays_nonceStr = GetQueryString("nonceStr"); var pays_package = GetQueryString("package"); var pays_signType = GetQueryString("signType"); var pays_timeStamp = GetQueryString("timeStamp"); var pays_paySign = GetQueryString("paySign"); if(pays_package && pays_paySign){//wxPay status wx.config ({ Debug: false , // turn on debug mode, all calls will alert api return values out of the client, to view the incoming parameters, you can open the pc side, will be played by the parameter information log, will be printed only when the pc. appId: pays_appId, // required, a unique identification number of public wx4943f6480a79a436 timestamp: pays_timeStamp, // required to generate a signature timestamp nonceStr: pays_nonceStr, // required to produce the signature random string signature: pays_paySign, // required, signature, see Appendix. 1 jsApiList: [ "chooseWXPay"] // required, JS need to use the list of interfaces, all interfaces JS listing in Appendix 2 }); function onBridgeReady () { console.log ("进入onBridgeReady~") WeixinJSBridge.invoke('getBrandWCPayRequest', { "appId": pays_appId, "timeStamp": pays_timeStamp, "nonceStr": pays_nonceStr, "package": pays_package, "signType": pays_signType, "paySign": pays_paySign //微信签名 }, function (res) { if (res.err_msg == "get_brand_wcpay_request:ok") { obj.success(); }else if (res.err_msg == "get_brand_wcpay_request:fail") { obj.fail(); } }); } wx.ready(function () { if (typeof WeixinJSBridge == "undefined") { console.log("typeof WeixinJSBridge~running"); if (document.addEventListener) { document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false); } else if (document.attachEvent) { document.attachEvent('WeixinJSBridgeReady', onBridgeReady); document.attachEvent('onWeixinJSBridgeReady', onBridgeReady); } }else{ console.log("onBridgeReady()"); onBridgeReady(); } }); } },
h5 from the transfer of native micro-channel pay
pay.goWXPay ({ // page data initialized -> micro-channel payment invoking Success: function () { Resolve (RES); the console.log ( "after the user has successfully paid return OK" ) the console.log (RES) Alert ( "paid to complete, ready to refresh the current page" ); window.location.href = "./a.html"; // update the current page data // use the above way to determine return to the front, micro-letter team solemnly Tip: // RES. err_msg will return after a successful payment user ok, but does not guarantee it is absolutely reliable. }, Fail:function () { the console.log ( "failure to return the user to pay Fail" ) the console.log (RES) Toast ( "payment fails" ) window.location.href = "./a.html"; // prevent page unresponsive } });