修复小程序订阅消息问题

This commit is contained in:
hupeng
2023-12-06 17:14:32 +08:00
parent 3e08136bfa
commit 583c1b8d81
3 changed files with 42 additions and 18 deletions

View File

@ -121,8 +121,12 @@ export async function payOrderHandle(orderId, type, from) {
// 处理调用支付接口的逻辑 // 处理调用支付接口的逻辑
// @type create(创建订单)||pay(支付订单) // @type create(创建订单)||pay(支付订单)
export function handleOrderPayResults(data, type, payType) { export function handleOrderPayResults(data, type, payType) {
// #ifdef MP-WEIXIN
//subscribeMessage()
// #endif
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
uni.hideLoading() uni.hideLoading()
switch (data.status) { switch (data.status) {
// 订单号已存在 // 订单号已存在
case "ORDER_EXIST": case "ORDER_EXIST":
@ -179,7 +183,7 @@ export function handleOrderPayResults(data, type, payType) {
goOrderDetails(data.result.orderId, type) goOrderDetails(data.result.orderId, type)
}).then(res => { }).then(res => {
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
subscribeMessage() //subscribeMessage()
// #endif // #endif
}) })
break; break;
@ -197,17 +201,32 @@ export function handleOrderPayResults(data, type, payType) {
export function subscribeMessage() { export function subscribeMessage() {
// 调用订阅 // 调用订阅
console.log('调用订阅') console.log('调用订阅')
getSubscribeTemplate() getSubscribeTemplate()
.then(res => { .then(res => {
wx.showModal({
title: '温馨提示',
content: '为更好的促进您与商家的交流,小程序需要在您成交时向您发送消息',
confirmText: "同意",
cancelText: "拒绝",
success: function(res1) {
if (res1.confirm) {
uni.requestSubscribeMessage({ uni.requestSubscribeMessage({
tmplIds: res.data, tmplIds: res.data,
success(res) { success(res2) {
console.log(res) console.log('res01:',res2)
}, },
fail(error) { fail(error) {
console.log(error) console.log('res02:',error)
} }
}) })
} else {
//revolve(true)
}
}
})
}) })
.catch(err => {}); .catch(err => {});
} }

View File

@ -311,6 +311,10 @@ export default {
}, },
}, },
onLoad: function() { onLoad: function() {
// #ifdef MP-WEIXIN
subscribeMessage()
// #endif
let that = this let that = this
this.$store.dispatch('getUser', true) this.$store.dispatch('getUser', true)
that.getCartInfo() that.getCartInfo()
@ -512,7 +516,8 @@ export default {
} }
console.log(this.$deviceType) console.log(this.$deviceType)
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
subscribeMessage()
// subscribeMessage()
// #endif // #endif
createOrder(this.orderGroupInfo.orderKey, { createOrder(this.orderGroupInfo.orderKey, {
realName: this.contacts, realName: this.contacts,