zoukankan      html  css  js  c++  java
  • 消息订阅---小程序

    直接上代码:

    wx.getSetting({
      withSubscriptions: true,   //  这里设置为true,下面才会返回mainSwitch
      success: function(res){       
        // 调起授权界面弹窗
        if (res.subscriptionsSetting.mainSwitch == true) {  // 用户打开了订阅消息总开关
          if (res.subscriptionsSetting.itemSettings != null) {   // 用户同意总是保持是否推送消息的选择, 这里表示以后不会再拉起推送消息的授权
            let moIdState = res.subscriptionsSetting.itemSettings['模板ID'];  // 用户同意的消息模板id
            if(moIdState === 'accept'){   
              console.log('接受了消息推送');
            }else if(moIdState === 'reject'){
              console.log("拒绝了你的消息推送");
            }else if(moIdState === 'ban'){
              console.log("已被后台封禁啦!!!");
            }
          }else {
            // 当用户没有点击 ’总是保持以上选择,不再询问‘  按钮。那每次执到这都会拉起授权弹窗
            wx.showModal({
              title: '提示',
              content:'请开通授权服务通知',
              showCancel: true,
              success: function (res) {
                if (res.confirm) {  
                  wx.requestSubscribeMessage({   // 调起消息订阅界面
                    tmplIds: ['模板ID'],
                    success (res) { 
                      console.log('订阅消息 成功 ');
                      // console.log(res);
                    },
                    fail (er){
                      console.log("订阅消息 失败 ");
                      // console.log(er);
                    }
                  })     
                        
                }else{
                  console.log("点击了取消 >>>> 未授权")
                  return false;
                }
              },
            })
          }
        }else {
          console.log('订阅消息未开启')
        }      
      },
      fail: function(error){
        console.log(error);
      },
    })

    效果图:

    写在最后:

    每次整理一点点,每天进步一点点,✌️

    本文来自博客园,作者:_小狐狸,转载请注明原文链接:https://www.cnblogs.com/zwh520/p/15214643.html

  • 相关阅读:
    Linux2.6X内核中文件相关结构体总结
    Linux 内核文件系统与设备操作流程分析
    在linux下删除的共享文件怎么恢复
    fedora17的U盘安装和硬盘安装
    cakephp
    【25.00%】【vijos P1907】飞扬的小鸟
    【14.36%】【codeforces 614C】Peter and Snow Blower
    【14.67%】【codeforces 615D】Multipliers
    【records】10.24..10.30
    【非常高%】【codeforces 733A】Grasshopper And the String
  • 原文地址:https://www.cnblogs.com/zwh520/p/15214643.html
Copyright © 2011-2022 走看看