| | |
| | | * @returns {boolean} |
| | | */ |
| | | checkLocalSubscribeStatus() { |
| | | return true;// uni.getStorageSync('hasSubscribedTaskNotify') || false |
| | | return uni.getStorageSync('hasSubscribedTaskNotify') || false |
| | | } |
| | | |
| | | /** |
| | |
| | | wx.getSetting({ |
| | | withSubscriptions: true, |
| | | success: (res) => { |
| | | console.log('微信订阅状态查询结果:', res) |
| | | // console.log('微信订阅状态查询结果:', res.subscriptionsSetting.mainSwitch) |
| | | |
| | | // 检查subscriptionsSetting中是否有该模板ID的记录 |
| | | if (res.subscriptionsSetting && res.subscriptionsSetting.mainSwitch) { |
| | | const subscribeStatus = res.subscriptionsSetting.mainSwitch; |
| | | resolve(subscribeStatus) |
| | | resolve(false); // 如果用户同意了订阅,则返回false |
| | | // const subscribeStatus = res.subscriptionsSetting.mainSwitch; |
| | | // console.log(res.subscriptionsSetting.itemSettings[templateId]) |
| | | // resolve(subscribeStatus) |
| | | // 'accept' 表示用户同意订阅,'reject' 表示拒绝,'ban' 表示被封禁 |
| | | // const isSubscribed = subscribeStatus === 'accept' |
| | | // console.log(`模板ID ${templateId} 订阅状态:`, subscribeStatus, '是否已订阅:', isSubscribed) |
| | | // resolve(isSubscribed) |
| | | // console.log("发起订阅请求") |
| | | // wx.requestSubscribeMessage({ |
| | | // tmplIds: [templateId], |
| | | // success: (res) => { |
| | | // console.log('订阅消息状态:', res) |
| | | // if (res[templateId] === 'accept') { |
| | | // console.log('用户已订阅') |
| | | // resolve(true) |
| | | // } else if (res[templateId] === 'reject') { |
| | | // console.log('用户已拒绝订阅') |
| | | // resolve(false) |
| | | // } else if (res[templateId] === 'ban') { |
| | | // console.log('用户已封禁订阅') |
| | | // resolve(false) |
| | | // } else { |
| | | // console.log('未知订阅状态') |
| | | // resolve(false) |
| | | // } |
| | | // },fail: (err) => { |
| | | // console.error('订阅消息失败:', err) |
| | | // resolve(false) |
| | | // } |
| | | |
| | | // } |
| | | // ) |
| | | } else { |
| | | console.log('未找到订阅设置信息,视为未订阅') |
| | | resolve(false) |
| | |
| | | const wechatStatus = await this.checkWechatSubscribeStatus() |
| | | |
| | | // 如果本地显示已订阅,但微信官方显示未订阅,需要重新订阅 |
| | | const needResubscribe = wechatStatus |
| | | const needResubscribe = !localStatus |
| | | |
| | | if (needResubscribe) { |
| | | console.warn('本地状态与微信官方状态不一致,需要重新订阅') |
| | | // console.warn('本地状态与微信官方状态不一致,需要重新订阅') |
| | | // 清除本地记录 |
| | | uni.removeStorageSync('hasSubscribedTaskNotify') |
| | | // uni.removeStorageSync('hasSubscribedTaskNotify') |
| | | } |
| | | |
| | | return { |
| | |
| | | console.log('检测到订阅状态失效,触发重新订阅流程') |
| | | } else { |
| | | console.log('用户未订阅,触发自动订阅流程') |
| | | return { success: false, action: 'not_subscribed', skipped: true, status } |
| | | } |
| | | |
| | | // 显示确认弹窗并订阅 直接默认订阅 |