发送消息时,contentType 决定 content 的 JSON 结构。contentType 与 content 必须匹配,否则客户端可能无法解析或渲染消息。
图片、语音、视频和文件消息只在消息体中保存资源地址和元数据。调用发送消息接口前,应先把文件上传到对象存储或业务文件服务,再将可访问的 URL 写入对应字段。
contentType 对照
文本消息
{
"contentType": 101,
"content": {
"content": "hello"
}
}
图片消息
{
"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"
}
}
}
PictureBaseInfo
语音消息
{
"contentType": 103,
"content": {
"uuid": "audio_001",
"soundPath": "",
"sourceUrl": "https://example.com/audio/voice.m4a",
"dataSize": 24576,
"duration": 12,
"soundType": "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
}
}
文件消息
{
"contentType": 105,
"content": {
"filePath": "",
"uuid": "file_001",
"sourceUrl": "https://example.com/files/report.pdf",
"fileName": "report.pdf",
"fileSize": 1048576,
"fileType": "pdf"
}
}
@ 消息
{
"contentType": 106,
"content": {
"text": "@Tom 请查看",
"atUserList": ["user_002"],
"isAtSelf": false
}
}
合并消息
{
"contentType": 107,
"content": {
"title": "聊天记录",
"abstractList": ["Tom: hello", "Jerry: received"],
"multiMessage": []
}
}
名片消息
{
"contentType": 108,
"content": {
"userID": "user_002",
"nickname": "Tom",
"faceURL": "https://example.com/avatar/tom.png",
"ex": ""
}
}
位置消息
{
"contentType": 109,
"content": {
"description": "OpenIM office",
"longitude": 113.93041,
"latitude": 22.53332
}
}
自定义消息
{
"contentType": 110,
"content": {
"data": "{\"type\":\"order_paid\",\"orderID\":\"order_001\"}",
"description": "Order paid",
"extension": "{\"source\":\"backend\"}"
}
}
引用消息
{
"contentType": 114,
"content": {
"text": "收到",
"quoteMessage": {
"clientMsgID": "client_msg_001",
"serverMsgID": "server_msg_001",
"sendID": "user_001",
"contentType": 101,
"content": "{\"content\":\"hello\"}"
}
}
}
表情消息
{
"contentType": 115,
"content": {
"index": 1,
"data": "{\"name\":\"smile\"}"
}
}
高级文本消息
{
"contentType": 117,
"content": {
"text": "请查看附件",
"messageEntityList": []
}
}
使用建议
contentType 和 content 必须严格匹配。不要只修改类型编号而复用其他类型的内容结构。- 媒体类消息应先上传资源,再把资源 URL 和元数据写入
content。Platform API 不直接接收媒体二进制内容。 sourcePath、soundPath、videoPath、snapshotPath 和 filePath 是客户端本地路径,服务端发送时通常留空。- 自定义消息需要在客户端和业务服务端之间约定
data、description 和 extension 的业务协议。 - 导入历史消息时,应保留原始
contentType、content 和 sendTime,并确认旧系统消息结构能够被当前客户端识别。
相关页面