startPay() {
var _this = this;
uni.login({
provider: 'weixin',
success: function(ress) {
var orders = {
payClass: 'org.jeecg.modules.pay.service.MallPayService',
orderId: _this.mallPayId,//支付之前,后台会返回的支付id
payMethod: _this.active,//选中的支付类型 、微信3
code: ress.code,
appId: _this.appId//小程序的appid
}
uni.showLoading({
title: '加载中',
mask: true
});
_this.$http('post', 'pay', orders).then(res => {
uni.hideLoading();
if (res.success == true) {
var wxPay = JSON.parse(res.result.prepayid);
//唤起小程序支付
uni.requestPayment({
provider: 'wxpay',
timeStamp: wxPay.timeStamp,
nonceStr: wxPay.nonceStr,
package: wxPay.package,
signType: wxPay.signType,
paySign: wxPay.paySign,
success: function(wxPayRes) {
// debugger
uni.navigateTo({
url: '/pages/gotoOrder/paySuccess'
})
// uni.showModal({
// title:'支付成功',
// showCancel:false,
// success() {
// var url = '/pages/my/my'
// uni.switchTab({
// url: url
// });
// }
// })
},
fail: function(err) {
console.log('fail:' + JSON.stringify(err));
}
});
} else {
uni.showToast({
title: '支付失败' + res.message,
position: "center",
icon: 'none',
duration: 2500
})
console.log(res);
}
})
}
});
},
对你有帮助?
打赏博主: