#### 1. 前言 --- **一、订阅消息的类型** + 订阅消息的类型: 一次性订阅消息,长期订阅消息,设备订阅消息 + 一次性订阅消息: 用户对订阅消息模板授权 n 次,则可以推送 n 次订阅消息 + 长期订阅消息: 用户订阅一次后,开发者可长期下发多条消息,仅向政务民生、医疗、交通、教育等线下公共服务开放 + 设备订阅消息: 特殊类型的订阅消息,也是长期订阅消息,需要完成设备接入才能使用 **二、微信小程序订阅消息相关文章** + [uniapp API 文档 - 微信小程序订阅消息](https://uniapp.dcloud.net.cn/api/other/requestSubscribeMessage.html) + [微信小程序开发文档 - 订阅消息功能介绍](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/subscribe-message.html) + [微信小程序开发文档 - 订阅消息前端 API](https://developers.weixin.qq.com/miniprogram/dev/api/open-api/subscribe-message/wx.requestSubscribeMessage.html) + [微信小程序开发文档 - 订阅消息服务端 API](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html#订阅消息参数值内容限制说明) #### 2. 订阅消息授权 --- 小程序原生写法 ``` wx.requestSubscribeMessage({ tmplIds: [ '4Bm39pxbpalyZTOTtHHRfjvO1ERKRfH2dhp5R9HyMbU', 'zM0RQGInVrSl4JF8YNmNwF4N-L4hxkipRa-rDBxEq9M' ], success (res) { console.log(res, 'success') }, fail(res){ console.log(res, 'fail') }, complete(res){ console.log(res, 'complete') } }) ``` uniapp 写法(只是将 wx 改为 uni 而已): ``` uni.requestSubscribeMessage({ tmplIds: [ ], success (res) {}, fail(res){}, complete(res){} }) ``` 回调函数 + success 当模板id不能为空,且都是正确的模板id时执行该回调(是否授权都会进入该回调) + fail 当模板id为空或有错误的模板id时进入该回调 + complete 当模板id为空或有错误的模板id时进入该回调(调用成功、失败都会执行)