Skip to main content

云信获取云端历史记录

nimGetHistoryMsgs

该接口用于获取一段时间内的历史消息, 由参数beginTime和endTime来控制时间范围。

参数说明

属性类型默认值是否必填描述
scenestringp2pp2p (点对点消息) team (群消息) superTeam (超大群群消息)
tostring``帐号或者群id
beginTimenumber0表示查询开始时间(默认值0表示不限制开始时间)
endTimenumberendTime: endTime表示结束时间(默认值为服务器当前时间),可以传入13位的UTC时间戳(对应毫秒)。
lastMsgIdstring以某条消息为起点进行查询,与beginTime或endTime时间参数搭配使用,时间参数二选一取决于reverse参数。查询时,时间参数设置为该条消息的time,lastMsgId设置为该条消息的idServer,查询结果不包含该条消息
limitnumber15本次查询的消息数量限制, 最多100条, 默认100条
reversebooleanfalse默认false表示从endTime开始往前查找历史消息; true表示从beginTime开始往后查找历史消息
ascbooleanfalse表示对查询结果按照时间进行排序的方式: 如果asc和reverse设置相同(都为true,或者都为false),查询结果按照时间戳从大到小;如果asc和reverse设置不同,查询结果按照时间戳从小到大。

当reverse为false时, 后续查询的endTime对应上次查询的最后一条消息的time字段

当reverse为true时, 后续查询的beginTime对应上次查询的最后一条消息的time字段

示例代码

dsBridge.call('nimGetHistoryMsgs', {
scene: 'p2p',
to: '',
limit: 20
}, function(res) { console.log(res) })

返回结果示例

{
"code":1,
"data": {
msgs: []
},
"msg":"success"
}