From b0f598af6816880ac72124e6ad08d0448d80aba5 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 25 Jul 2023 18:04:01 +0800 Subject: [PATCH] fix --- .../internal/handler/datatransferhandler.go | 12 ++++++------ .../internal/handler/rendernotifyhandler.go | 1 - server/websocket/internal/types/types.go | 8 ++++---- server_api/websocket.api | 8 ++++---- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/server/websocket/internal/handler/datatransferhandler.go b/server/websocket/internal/handler/datatransferhandler.go index afcaf88d..827ac058 100644 --- a/server/websocket/internal/handler/datatransferhandler.go +++ b/server/websocket/internal/handler/datatransferhandler.go @@ -97,8 +97,8 @@ func DataTransferHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { mapConnPool.Store(flag, ws) defer ws.close() //把连接成功消息发回去 - rsp.MsgType = constants.WEBSOCKET_CONNECT_SUCCESS - rsp.Message = flag + rsp.T = constants.WEBSOCKET_CONNECT_SUCCESS + rsp.D = flag b, _ := json.Marshal(rsp) conn.WriteMessage(websocket.TextMessage, b) //循环读客户端信息 @@ -116,8 +116,8 @@ func DataTransferHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { // 心跳 func (w *wsConnectItem) heartbeat() { rsp := types.DataTransferRsp{ - MsgType: constants.WEBSOCKET_HEARTBEAT, - Message: "", + T: constants.WEBSOCKET_HEARTBEAT, + D: "", } for { time.Sleep(time.Second * 10) @@ -202,11 +202,11 @@ func (w *wsConnectItem) dealwithReciveData(data []byte) { logx.Error("invalid format of websocket message") return } - switch parseInfo.MsgType { + switch parseInfo.T { //图片渲染 case constants.WEBSOCKET_RENDER_IMAGE: var renderImageData []types.RenderImageReqMsg - if err := json.Unmarshal([]byte(parseInfo.Message), &renderImageData); err != nil { + if err := json.Unmarshal([]byte(parseInfo.D), &renderImageData); err != nil { logx.Error("invalid format of websocket render image message", err) return } diff --git a/server/websocket/internal/handler/rendernotifyhandler.go b/server/websocket/internal/handler/rendernotifyhandler.go index 5fa2371a..de6e3e21 100644 --- a/server/websocket/internal/handler/rendernotifyhandler.go +++ b/server/websocket/internal/handler/rendernotifyhandler.go @@ -50,7 +50,6 @@ func RenderNotifyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { h.Write([]byte(fmt.Sprintf(constants.RENDER_NOTIFY_SIGN_KEY, string(notifyByte), req.Time))) signHex := h.Sum(nil) sign := hex.EncodeToString(signHex) - fmt.Println(sign) if req.Sign != sign { httpx.OkJsonCtx(r.Context(), w, basic.Response{ Code: basic.CodeRequestParamsErr.Code, diff --git a/server/websocket/internal/types/types.go b/server/websocket/internal/types/types.go index 6082881a..6a1cf750 100644 --- a/server/websocket/internal/types/types.go +++ b/server/websocket/internal/types/types.go @@ -6,13 +6,13 @@ import ( ) type DataTransferReq struct { - MsgType string `json:"msg_type"` //消息类型 - Message string `json:"message"` //传递的消息 + T string `json:"t"` //消息类型 + D string `json:"d"` //传递的消息 } type DataTransferRsp struct { - MsgType string `json:"msg_type"` //消息类型 - Message string `json:"message"` //传递的消息 + T string `json:"t"` //消息类型 + D string `json:"d"` //传递的消息 } type RenderImageReqMsg struct { diff --git a/server_api/websocket.api b/server_api/websocket.api index 4b5c1fed..d0daf98b 100644 --- a/server_api/websocket.api +++ b/server_api/websocket.api @@ -19,12 +19,12 @@ service websocket { //websocket数据交互 type DataTransferReq { - MsgType string `json:"msg_type"` //消息类型 - Message string `json:"message"` //传递的消息 + T string `json:"t"` //消息类型 + D string `json:"d"` //传递的消息 } type DataTransferRsp { - MsgType string `json:"msg_type"` //消息类型 - Message string `json:"message"` //传递的消息 + T string `json:"t"` //消息类型 + D string `json:"d"` //传递的消息 } type RenderImageReqMsg { //websocket接受需要云渲染的图片 ProductId int64 `json:"product_id"`