atomicoke / chat

即时聊天demo (由于不可抗力终止)
http://114.132.249.192
Apache License 2.0
4 stars 0 forks source link

:sparkles:[后端] websocket消息协议改变 #16

Open fzdwx opened 2 years ago

fzdwx commented 2 years ago

Describe the effect you want to achieve

这是当前的消息

{
  "randomId": "d9c3cc4e9626d37f",
  "type": "chat",
  "id": "444444444444",
  "toId": "444444444444",
  "sessionType": "1",
  "fromUname": "fzdwx",
  "chatMessage": {
    "content": "qweqwe",
    "sendTime": "2022-04-27 20:10:18",
    "leftOrRight": "2",
    "contentType": 1
  }
}

之后

123{
  "randomId": "d9c3cc4e9626d37f",
  "id": "444444444444",
  "toId": "444444444444",
  "sessionType": "1",
  "fromUname": "fzdwx",
  "chatMessage": {
    "content": "qweqwe",
    "sendTime": "2022-04-27 20:10:18",
    "leftOrRight": "2",
    "contentType": 1
  }
}

Describe the solution you'd like 在解析为JSON之前先读取一个int,来表示类型。

这将为性能带来提升

fzdwx commented 2 years ago

消息的前6位用来表示类型

String err = "777777";
String success = "666666";
String chat = "100101";
String replayChat = "100102";
String notify= "100201";

现在这样传入,不用传type了

100101{
  "randomId": "e81a68c3c486720fb",
  "id": "444444444444",
  "toId": "444444444444",
  "sessionType": "1",
  "fromUname": "fzdwx",
  "chatMessage": {
    "content": "啊实打实",
    "sendTime": "2022-04-27 23:22:19",
    "leftOrRight": "2",
    "contentType": 1
  }
}

这是现在后端返回的包

666666{"message":"ok","randomId":"e81a1628c3c4286720fb"}
100102{
  "data": {
    "boxOwnerId": "111111111111",
    "boxOwnerSeq": "6",
    "messageId": "309842667163152384"
  },
  "randomId": "e81a1628c3c4286720fb"
}
fzdwx commented 2 years ago

https://atomicoke.yuque.com/staff-kda8t4/hl68h6/vbv7n7

DesignerLookMe commented 1 year ago

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。