Now I will share with you a vue.js WeChat payment front-end code. Has very good reference value. I hope to be helpful.
The example is as follows:
onBridgeReady: function () { const openId = localStorage.getItem('openId') payService.payment(this.$route.params.orderId, 1, openId).then(rt => { //1:支付类型,可不填 this.message = rt.t WeixinJSBridge.invoke( 'getBrandWCPayRequest', { 'appId': this.message.appId, 'timeStamp': this.message.timeStamp, 'nonceStr': this.message.nonceStr, 'package': this.message.package, 'signType': this.message.signType, 'paySign': this.message.paySign }, function (res) { console.log(res) if (res.err_msg === 'get_brand_wcpay_request:ok') { Toast('微信支付成功') this.$router.push('/MineOrder') } else if (res.err_msg === 'get_brand_wcpay_request:cancel') { Toast('用户取消支付') // window.location.href = 'gift_failview.do?out_trade_no=' + this.orderId } else if (res.err_msg === 'get_brand_wcpay_request:fail') { Toast('网络异常,请重试') } } ) }) }, callpay: function () { if (typeof WeixinJSBridge === 'undefined') { if (document.addEventListener) { document.addEventListener('WeixinJSBridgeReady', this.onBridgeReady(), false) } else if (document.attachEvent) { document.attachEvent('WeixinJSBridgeReady', this.onBridgeReady()) document.attachEvent('onWeixinJSBridgeReady', this.onBridgeReady()) } } else { this.onBridgeReady() } }
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
How to implement the method of adding tr to table in angularjs
How to use json objects to push to an array in angular The method in
How to determine whether an element is contained in an angularjs array
The above is the detailed content of Implement WeChat payment through vue.js. For more information, please follow other related articles on the PHP Chinese website!