// 微信
wxPay() {
let me = this
uni.getProvider({
service: 'payment',
success: res => {
if (~res.provider.indexOf('wxpay')) { //先判断用户是否有微信支付环境(是否安装了微信app)
uni.showLoading({
title: '正在调起微信支付'
})
let params = {
mid: me.globalMid,
stids: me.strnum,
sbid: me.tbid,
}
uni.request({ //再从后端接口获取相关数据配置到orderInfo里,这个接口由后端配置好了,返回结果见下图2-微信
url: me.$serverUrl + 'payorder/payInfo',
method: 'POST',
data: params,
success: res => {
if (res.data.code == 200) {
let resobj = JSON.parse(res.data
.data) //(这里注意后端返回的数据类型是string还是object,需转成object类型)
let payInfo = {
table_money: resobj.table_money,
deposit_money: resobj.mch_id,
service_money: resobj.service_money,
package: "Sign=WXPay"
}
uni.requestPayment({
provider: 'wxpay',
orderInfo: payInfo, //微信订单数据(Object类型)
success: res => {
uni.hideLoading();
uni.showToast({
title: '支付成功',
icon: 'none'
})
},
fail: err => {
uni.hideLoading();
uni.showToast({
title: '支付失败,请稍后再试',
icon: 'none'
})
}
});
}
},
fail: () => {
uni.hideLoading();
uni.showToast({
title: '服务器开小差了呢,请您稍后再试',
icon: 'none'
})
}
});
} else {
uni.showToast({
title: '获取微信通道失败,请检查您的微信是否正常启用',
icon: 'none'
})
}
}
});
},
|