浏览 平台 API
服务端 API

消息内容类型

复制

发送消息时,contentType 决定 content 的 JSON 结构。contentTypecontent 必须匹配,否则客户端可能无法解析或渲染消息。

图片、语音、视频和文件消息只在消息体中保存资源地址和元数据。调用发送消息接口前,应先把文件上传到对象存储或业务文件服务,再将可访问的 URL 写入对应字段。

contentType 对照

contentType消息类型content 结构
101文本消息TextElem
102图片消息PictureElem
103语音消息SoundElem
104视频消息VideoElem
105文件消息FileElem
106@ 消息AtTextElem
107合并消息MergeElem
108名片消息CardElem
109位置消息LocationElem
110自定义消息CustomElem
114引用消息QuoteElem
115表情消息FaceElem
117高级文本消息AdvancedTextElem

文本消息

{
  "contentType": 101,
  "content": {
    "content": "hello"
  }
}
字段必填类型说明
contentstring文本消息内容。

图片消息

{
  "contentType": 102,
  "content": {
    "sourcePath": "",
    "sourcePicture": {
      "uuid": "image_001",
      "type": "png",
      "size": 204800,
      "width": 1280,
      "height": 720,
      "url": "https://example.com/images/source.png"
    },
    "bigPicture": {
      "uuid": "image_001_big",
      "type": "png",
      "size": 102400,
      "width": 640,
      "height": 360,
      "url": "https://example.com/images/big.png"
    },
    "snapshotPicture": {
      "uuid": "image_001_snapshot",
      "type": "png",
      "size": 20480,
      "width": 160,
      "height": 90,
      "url": "https://example.com/images/snapshot.png"
    }
  }
}
字段必填类型说明
sourcePathstring图片本地路径。服务端发送时通常为空。
sourcePictureobject原图信息,结构为 PictureBaseInfo
bigPictureobject大图信息,结构为 PictureBaseInfo
snapshotPictureobject缩略图信息,结构为 PictureBaseInfo

PictureBaseInfo

字段必填类型说明
uuidstring图片文件唯一 ID。
typestring图片文件类型,例如 pngjpg
sizeint64图片文件大小,单位为字节。
widthint图片宽度,单位为像素。
heightint图片高度,单位为像素。
urlstring图片文件的可访问地址。

语音消息

{
  "contentType": 103,
  "content": {
    "uuid": "audio_001",
    "soundPath": "",
    "sourceUrl": "https://example.com/audio/voice.m4a",
    "dataSize": 24576,
    "duration": 12,
    "soundType": "m4a"
  }
}
字段必填类型说明
uuidstring语音文件唯一 ID。
soundPathstring语音文件本地路径。服务端发送时通常为空。
sourceUrlstring语音文件的可访问地址。
dataSizeint64语音文件大小,单位为字节。
durationint64语音时长,单位应与客户端 SDK 约定保持一致。
soundTypestring语音文件类型,例如 m4a

视频消息

{
  "contentType": 104,
  "content": {
    "videoPath": "",
    "videoUUID": "video_001",
    "videoUrl": "https://example.com/video/demo.mp4",
    "videoType": "mp4",
    "videoSize": 5242880,
    "duration": 30,
    "snapshotPath": "",
    "snapshotUUID": "snapshot_001",
    "snapshotSize": 65536,
    "snapshotUrl": "https://example.com/video/demo-cover.jpg",
    "snapshotWidth": 640,
    "snapshotHeight": 360
  }
}
字段必填类型说明
videoPathstring视频本地路径。服务端发送时通常为空。
videoUUIDstring视频文件唯一 ID。
videoUrlstring视频文件的可访问地址。
videoTypestring视频文件类型,例如 mp4
videoSizeint64视频文件大小,单位为字节。
durationint64视频时长,单位应与客户端 SDK 约定保持一致。
snapshotPathstring视频封面图本地路径。服务端发送时通常为空。
snapshotUUIDstring视频封面图唯一 ID。
snapshotSizeint64视频封面图大小,单位为字节。
snapshotUrlstring视频封面图的可访问地址。
snapshotWidthint视频封面图宽度,单位为像素。
snapshotHeightint视频封面图高度,单位为像素。

文件消息

