一、代碼
paymentAdded:function(order){//調用微信支付
let that=this
let load = that.$createToast({txt:'', type:'loading',time: 100000,mask:true}).show()//加載信息
that.$ajax.post('wechatPay/toConfig',{url1 :location.href.split('#')[0]})
.then(response=> {
console.log(response);
if (response.success) {
//alert("獲取簽名成功");
wx.config({
beta:true,
debug : false, // 開啓調試模式,調用的所有api的返回值會在客戶端alert出來,若要查看傳入的參數,可以在pc端打開,參數信息會通過log打出,僅在pc端時纔會打印。
appId : response.data.weixinAppId, // 必填,公衆號的唯一標識
timestamp : response.data.timestamp, // 必填,生成簽名的時間戳
nonceStr : response.data.noncestr, // 必填,生成簽名的隨機串
signature : response.data.signature,// 必填,簽名,見附錄1
jsApiList : [ 'requestWxFacePictureVerify' ] // 必填,需要使用的JS接口列表,所有JS接口列表見附錄2
});
that.$ajax.post('orders/getOverTimePayInfoByOrderId',{orderId:order.orderId,orderType:order.orderType})
.then(response=> {
console.log(response);
if (response.success) {
that.$ajax.post('wechatPay/toPaySign',{amount:100,body:"公司名",order_id:response.data.orderNo,orderType:'5'})
.then(response=> {
console.log(response);
load.hide()
if (response.success) {
wx.chooseWXPay({
timestamp : response.data.timeStamp, // 支付簽名時間戳,注意微信jssdk中的所有使用timestamp字段均爲小寫。但最新版的支付後臺生成簽名使用的timeStamp字段名需大寫其中的S字符
nonceStr : response.data.nonceStr, // 支付簽名隨機串,不長於 32 位
package : response.data.package, // 統一支付接口返回的prepay_id參數值,提交格式如:prepay_id=***)
signType : response.data.signType, // 簽名方式,默認爲'SHA1',使用新版支付需傳入'MD5'
paySign : response.data.paySign, // 支付簽名
success : function(res) {
if (res.errMsg == "chooseWXPay:ok") {
//支付成功
that.$store.commit('toast',{message:'微信支付成功',type:'correct',time:2000})
order.state=14
order.stateName='體檢已完成'
} else {
that.$store.commit('toast',{message:'放棄支付',type:'error',time:2000})
//that.$router.replace({path:'/paymentSuccess',query:this.userData})
}
}
});
}
})
}
})
}
})
},