融云Web即时通讯的消息格式有哪些?
融云Web即时通讯是一款功能强大的即时通讯解决方案,它支持多种消息格式,包括文本、图片、文件、视频、语音等。下面将详细介绍融云Web即时通讯的消息格式,帮助开发者更好地了解和使用这一功能。
一、文本消息
文本消息是融云Web即时通讯中最基本的消息类型,用于发送纯文本内容。文本消息格式如下:
{
"msgType": "txt",
"from": "sender_id",
"to": "receiver_id",
"content": "这是一条文本消息",
"timestamp": 1616161616161
}
其中,msgType
表示消息类型,值为txt
;from
表示发送者ID;to
表示接收者ID;content
表示消息内容;timestamp
表示消息发送时间戳。
二、图片消息
图片消息用于发送图片内容,支持本地图片和网络图片。图片消息格式如下:
{
"msgType": "img",
"from": "sender_id",
"to": "receiver_id",
"content": {
"url": "http://example.com/image.jpg",
"type": "network"
},
"timestamp": 1616161616161
}
其中,msgType
表示消息类型,值为img
;from
表示发送者ID;to
表示接收者ID;content
中的url
表示图片的URL地址,type
表示图片类型,值为network
表示网络图片。
三、文件消息
文件消息用于发送文件内容,支持多种文件格式,如PDF、Word、Excel等。文件消息格式如下:
{
"msgType": "file",
"from": "sender_id",
"to": "receiver_id",
"content": {
"url": "http://example.com/file.pdf",
"type": "pdf",
"name": "file.pdf",
"size": 1024
},
"timestamp": 1616161616161
}
其中,msgType
表示消息类型,值为file
;from
表示发送者ID;to
表示接收者ID;content
中的url
表示文件的URL地址,type
表示文件类型,name
表示文件名,size
表示文件大小。
四、视频消息
视频消息用于发送视频内容,支持多种视频格式,如MP4、AVI等。视频消息格式如下:
{
"msgType": "video",
"from": "sender_id",
"to": "receiver_id",
"content": {
"url": "http://example.com/video.mp4",
"type": "mp4",
"name": "video.mp4",
"size": 2048
},
"timestamp": 1616161616161
}
其中,msgType
表示消息类型,值为video
;from
表示发送者ID;to
表示接收者ID;content
中的url
表示视频的URL地址,type
表示视频类型,name
表示视频名,size
表示视频大小。
五、语音消息
语音消息用于发送语音内容,支持多种语音格式,如MP3、WAV等。语音消息格式如下:
{
"msgType": "voice",
"from": "sender_id",
"to": "receiver_id",
"content": {
"url": "http://example.com/voice.mp3",
"type": "mp3",
"name": "voice.mp3",
"duration": 30
},
"timestamp": 1616161616161
}
其中,msgType
表示消息类型,值为voice
;from
表示发送者ID;to
表示接收者ID;content
中的url
表示语音的URL地址,type
表示语音类型,name
表示语音名,duration
表示语音时长。
六、自定义消息
融云Web即时通讯还支持自定义消息,允许开发者根据需求定义新的消息类型。自定义消息格式如下:
{
"msgType": "custom",
"from": "sender_id",
"to": "receiver_id",
"content": {
"type": "your_custom_type",
"data": {
"key1": "value1",
"key2": "value2"
}
},
"timestamp": 1616161616161
}
其中,msgType
表示消息类型,值为custom
;from
表示发送者ID;to
表示接收者ID;content
中的type
表示自定义消息类型,data
表示自定义消息内容,开发者可以根据需要添加任意字段。
总结
融云Web即时通讯提供了丰富的消息格式,包括文本、图片、文件、视频、语音等,同时支持自定义消息。开发者可以根据实际需求选择合适的消息格式,实现功能丰富的即时通讯应用。
猜你喜欢:直播服务平台