@quec-wx-mp/api-msg
v1.0.0
Published
消息中心
Readme
消息中心
消息中心模块,提供消息列表查询、未读统计、已读标记、删除和消息类型统计等 API。
安装
npm install @quec-wx-mp/api-msgimport apiMsg from '@quec-wx-mp/api-msg'
const plugin = requirePlugin('quecPlugin')
plugin.use(apiMsg)API 列表
| 方法 | 说明 | | ---------------- | ---------------------- | | getMsgList | 获取消息列表数据 | | getMsgNoReadList | 获取未读消息数量 | | msgDelete | 删除消息 | | readMsg | 标记消息已读 | | getMsgStatsV2 | 统计用户消息类型(v2) |
API 详细说明
1) 获取消息列表数据
接口名称
getMsgList功能描述
按设备和消息类型分页查询消息列表。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | ------------------ | -------- | ------ | ---- | ---------------------------------- | | dk | string | - | 是 | 设备 dk | | pk | string | - | 是 | 产品 pk | | msgType | number | - | 是 | 消息类型(1 通知,2 告警,3 故障) | | page | number | - | 是 | 页码 | | pageSize | number | - | 是 | 每页数量 | | firstLabelList | any | - | 否 | 一级标签筛选 | | secondaryLabelList | any | - | 否 | 二级标签筛选 | | success | function | - | 否 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.data为消息分页列表。
示例代码
plugin.msg.getMsgList({
dk: 'device_key',
pk: 'product_key',
msgType: 1,
page: 1,
pageSize: 10,
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})2) 获取未读消息数量
接口名称
getMsgNoReadList功能描述
获取指定消息类型的未读消息数量。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | ------------------ | -------- | ------ | ---- | ---------------------------------- | | msgType | number | - | 否 | 消息类型(1 通知,2 告警,3 故障) | | firstLabelList | any | - | 否 | 一级标签筛选 | | secondaryLabelList | any | - | 否 | 二级标签筛选 | | page | number | 1 | 否 | 页码(内部固定为 1) | | success | function | - | 否 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,可通过
res.data.total或返回结构中的总数字段获取未读数。
示例代码
plugin.msg.getMsgNoReadList({
msgType: 2,
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})3) 删除消息
接口名称
msgDelete功能描述
根据消息 ID 删除单条消息。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | -------- | | msgId | string | - | 是 | 消息 ID | | success | function | - | 否 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应。
示例代码
plugin.msg.msgDelete({
msgId: 'msg_id',
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})4) 标记消息已读
接口名称
readMsg功能描述
按消息 ID 列表批量标记已读。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | ------------------ | -------- | ------ | ---- | ---------------------------------- | | msgIdList | array | - | 是 | 消息 ID 列表 | | msgType | number | - | 是 | 消息类型(1 通知,2 告警,3 故障) | | firstLabelList | any | - | 否 | 一级标签筛选 | | secondaryLabelList | any | - | 否 | 二级标签筛选 | | success | function | - | 否 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应。
示例代码
plugin.msg.readMsg({
msgIdList: ['msg_1', 'msg_2'],
msgType: 1,
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})5) 统计用户消息类型
接口名称
getMsgStatsV2功能描述
统计用户消息类型数量。参数
| 属性 | 类型 | 默认值 | 必填 | 说明 | | -------- | -------- | ------ | ---- | -------- | | success | function | - | 否 | 成功回调 | | fail | function | - | 否 | 失败回调 | | complete | function | - | 否 | 结束回调 |
返回数据
- success(res):接口成功响应,
res.data为消息类型统计数据。
示例代码
plugin.msg.getMsgStatsV2({
success(res) {
console.log(res)
},
fail(err) {
console.log(JSON.stringify(err))
},
complete() {}
})