微信浏览器唤起微信支付
作者:互联网
微信浏览器自带WeixinJSBridge方法直接调用就可以唤起微信支付
wxpay(data) { var ua = navigator.userAgent.toLowerCase(); var isWeixin = ua.indexOf("micromessenger") != -1; pay(data).then((res) = > { if (res.success) { console.log(res.data.result); const pay_params = res.data.result; if (isWeixin) { if (typeof WeixinJSBridge == "undefined") { if (document.addEventListener) { document.addEventListener("WeixinJSBridgeReady", onBridgeReady, false); } else if (document.attachEvent) { document.attachEvent("WeixinJSBridgeReady", onBridgeReady); document.attachEvent("onWeixinJSBridgeReady", onBridgeReady); } } else { this.onBridgeReady(pay_params); } } else { // this.goLoginPage (pay_params) } } else { Toast.fail("微信支付调起失败!"); } }). catch ((err) = > { console.log(err); }); }, onBridgeReady(params) { const pay_params = params; WeixinJSBridge.invoke("getBrandWCPayRequest", { appId: pay_params.appId, //公众号名称,由商户传入 timeStamp: pay_params.timeStamp, //时间戳,自1970年以来的秒数 nonceStr: pay_params.nonceStr, //随机串 package: pay_params.package, signType: pay_params.signType, //微信签名方式: paySign: pay_params.paySign, //微信签名 }, function(res) { if (res.err_msg == "get_brand_wcpay_request:ok") { Toast.success("支付成功!"); } }); },
标签:pay,浏览器,微信,params,res,唤起,document,onBridgeReady 来源: https://www.cnblogs.com/ziyoublog/p/16178252.html