This commit is contained in:
laodaming 2023-08-23 18:16:12 +08:00
parent b2460bbc87
commit d349fe3197
2 changed files with 8 additions and 0 deletions

View File

@ -46,11 +46,13 @@ func (l *LoginNotifyLogic) LoginNotify(req *types.LoginNotifyReq, userinfo *auth
logx.Error("解密失败:", err) logx.Error("解密失败:", err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ") return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ")
} }
//真正的数据结构
var parseInfo websocket_data.NotifyData var parseInfo websocket_data.NotifyData
if err = json.Unmarshal([]byte(data), &parseInfo); err != nil { if err = json.Unmarshal([]byte(data), &parseInfo); err != nil {
logx.Error("failed to parse json data:", err) logx.Error("failed to parse json data:", err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid format of parse data") return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid format of parse data")
} }
//websocket连接id不能为空
if parseInfo.WebsocketConnectId == "" { if parseInfo.WebsocketConnectId == "" {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "websocket connect id is empty") 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 { if parseInfo.RequestTime < now-20 || parseInfo.RequestTime > now+20 {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ,time is not in allowed range") return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ,time is not in allowed range")
} }
//查询websocket连接
value, ok := mapConnPool.Load(parseInfo.WebsocketConnectId) value, ok := mapConnPool.Load(parseInfo.WebsocketConnectId)
if !ok { if !ok {
return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found") return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found")
} }
//断言连接
ws, ok := value.(wsConnectItem) ws, ok := value.(wsConnectItem)
if !ok { if !ok {
logx.Error("渲染回调断言websocket连接失败") logx.Error("渲染回调断言websocket连接失败")

View File

@ -46,11 +46,13 @@ func (l *RegisterAccountNotifyLogic) RegisterAccountNotify(req *types.RegisterAc
logx.Error("解密失败:", err) logx.Error("解密失败:", err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ") return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ")
} }
//真正的数据结构
var parseInfo websocket_data.NotifyData var parseInfo websocket_data.NotifyData
if err = json.Unmarshal([]byte(data), &parseInfo); err != nil { if err = json.Unmarshal([]byte(data), &parseInfo); err != nil {
logx.Error("failed to parse json data:", err) logx.Error("failed to parse json data:", err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid format of parse data") return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid format of parse data")
} }
//websocket连接id不能为空
if parseInfo.WebsocketConnectId == "" { if parseInfo.WebsocketConnectId == "" {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "websocket connect id is empty") 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 { if parseInfo.RequestTime < now-20 || parseInfo.RequestTime > now+20 {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ,time is not in allowed range") return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ,time is not in allowed range")
} }
//查询websocket连接
value, ok := mapConnPool.Load(parseInfo.WebsocketConnectId) value, ok := mapConnPool.Load(parseInfo.WebsocketConnectId)
if !ok { if !ok {
return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found") return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found")
} }
//断言连接
ws, ok := value.(wsConnectItem) ws, ok := value.(wsConnectItem)
if !ok { if !ok {
logx.Error("渲染回调断言websocket连接失败") logx.Error("渲染回调断言websocket连接失败")