跳转到主要内容
POST
/
conversation
/
sync
curl -X POST "http://localhost:5001/conversation/sync" \
  -H "Content-Type: application/json" \
  -d '{
    "uid": "user123",
    "version": 1640995200000000000,
    "last_msg_seqs": "user1:1:100|group1:2:200",
    "msg_count": 10,
    "only_unread": 0,
    "exclude_channel_types": [3, 4]
  }'
[
  {
    "channel_id": "group123",
    "channel_type": 2,
    "unread": 5,
    "timestamp": 1640995200,
    "last_msg_seq": 1005,
    "version": 1640995200000000000,
    "messages": [
      {
        "message_id": 123456789,
        "message_seq": 1005,
        "client_msg_no": "msg_123",
        "from_uid": "user456",
        "timestamp": 1640995200,
        "payload": "SGVsbG8gV29ybGQ="
      }
    ]
  },
  {
    "channel_id": "private_user123_user789",
    "channel_type": 1,
    "unread": 2,
    "timestamp": 1640995100,
    "last_msg_seq": 502,
    "version": 1640995100000000000,
    "messages": [
      {
        "message_id": 123456788,
        "message_seq": 502,
        "client_msg_no": "msg_122",
        "from_uid": "user789",
        "timestamp": 1640995100,
        "payload": "SGkgdGhlcmU="
      }
    ]
  }
]

概述

同步用户的会话列表和状态,支持增量同步和全量同步。

请求体

必传参数

uid
string
required
用户 ID

可选参数

version
integer
版本时间戳,用于增量同步
last_msg_seqs
string
客户端最后消息序列号,格式:channelID:channelType:last_msg_seq|channelID:channelType:last_msg_seq
msg_count
integer
每个会话返回的最近消息数量
only_unread
integer
default:0
是否只返回未读会话 (1=只返回未读, 0=返回所有)
exclude_channel_types
array
要排除的频道类型数组
exclude_channel_types[]
integer
频道类型
curl -X POST "http://localhost:5001/conversation/sync" \
  -H "Content-Type: application/json" \
  -d '{
    "uid": "user123",
    "version": 1640995200000000000,
    "last_msg_seqs": "user1:1:100|group1:2:200",
    "msg_count": 10,
    "only_unread": 0,
    "exclude_channel_types": [3, 4]
  }'
[
  {
    "channel_id": "group123",
    "channel_type": 2,
    "unread": 5,
    "timestamp": 1640995200,
    "last_msg_seq": 1005,
    "version": 1640995200000000000,
    "messages": [
      {
        "message_id": 123456789,
        "message_seq": 1005,
        "client_msg_no": "msg_123",
        "from_uid": "user456",
        "timestamp": 1640995200,
        "payload": "SGVsbG8gV29ybGQ="
      }
    ]
  },
  {
    "channel_id": "private_user123_user789",
    "channel_type": 1,
    "unread": 2,
    "timestamp": 1640995100,
    "last_msg_seq": 502,
    "version": 1640995100000000000,
    "messages": [
      {
        "message_id": 123456788,
        "message_seq": 502,
        "client_msg_no": "msg_122",
        "from_uid": "user789",
        "timestamp": 1640995100,
        "payload": "SGkgdGhlcmU="
      }
    ]
  }
]

响应字段

响应是一个会话数组,每个会话包含以下字段:

会话信息

channel_id
string
required
频道 ID
channel_type
integer
required
频道类型
  • 1 - 个人频道
  • 2 - 群组频道
unread
integer
required
未读消息数量
timestamp
integer
required
最后消息时间戳
last_msg_seq
integer
required
最后消息序列号
version
integer
required
会话版本号(纳秒级时间戳)

消息列表

messages
array
required
会话中的最新消息列表

状态码

状态码说明
200会话同步成功
400请求参数错误
403没有访问权限
500服务器内部错误

参数说明

消息数量 (msg_count)

控制每个会话返回的消息数量:
说明适用场景
0不返回消息只需要会话列表
1-50返回指定数量正常使用
> 50系统限制为 50避免数据过大