Skip to content

消息管理

本文介绍了如何对消息进行管理, 包括设备告警和事件消息, 自动化和场景执行结果消息

功能概述

kotlin
QuecUserMessageService

查询消息列表

接口说明

查询用户的消息列表(根据消息类型查询,标签查询调用下方新Api)

kotlin
fun getUserMessageListByPageNumber(
    pageNumber: Int,
    pageSize: Int,
    msgType: Int,
    isRead: Boolean,
    deviceKey: String?,
    productKey: String?,
    callback: QuecCallback<QuecPageResponse<QuecUserMessageListModel>>
)

参数说明

参数是否必传说明
pageNumber查询的列表页,默认为 1
pageSize查询的页大小,默认 10
msgType1:设备通知,2:设备告警,3:设备故障,4:系统消息;接收的消息类型任意组合,多个类型使用英文逗号分隔
isRead是否已读
deviceKeydevice key
productKeyproduct key
callback请求回调

QuecUserMessageListModel属性定义

参数类型说明
msgIdString消息ID
msgTypeint/// 消息类型 1-设备通知 2-设备告警 3-设备故障 4-系统消息
isReadboolean是否已读
titleString标题
contentString内容
pkStringProduct Key
dkStringDevice Key
addTimelong添加时间
readTimelong阅读时间
shareCodeString分享code
sceneIconString场景图标
sceneNameString场景名称
sceneExecuteTimeString场景执行时间
executeIdString场景执行Id
logIdString自动化日志id
automationIdString自动化Id
firstLabelString消息一级分类
secondaryLabelString消息二级分类

示例代码

kotlin
QuecUserMessageService.getUserMessageListByPageNumber(1, 10, 1, false, null, null) {
    if (it.isSuccess) {
        val value = it.data //请求成功
    } else {
        val code = it.code //请求失败, 错误码
        val msg = it.msg //请求失败, 错误信息
    }
}

阅读消息

接口说明

单个及批量阅读消息(根据标签阅读调用下面新Api)

kotlin
fun readMessageByMsgIdList(
    msgIdList: String?,
    msgType: Int,
    callback: QuecCallback<QuecReadMsgModel>
)

参数说明

参数是否必传说明
msgIdList阅读的消息ID列表 多个ID使用英文逗号分隔,如果不传,会阅读所有消息
msgType1:设备通知,2:设备告警,3:设备故障,4:系统消息;接收的消息类型任意组合,多个类型使用英文逗号分隔
callback请求回调

QuecReadMsgModel属性定义

参数类型说明
successListList<QuecReadMsgListModel>成功列表
failureListList<QuecReadMsgListModel>失败列表

QuecReadMsgListModel属性定义

参数类型说明
msgIDString消息ID
failureMsgString阅读失败原因(仅失败列表有此字段)

示例代码

kotlin
QuecUserMessageService.readMessageByMsgIdList("msgIdList", 1) {
    if (it.isSuccess) {
        val value = it.data //请求成功
    } else {
        val code = it.code //请求失败, 错误码
        val msg = it.msg //请求失败, 错误信息
    }
}

删除消息

接口说明

删除用户消息

kotlin
fun deleteMessageByMsgId(msgId: String?, language: String?, callback: QuecCallback<Unit>)

参数说明

参数是否必传说明
msgId阅读的消息ID列表 多个ID使用英文逗号分隔
language语音
callback请求回调

示例代码

kotlin
QuecUserMessageService.deleteMessageByMsgId("msgId", "cn") {
    if (it.isSuccess) {
        //删除成功
    } else {
        val code = it.code //请求失败, 错误码
        val msg = it.msg //请求失败, 错误信息
    }
}

阅读消息

接口说明

通过标签标记阅读消息

kotlin
fun readMessageByMsgIdList(
    msgIdList: String?,
    firstLabelList: String?,
    secondaryLabelList: String?,
    callback: QuecCallback<QuecReadMsgModel>
)

参数说明

参数是否必传说明
msgIdList阅读的消息ID列表 多个ID使用英文逗号分隔,如果不传,会阅读所有消息
firstLabelList1:系统 2:智能 3:设备,多个使用","拼接
secondaryLabelList1:隐私 2:服务 3:自动化 4:场景 5:设备通知 6:设备告警 7:设备故障 8:ota,多个使用","拼接
callback请求回调

QuecReadMsgModel属性定义

参数类型说明
successListList<QuecReadMsgListModel>成功列表
failureListList<QuecReadMsgListModel>失败列表

QuecReadMsgListModel属性定义

参数类型说明
msgIDString消息ID
failureMsgString阅读失败原因(仅失败列表有此字段)

示例代码

kotlin
QuecUserMessageService.readMessageByMsgIdList("msgIdList", "1", "1") {
    if (it.isSuccess) {
        val value = it.data //请求成功
    } else {
        val code = it.code //请求失败, 错误码
        val msg = it.msg //请求失败, 错误信息
    }
}

获取未读消息数

接口说明

获取未读消息数,可用于标记用户消息阅读状态

kotlin
fun getMsgStats(callback: QuecCallback<QuecUserMessageStatsModel>)

参数说明

参数是否必传说明
callback请求回调

QuecUserMessageStatsModel属性定义

参数类型说明
smartQuecUserMessageUnReadModel智能相关消息
systemQuecUserMessageUnReadModel系统相关消息
deviceQuecUserMessageUnReadModel设备相关消息

QuecUserMessageUnReadModel属性定义

参数类型说明
readint已读消息数
unReadint未读消息数

示例代码

kotlin
QuecUserMessageService.getMsgStats {
    if (it.isSuccess) {
        val value = it.data //请求成功
    } else {
        val code = it.code //请求失败, 错误码
        val msg = it.msg //请求失败, 错误信息
    }
}

用户接收推送的消息类型

接口说明

获取用户接收推送的消息类型

kotlin
fun getMsgPushSetting(callback: QuecCallback<QuecPushSettingModel>)

参数说明

参数是否必传说明
callback请求回调

QuecPushSettingModel属性定义

参数类型说明
deviceNotifyboolean设备推送
smartNotifyboolean智能推送
systemNotifyboolean系统推送
deviceQuecPushSettingItemModel设备推送子属性设置情况
smartQuecPushSettingItemModel智能推送子属性设置情况
systemQuecPushSettingItemModel系统推送子属性设置情况

QuecPushSettingItemModel属性定义

参数类型说明
appboolean系统推送是否开启
smsboolean短信推送是否开启
voiceboolean语音推送是否开启

示例代码

kotlin
QuecUserMessageService.getMsgPushSetting {
    if (it.isSuccess) {
        val value = it.data //请求成功
    } else {
        val code = it.code //请求失败, 错误码
        val msg = it.msg //请求失败, 错误信息
    }
}

设置用户接收推送的消息类型

接口说明

用户自定义设置接收推送的消息类型

kotlin
fun setMsgPushSetting(config: QuecPushSettingModel, callback: QuecCallback<Unit>)

参数说明

参数是否必传说明
configQuecPushSettingModel属性定义同上【用户接收推送的消息类型】
callback请求回调

示例代码

kotlin
val config = getConfig() //从云端获取配置参数
QuecUserMessageService.setMsgPushSetting(config) {
    if (it.isSuccess) {
        //设置成功
    } else {
        val code = it.code //请求失败, 错误码
        val msg = it.msg //请求失败, 错误信息
    }
}