<button @tap="toResult">立即购买</button>
toResult(){
let _this = this
console.log(_this.data.cardId)
console.log(_this.shopId)
let data={
cardId: _this.data.cardId,
shopId: _this.shopId
}
request.post('/app/vip/buyVipCard', data).then(res=>{//支付接口
console.log(res)
uni.showToast({
title: '加载中',
icon: 'loading',
duration: 9000
});
if(res.code==200) {
toPay(res.result,1).then(re=>{
console.log(re)
uni.requestPayment({
provider: 'wxpay',
timeStamp: re.timeStamp,
nonceStr: re.nonceStr,
package: re.package,
signType: re.signType,
paySign: re.paySign,
success: function (ress) {
uni.hideToast();
console.log('success:' + JSON.stringify(ress));
_this.$api.msg('支付成功');
uni.redirectTo({
url: 'submit_review'
});
},
fail: function (err) {
uni.hideToast();
_this.$api.msg('支付失败');
console.log('fail:' + JSON.stringify(err));
setTimeout(function(){
uni.redirectTo({
url: 'card'
})
},1000)
}
})
})
}else {
_this.$api.msg(res.errorMessage);
}
})
}
uniapp文档:https://uniapp.dcloud.io/api/plugins/payment