From d349fe3197d027ccd874fda629516bd76eeebd27 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 23 Aug 2023 18:16:12 +0800 Subject: [PATCH] fix --- server/websocket/internal/logic/loginnotifylogic.go | 4 ++++ server/websocket/internal/logic/registeraccountnotifylogic.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/server/websocket/internal/logic/loginnotifylogic.go b/server/websocket/internal/logic/loginnotifylogic.go index a532764e..024880a4 100644 --- a/server/websocket/internal/logic/loginnotifylogic.go +++ b/server/websocket/internal/logic/loginnotifylogic.go @@ -46,11 +46,13 @@ func (l *LoginNotifyLogic) LoginNotify(req *types.LoginNotifyReq, userinfo *auth logx.Error("解密失败:", err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ") } + //真正的数据结构 var parseInfo websocket_data.NotifyData if err = json.Unmarshal([]byte(data), &parseInfo); err != nil { logx.Error("failed to parse json data:", err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid format of parse data") } + //websocket连接id不能为空 if parseInfo.WebsocketConnectId == "" { return resp.SetStatusWithMessage(basic.CodeServiceErr, "websocket connect id is empty") } @@ -59,10 +61,12 @@ func (l *LoginNotifyLogic) LoginNotify(req *types.LoginNotifyReq, userinfo *auth if parseInfo.RequestTime < now-20 || parseInfo.RequestTime > now+20 { return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ,time is not in allowed range") } + //查询websocket连接 value, ok := mapConnPool.Load(parseInfo.WebsocketConnectId) if !ok { return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found") } + //断言连接 ws, ok := value.(wsConnectItem) if !ok { logx.Error("渲染回调断言websocket连接失败") diff --git a/server/websocket/internal/logic/registeraccountnotifylogic.go b/server/websocket/internal/logic/registeraccountnotifylogic.go index 278c2a13..74da6240 100644 --- a/server/websocket/internal/logic/registeraccountnotifylogic.go +++ b/server/websocket/internal/logic/registeraccountnotifylogic.go @@ -46,11 +46,13 @@ func (l *RegisterAccountNotifyLogic) RegisterAccountNotify(req *types.RegisterAc logx.Error("解密失败:", err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ") } + //真正的数据结构 var parseInfo websocket_data.NotifyData if err = json.Unmarshal([]byte(data), &parseInfo); err != nil { logx.Error("failed to parse json data:", err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid format of parse data") } + //websocket连接id不能为空 if parseInfo.WebsocketConnectId == "" { return resp.SetStatusWithMessage(basic.CodeServiceErr, "websocket connect id is empty") } @@ -59,10 +61,12 @@ func (l *RegisterAccountNotifyLogic) RegisterAccountNotify(req *types.RegisterAc if parseInfo.RequestTime < now-20 || parseInfo.RequestTime > now+20 { return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ,time is not in allowed range") } + //查询websocket连接 value, ok := mapConnPool.Load(parseInfo.WebsocketConnectId) if !ok { return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found") } + //断言连接 ws, ok := value.(wsConnectItem) if !ok { logx.Error("渲染回调断言websocket连接失败")