查询历史消息,可以根据私聊双方的userId查询,也可以根据groupId查询.
2021年11月起,IM消息历史查询功能从高级功能调整为普通功能,所有应用均默认开通,可直接调用,无需单独开通。
所有增强型应用(包括免费应用),均可以免费调用IM历史消息查询接口,2021年11月起,IM历史消息查询接口不再单独扣除消息条数。
套餐 | 保留规则 |
---|---|
免费套餐 | 免费保留1天 |
750日活套餐 | 免费保留10天 |
800日活套餐 | 免费保留10天 |
10,000日活套餐 | 免费保留30天 |
30,000日活套餐 | 免费保留60天 |
50,000日活套餐 | 免费保留90天 |
历史消息保留时间 | 价格 |
---|---|
延长至30天 | ¥49/月 |
延长至90天 | ¥99/月 |
延长至180天 | ¥198/月 |
延长至360天 | ¥297/月 |
延长至720天 | ¥396/月 |
GET http://{rest-host}/v2/im/history
杭州: rest-hangzhou.goeasy.io
新加坡: rest-singapore.goeasy.io
参数 | 类型 | 必须 | 描述 |
---|---|---|---|
rest-host | String | 是 | 根据您创建应用的区域选择 杭州:rest-hangzhou.goeasy.io 新加坡:暂不支持IM,敬请期待 |
appkey | String | 是 | common key 或者 rest key |
userAId | String | 否 | 私聊双方其中一方的userId,必须与userBId成对传入,不区分发送方和接收方,不得与groupId同时存在 |
userBId | String | 否 | 私聊双方其中一方的userId,必须与userAId成对传入,不区分发送方和接收方,不得与groupId同时存在 |
groupId | String | 否 | 群聊的groupId,不得与userAId/userBId同时存在 |
limit | String | 否 | 每次返回的消息消息总数,默认为10条,最大不超过30条 |
lasttimestamp | long | 否 | 查询发送时间小于(不包含)该时间的历史消息,可用于分页和分批拉取聊天记录,默认为当前时间 |
curl -X GET "http://rest-hangzhou.goeasy.io/v2/im/history?appkey=BC-xxxxx&userAId=user1&userBId=user2&limit=5&lasttimestamp="
{
"code": 200,
"content": [
{
"type": "text", "messageId": "8f0e27a0c7e111eab347b726da4416bd",
"timestamp": 1594958217087, "senderId": "3bb179af-bcc5-4fe0-9dac-c05688484649",
"payload": {"text": "Hello, GoEasyIM"}
},
{
"type": "audio", "messageId": "312c8900c7e211ea9744b7abe1fd7831",
"timestamp": 1594958490234, "senderId": "fdee46b0-4b01-4590-bdba-6586d7617f95",
"payload": {
"name": "20200717120129175.m4a", "contentType": "audio/m4a",
"url": "https://goeasy-hangzhou.oss-cn-hangzhou.aliyuncs.com/goeasy-im/20200717120129175.m4a",
"duration": 2.46, "size": 15220,
}
},
{
"type": "image", "messageId": "9498cf40c7d711eab228bf40d56471fe",
"timestamp": 1594953936702, "senderId": "3bb179af-bcc5-4fe0-9dac-c05688484649",
"payload": {
"name": "04531220.jpg", "contentType": "image/jpeg",
"url": "https://goeasy-hangzhou.oss-cn-hangzhou.aliyuncs.com/goeasy-im/04531220.jpg",
"width": 1758, "height": 765, "size": 62988,
}
},
{
"type": "video", "messageId": "373e36c0c7df11eab228bf40d56471fe",
"senderId": "3bb179af-bcc5-4fe0-9dac-c05688484649", "timestamp": 1594957262738,
"payload": {
"video": {
"name": "1593738719905558_20200717114010716.mp4", "contentType": "video/mp4",
"url": "https://goeasy-im.oss-cn-hangzhou.aliyuncs.com/goeasy-im/1593738719905558_20200717114010716.mp4",
"duration": 46.766667, "width": 544, "height": 960, "size": 7404683
},
"thumbnail": {
"width": 544, "height": 960, "contentType": "image/jpg",
"url": "https://goeasy-im.oss-cn-hangzhou.aliyuncs.com/goeasy-im/1593738719905558_20200717114010716.mp4?x-oss-process=video/snapshot,t_0000,f_jpg,w_544,m_fast"
}
},
}
]
}
{
"code":401,
"content":"Unauthorized"
}