{
  "contentType": 105,
  "content": {
    "filePath": "",
    "uuid": "file_001",
    "sourceUrl": "https://example.com/files/report.pdf",
    "fileName": "report.pdf",
    "fileSize": 1048576,
    "fileType": "pdf"
  }
}
字段必填类型说明
filePathstring文件本地路径。服务端发送时通常为空。
uuidstring文件唯一 ID。
sourceUrlstring文件的可访问地址。
fileNamestring文件名称。
fileSizeint64文件大小,单位为字节。
fileTypestring文件类型,例如 pdf

@ 消息

{
  "contentType": 106,
  "content": {
    "text": "@Tom 请查看",
    "atUserList": ["user_002"],
    "isAtSelf": false
  }
}
字段必填类型说明
textstring消息文本内容。
atUserListstring[]被提及用户的 ID 列表。使用 AtAllTag 时表示提及全部成员。
isAtSelfboolean当前消息是否提及消息接收方自身,通常由客户端使用。
quoteMessageobject@ 消息附带的引用消息。没有引用内容时可不传。

合并消息

{
  "contentType": 107,
  "content": {
    "title": "聊天记录",
    "abstractList": ["Tom: hello", "Jerry: received"],
    "multiMessage": []
  }
}
字段必填类型说明
titlestring合并消息标题。
abstractListstring[]合并消息摘要列表,用于会话界面预览。
multiMessageobject[]被合并的消息列表。元素为完整消息对象,字段应与当前 OpenIM 消息结构保持一致。

名片消息

{
  "contentType": 108,
  "content": {
    "userID": "user_002",
    "nickname": "Tom",
    "faceURL": "https://example.com/avatar/tom.png",
    "ex": ""
  }
}
字段必填类型说明
userIDstring名片对应的 OpenIM 用户 ID。
nicknamestring名片展示名称。
faceURLstring名片头像地址。
exstring业务扩展字段。

位置消息

{
  "contentType": 109,
  "content": {
    "description": "OpenIM office",
    "longitude": 113.93041,
    "latitude": 22.53332
  }
}
字段必填类型说明
descriptionstring位置描述。
longitudedouble经度。
latitudedouble纬度。

自定义消息

{
  "contentType": 110,
  "content": {
    "data": "{\"type\":\"order_paid\",\"orderID\":\"order_001\"}",
    "description": "Order paid",
    "extension": "{\"source\":\"backend\"}"
  }
}
字段必填类型说明
datastring业务自定义消息内容。通常使用 JSON 字符串,并由业务客户端解析。
descriptionstring自定义消息的描述信息。
extensionstring自定义扩展字段。

引用消息

{
  "contentType": 114,
  "content": {
    "text": "收到",
    "quoteMessage": {
      "clientMsgID": "client_msg_001",
      "serverMsgID": "server_msg_001",
      "sendID": "user_001",
      "contentType": 101,
      "content": "{\"content\":\"hello\"}"
    }
  }
}
字段必填类型说明
textstring回复文本。
quoteMessageobject被引用的完整消息对象。示例只展示常用字段,实际结构应与当前 OpenIM 消息对象保持一致。

表情消息

{
  "contentType": 115,
  "content": {
    "index": 1,
    "data": "{\"name\":\"smile\"}"
  }
}
字段必填类型说明
indexint表情索引。
datastring表情自定义数据,通常为 JSON 字符串。

高级文本消息

{
  "contentType": 117,
  "content": {
    "text": "请查看附件",
    "messageEntityList": []
  }
}
字段必填类型说明
textstring高级文本消息正文。
messageEntityListobject[]正文中的实体列表,例如文件、图片或其他业务片段。实体结构由当前客户端 SDK 定义。

使用建议

  • contentTypecontent 必须严格匹配。不要只修改类型编号而复用其他类型的内容结构。
  • 媒体类消息应先上传资源,再把资源 URL 和元数据写入 content。Platform API 不直接接收媒体二进制内容。
  • sourcePathsoundPathvideoPathsnapshotPathfilePath 是客户端本地路径,服务端发送时通常留空。
  • 自定义消息需要在客户端和业务服务端之间约定 datadescriptionextension 的业务协议。
  • 导入历史消息时,应保留原始 contentTypecontentsendTime,并确认旧系统消息结构能够被当前客户端识别。

相关页面