• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

微信小程序判断是否已经订阅某条消息

武飞扬头像
高先生的猫
帮助1

判断订阅消息是否已经订阅

res.subscriptionsSetting.itemSettings 返回的是所有订阅消息的对象集合,'accept' 表示用户同意订阅这条消息,'reject' 表示用户拒绝订阅这条消息,'ban' 表示已被后台封禁。

  1.  
    // 要检查的订阅id
  2.  
    let id = 'WwrpsGYQFVkU4CCyY5m0ytYbg1bk2Fxxxxxxxxxxx'
  3.  
    wx.getSetting({
  4.  
    withSubscriptions: true,
  5.  
    success(res) {
  6.  
    console.log(res)
  7.  
    if (res.subscriptionsSetting.mainSwitch) { // 用户打开了订阅消息总开关
  8.  
    if (res.subscriptionsSetting.itemSettings) { // 用户同意总是保持是否推送消息的选择, 这里表示以后不会再拉起推送消息的授权
  9.  
    let moIdState = res.subscriptionsSetting.itemSettings[id]; // 用户同意的消息模板id
  10.  
    if (moIdState === 'accept') {
  11.  
    console.log('接受了消息推送');
  12.  
    } else if (moIdState === 'reject') {
  13.  
    console.log('拒绝了消息推送');
  14.  
    if (app.globalData.isCheck1 === 0) {
  15.  
    wx.requestSubscribeMessage({
  16.  
    tmplIds: ['WwrpsGYQFVkU4CCyY5m0ytYbg1bk2Fxxxxxxxxxxx'],
  17.  
    success(res) {},
  18.  
    })
  19.  
    }
  20.  
    } else if (moIdState === 'ban') {
  21.  
    console.log("已被后台封禁");
  22.  
    }
  23.  
    } else {
  24.  
    if (app.globalData.isCheck1 === 0) {
  25.  
    wx.requestSubscribeMessage({
  26.  
    tmplIds: ['WwrpsGYQFVkU4CCyY5m0ytYbg1bk2Fxxxxxxxxxxx'],
  27.  
    success(res) {},
  28.  
    })
  29.  
    }
  30.  
    }
  31.  
    } else {
  32.  
    wx.openSetting({
  33.  
    withSubscriptions: true,
  34.  
    })
  35.  
     
  36.  
    }
  37.  
    }
  38.  
    })
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfkkejc
系列文章
更多 icon
同类精品
更多 icon
继续加载