food_wechat/pages/shop/pay.vue

64 lines
1.3 KiB
Vue
Raw Normal View History

2024-05-29 21:49:52 +08:00
<template>
<view>
<button @click="pay">确认支付</button>
</view>
</template>
<script>
export default {
data() {
return {
order_sn: '' //订单号
}
},
onLoad(options) {
this.order_sn = options.order_sn; // 从提交订单页面传递过来的订单号
},
methods: {
// 支付方法
pay() {
uni.$u.http.post('/Api/Pay/pay', {
order_sn: this.order_sn
}, {
header: {
'Token': this.$store.state.userInfo.token,
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then((res) => {
if (res.data.status === 1) {
// 调用微信支付接口
this.requestPayment(res.data.payMsg);
}
2024-05-29 21:49:52 +08:00
})
},
// 调用微信支付接口
requestPayment(payMsg) {
uni.requestPayment({
timeStamp: payMsg.timeStamp,
nonceStr: payMsg.nonceStr,
package: payMsg.package,
signType: payMsg.signType,
paySign: payMsg.paySign,
success: (res) => {
uni.showToast({
title: '支付成功',
icon: 'success'
});
// 可以在这里处理支付成功后的逻辑
},
fail: (err) => {
uni.showToast({
title: '支付失败',
icon: 'none'
});
console.error(err);
}
});
},
2024-05-29 21:49:52 +08:00
}
}
</script>
<style>
</style>