js 調用微信支付方法
阿新 • • 發佈:2018-05-08
chat token navig att () invoke ati sse ID
pay(){
let data ={
order_id:this.order_id,
wechatpay_type:this.wechatpay_type,
merchant_id:localStorage.merchant_id,
authentication_token:this.token,
client_token:this.client_token
}
this.$fetch(this.Wxpay, data) .then(res=>{ if(res.code==200){ if (res.data.wechatpay_type == "wxpay") { // 公眾號支付 this.callWxPay(res.data.pay_param); } else if (res.data.wechatpay_type == "wxpay_h5_wap") { this.callWxPayH5(res.data.pay_param.mweb_url); } else if (res.data.wechatpay_type == "wxpay_app") { this.callWxPayAPP(res.data.pay_param); } else { Toast(‘無效的支付類型‘); } }else{ Toast(res.error) } },err=>{ alert(JSON.stringify(err)) }) }, jsApiCall(params) { let that = this WeixinJSBridge.invoke( ‘getBrandWCPayRequest‘, { ‘appId‘: params.appId, ‘timeStamp‘:params.timeStamp, ‘nonceStr‘: params.nonceStr, ‘package‘: params.package, ‘signType‘: params.signType, ‘paySign‘: params.paySign }, function (res) { if (res.err_msg === ‘get_brand_wcpay_request:ok‘) { Toast(‘微信支付成功‘) that.$router.replace({name:‘fullOrder‘,query:{id:‘2‘}}) } else if (res.err_msg === ‘get_brand_wcpay_request:cancel‘) { Toast(‘用戶取消支付‘) that.$router.replace({name:‘fullOrder‘,query:{id:‘1‘}}) } else if (res.err_msg === ‘get_brand_wcpay_request:fail‘) { Toast(‘網絡異常,請重試‘) } } ); }, callWxPay(params) { if (typeof WeixinJSBridge == "undefined"){ if( document.addEventListener ){ document.addEventListener(‘WeixinJSBridgeReady‘, this.jsApiCall(params), false); }else if (document.attachEvent){ document.attachEvent(‘WeixinJSBridgeReady‘, this.jsApiCall(params)); document.attachEvent(‘onWeixinJSBridgeReady‘, this.jsApiCall(params)); } }else{ this.jsApiCall(params); } }, callWxPayH5(mweb_url) { location.href = mweb_url; }, callWxPayAPP(params) { let dsBridge = require("dsbridge"); dsBridge.call("requestWeChatPay", params, function (data) { alert(data); }) }, wechatpaytype(){ if(this.isWeiXin()){ this.wechatpay_type=‘wxpay‘ }else{ this.wechatpay_type=‘wxpay_h5_wap‘ } }, isWeiXin(){ //判斷是否微信平臺 var ua = window.navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == ‘micromessenger‘){ return true; } else { return false; } }
this.$fetch(this.Wxpay, data) .then(res=>{ if(res.code==200){ if (res.data.wechatpay_type == "wxpay") { // 公眾號支付 this.callWxPay(res.data.pay_param); } else if (res.data.wechatpay_type == "wxpay_h5_wap") { this.callWxPayH5(res.data.pay_param.mweb_url); } else if (res.data.wechatpay_type == "wxpay_app") { this.callWxPayAPP(res.data.pay_param); } else { Toast(‘無效的支付類型‘); } }else{ Toast(res.error) } },err=>{ alert(JSON.stringify(err)) }) }, jsApiCall(params) { let that = this WeixinJSBridge.invoke( ‘getBrandWCPayRequest‘, { ‘appId‘: params.appId, ‘timeStamp‘:params.timeStamp, ‘nonceStr‘: params.nonceStr, ‘package‘: params.package, ‘signType‘: params.signType, ‘paySign‘: params.paySign }, function (res) { if (res.err_msg === ‘get_brand_wcpay_request:ok‘) { Toast(‘微信支付成功‘) that.$router.replace({name:‘fullOrder‘,query:{id:‘2‘}}) } else if (res.err_msg === ‘get_brand_wcpay_request:cancel‘) { Toast(‘用戶取消支付‘) that.$router.replace({name:‘fullOrder‘,query:{id:‘1‘}}) } else if (res.err_msg === ‘get_brand_wcpay_request:fail‘) { Toast(‘網絡異常,請重試‘) } } ); }, callWxPay(params) { if (typeof WeixinJSBridge == "undefined"){ if( document.addEventListener ){ document.addEventListener(‘WeixinJSBridgeReady‘, this.jsApiCall(params), false); }else if (document.attachEvent){ document.attachEvent(‘WeixinJSBridgeReady‘, this.jsApiCall(params)); document.attachEvent(‘onWeixinJSBridgeReady‘, this.jsApiCall(params)); } }else{ this.jsApiCall(params); } }, callWxPayH5(mweb_url) { location.href = mweb_url; }, callWxPayAPP(params) { let dsBridge = require("dsbridge"); dsBridge.call("requestWeChatPay", params, function (data) { alert(data); }) }, wechatpaytype(){ if(this.isWeiXin()){ this.wechatpay_type=‘wxpay‘ }else{ this.wechatpay_type=‘wxpay_h5_wap‘ } }, isWeiXin(){ //判斷是否微信平臺 var ua = window.navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == ‘micromessenger‘){ return true; } else { return false; } }
js 調用微信支付方法