diff --git a/internal/services/chat.go b/internal/services/chat.go index d44d032..43804b8 100644 --- a/internal/services/chat.go +++ b/internal/services/chat.go @@ -81,17 +81,10 @@ func (h *ChatService) Chat(c *websocket.Conn) { break } //简单协议:bind: - if len(message) > 5 && string(message[:5]) == "bind:" { - uid := string(message[5:]) + if c.Headers("Sec-Websocket-Protocol") == "bind" && c.Headers("X-Session") != "" { + uid := c.Headers("X-Session") _ = h.Gw.BindUid(clientID, uid) log.Printf("bind %s -> uid:%s\n", clientID, uid) - continue - } - // 回显 - err = h.Gw.SendToClient(clientID, []byte("echo: "+string(message))) - if err != nil { - h.ChatFail(c, "send to client failed") - continue } msg, chatType := h.handleMessageToString(c, messageType, message) if chatType == constant.ConnStatusClosed {