修复小程序订阅消息问题

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

@ -1,5 +1,5 @@
// export const VUE_APP_API_URL = 'http://natapp.xinxintuan.co/api'; // export const VUE_APP_API_URL = 'http://natapp.xinxintuan.co/api';
// export const VUE_APP_API_URL = 'https://wxapi.yixiang.co/api' //export const VUE_APP_API_URL = 'https://wxapi.yixiang.co/api'
// export const VUE_APP_API_URL = '/h5api' // export const VUE_APP_API_URL = '/h5api'
export const VUE_APP_API_URL = 'http://127.0.0.1:8008/api' export const VUE_APP_API_URL = 'http://127.0.0.1:8008/api'
// export const VUE_APP_API_URL = 'http://192.168.31.223:8008/api' // export const VUE_APP_API_URL = 'http://192.168.31.223:8008/api'

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 => {
uni.requestSubscribeMessage({ wx.showModal({
tmplIds: res.data, title: '温馨提示',
success(res) { content: '为更好的促进您与商家的交流,小程序需要在您成交时向您发送消息',
console.log(res) confirmText: "同意",
}, cancelText: "拒绝",
fail(error) { success: function(res1) {
console.log(error) if (res1.confirm) {
} uni.requestSubscribeMessage({
}) tmplIds: res.data,
success(res2) {
console.log('res01:',res2)
},
fail(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,