发送
私聊
{
type: "SEND_TO_ONE_REQUEST",
body: {
type: "text || img || voice", // 发送的数据类型
userId: 9,
toUser: 13,
// 文本
content: {
text: "哈喽"
}
// 图片
content: {
url: "blob:http://localhost:8080/49d68e6f-6f2a-4d06-9fd4-ec606e79d1c8",
w: 200, // 宽度
h: 200 // 高度
},
// 语音
content: {
url: "_doc/uniapp_temp_1603265466159/recorder/1603265603072.mp3",
length: "00:06" // 时长
}
}
}
群聊
和私聊一样, 只是发送的 type 变为 SEND_TO_ALL_REQUEST
{
type: "SEND_TO_ALL_REQUEST",
body: {
type: "text || img || voice", // 发送的数据类型
circleId: 100001,
userId: 9,
// 文本
content: {
text: "哈喽"
}
// 图片
content: {
url: "blob:http://localhost:8080/49d68e6f-6f2a-4d06-9fd4-ec606e79d1c8",
w: 200, // 宽度
h: 200 // 高度
},
// 语音
content: {
url: "_doc/uniapp_temp_1603265466159/recorder/1603265603072.mp3",
length: "00:06" // 时长
}
}
}
注意: 在发送群聊消息的时候不需要返回数据
接收
私聊
注意: 返回的 content 是一个对象
{
"type":"SEND_TO_USER_REQUEST",
"body":{
// 文本
"type": "text",
"content":{
"text":"测试"
},
// 图片
"type": "img",
"content":{
"url":"blob:http://localhost:8080/49d68e6f-6f2a-4d06-9fd4-ec606e79d1c8",
"w":200,
"h":200,
},
// 语音
"type": "voice",
"content":{
url: "_doc/uniapp_temp_1603265466159/recorder/1603265603072.mp3",
length: "00:06" // 时长
}
"createTime":1603264147696,
"toUser":"TQL",
"toUserId":13,
"toUserImg":"http://39.99.156.255:8080/CircleChat/img/5993d7c4-8a22-4a4e-a2a5-ebacd0b0b278.jpeg",
"userId":9,
"userImg":"http://39.99.156.255:8080/CircleChat/img/a274f203-ea22-4594-be31-7449c3e52bca.jpeg",
"username":"LiRyan"
}
}
根据发送的 `type`, 返回对应的 type , 并需要对图片和语音的 url 进行处理
群聊
和私聊一样, 只是发送的 type 变为 SEND_TO_CIRCLE_REQUEST, 要注意对 url 进行处理
新增 circleType 字段
{
"type":"SEND_TO_CIRCLE_REQUEST",
"body":{
// 文本
"type": "text",
"content":{
"text":"测试"
},
// 图片
"type": "img",
"content":{
"url":"blob:http://localhost:8080/49d68e6f-6f2a-4d06-9fd4-ec606e79d1c8",
"w":200,
"h":200,
},
// 语音
"type": "voice",
"content":{
url: "_doc/uniapp_temp_1603265466159/recorder/1603265603072.mp3",
length: "00:06" // 时长
},
"circleId":100001,
"circleImg":"http://39.99.156.255:8080/CircleChat/img/672c1250-cc59-4df3-a960-aa78126e689e.jpeg",
"circleName":"LiRyan",
"circleType": "交友圈",
"content":"我是一条群聊消息",
"createTime":1603266020756,
"userId":11,
"userImg":"http://39.99.156.255:8080/CircleChat/img/5993d7c4-8a22-4a4e-a2a5-ebacd0b0b278.jpeg",
"username":"张三丰"
}
}
聊天列表
私聊
data 需要根据 type 判断
[
{
"userId": 9, // 对方 id
"username": "LiRyan", // 对方用户名
"avatar": "/static/chat/img/im/face/face_2.jpg", // 头像
"data": "测试内容",
"data": "[图片]",
"data": "[语音]",
"noReadNum": 0, // 未读数
"time": 1603018382636
}
]
群聊
和私聊一样, 群聊的 data 需要根据 type 来判断
非本人发送的信息加上用户名 :中文冒号
新增 circleType 字段
[
{
"circleId": 100001,
"circleName": "LiRyan",
"circleType": "交友圈",
"avatar": "/static/chat/img/im/face/face_2.jpg", // 头像
"data": "LiRyan:我是一条群聊消息",
"data": "LiRyan:[图片]",
"data": "LiRyan:[语音]",
"noReadNum": 0, // 未读数
"time": 1603018382636
}
]
聊天详情
私聊
msg 中需要 type 判断类型, 并且 content 中的内容也需要根据 type 判断, 并且必须处理 url
[
{
"type": "user", // 固定值
"msg": {
"id": 0, // 聊天信息唯一 id, 从 0 开始递增
"type": "text || img || voice", // 文本 | 图片 | 语音
"time": 1603014006394, // 与上一次消息相距 300s 才返回时间
"userinfo": {
"uid": 9, // 发送人 id
"username": "", // 单人聊天 username 为空
"face": "/static/chat/img/face.jpg" // 发送人头像
},
"content": {
"text": "测试内容" // 文本
},
"content": {
"url": "/static/img/p10.jpg", // 图片
"w": 200, // 宽度
"h": 200 // 高度
},
"content": {
"url": "/static/voice/2.mp3", // 语音
"length": "00:06" // 时长
}
}
}
]
单人聊天 username 为空
超过 300s 才返回时间, 否则返回空字符串
群聊
和私聊一样, 群聊需要返回 type , 并且也需要返回 type 对应的 content 和 处理过的 url
[
{
"type": "user", // 固定值
"msg": {
"id": 96, // 聊天信息唯一 id
"type": "text || img || voice", // 文本 | 图片 | 语音
"time": 1603014006394,
"userinfo": {
"uid": 9, // 发送人 id
"username": "LiRyan", // 发送人 username
"face": "/static/chat/img/face.jpg" // 发送人头像
},
"content": {
"text": "测试内容" // 文本
},
"content": {
"url": "/static/img/p10.jpg", // 图片
"w": 200, // 宽度
"h": 200 // 高度
},
"content": {
"url": "/static/voice/2.mp3", // 语音
"length": "00:06" // 时长
}
}
}
]
群聊需要 username
需要的接口
读取信息
/readMsg
需要将该条信息的 noReadNum 字段重置为 0 , 并且需要把总未读数减去读取的数量
获取总未读数
/getNoReadNum
获取聊天列表
/getChatList
获取聊天详情
/getChatDetail
聊天详情初始返回30条, 每次累加 30 条