当前位置: 首页 > news >正文

uniapp 微信小程序 订阅消息

第一步,需要先去小程序官方挑选一下订阅模板拿到模板id

 

订阅按钮在头部导航上,所以

<u-navbar :bgColor="bgColor"><view class="u-nav-slot" slot="left" @click="goSubscribe"><image :src="getimg('subscribe.png')" style="width: 44rpx;height: 44rpx;"></image><view class="le_tt">订阅</view></view></u-navbar>

 

// 订阅goSubscribe() {// 获取时间let time = new Date()let today = time.getDate()let moni1 = time.setDate(today + 1);let yM2 = new Date(moni1).getFullYear() + '-' + (this.checkTime(new Date(moni1).getMonth() + 1)) + '-'let temp2 = yM2 + this.checkTime(new Date(moni1).getDate())   //明天let _this = this;let tempid = ['你的模板id']uni.getSetting({withSubscriptions: true,success(res) {// 通过Object.keys() 获取返回的数据包含了哪些键名,返回的类型是个数组let obj = Object.keys(res.subscriptionsSetting)// mainSwitch 是消息订阅的总开关if (!res.subscriptionsSetting.mainSwitch) {uni.showToast({title: '请去 "设置-消息订阅" 开启消息通知',icon: 'none',duration: 2000});} else {if (obj.includes(tempid[0])) {  //判断是否勾选了“总是保持以上选择……”addSubscribe({date: temp2}).then(res => {})uni.showToast({title: '您已经设置了总是提醒了哟',icon: 'none',duration: 2000});return} else {_this.isSubscribe = trueuni.requestSubscribeMessage({tmplIds: tempid,success(res) {if (res[tempid[0]] == 'accept') {addSubscribe({date: temp2}).then(res => {uni.showToast({icon: 'none',title: res.msg,duration: 2000});})_this.isSubscribe = false} else {_this.isSubscribe = false}},fail(err) {console.log(err);}})}}}})},

http://www.lryc.cn/news/122614.html

相关文章:

  • JDK8日期时间工具类
  • 智汇云舟入选IDC《中国智慧城市数字孪生技术评估,2023》报告
  • 《Zookeeper》源码分析(九)之选举通信网络
  • JVM——栈和堆概述,以及有什么区别?
  • 恒盛策略:沪指冲高回落跌0.26%,酿酒、汽车等板块走弱,燃气股拉升
  • Mongodb 常用操作
  • 【python】-【】
  • 基于Elman神经网络的电力负荷预测
  • LeetCode 0088. 合并两个有序数组
  • 定义行业新标准?谷歌:折叠屏手机可承受20万次折叠
  • 在vscode中配置C/C++环境GCC on Linux
  • windows执行完LoadLibrary()后,可以删除源动态库文件,函数不会锁库文件
  • ios 知识
  • 8 | 美国航班数据分析
  • app.use(express.json()) 使用
  • 基于PyTorch的图像识别
  • js合并数组对象(将数组中具有相同属性对象合并到一起,组成一个新的数组)
  • Spring BeanPostProcessor 接口的作用和使用
  • Android 13 Hotseat定制化修改——006 hotseat图标禁止移动到Launcher中
  • RabbitMQ 发布确认机制
  • 微信小程序使用rich-text解析富文本字符串的时候,遇到image标签图片很大超过屏幕
  • 使用IIS服务器部署Flask python Web项目
  • sentinel核心流程源码解析
  • 中睿天下Coremail | 2023年第二季度企业邮箱安全态势观察
  • 桶排序-1184:明明的随机数
  • Spring Boot中整合Keycloak OpenID Connect(OIDC)
  • 如何使用Mac终端给树莓派pico构建C/C++程序进行开发,以及遇到各种问题该怎么处理,不使用任何IDE或编辑器(例如VS Code)
  • linux 关机和重启
  • Python(八十三)字符串的比较操作
  • Java面试