// 充值 recharge() { if (this.money == '') { return this.$refs.uToast.show({ title: '请选择充值金额' }) } let self = this let params = { rechid:self.id // 金额 id, 选择充值的金额 } self.$u.api.wxRecharge(params).then(res => { // 调用后端接口,拿到需要的参数 和 订单号 // console.log(res) let result = JSON.parse(res.message) self.orderNo = result.orderNo wx.requestPayment({ // 微信小程序 支付接口,传入几个必要的参数 timeStamp: result.timeStamp, nonceStr: result.nonceStr, package: result.package, signType: result.signType, paySign: result.paySign, success(res) { self.$refs.uToast.show({ title: '充值成功' }) }, fail(res) { let params = { orderNo:self.orderNo } self.$u.api.cancelRechargeOrder(params).then(res => { // 充值失败,调用 后端接口取消订单 console.log(res) self.$refs.uToast.show({ title: '充值失败,已取消此次充值' }) }) } }) }) }