From 0657307265b8b688293772e2dfe5f0f0df9a40a0 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 25 Jul 2023 19:43:28 +0800 Subject: [PATCH] fix --- .../internal/handler/datatransferhandler.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/server/websocket/internal/handler/datatransferhandler.go b/server/websocket/internal/handler/datatransferhandler.go index 050f84ad..66cde398 100644 --- a/server/websocket/internal/handler/datatransferhandler.go +++ b/server/websocket/internal/handler/datatransferhandler.go @@ -7,6 +7,7 @@ import ( "fusenapi/server/websocket/internal/logic" "fusenapi/server/websocket/internal/svc" "fusenapi/server/websocket/internal/types" + "fusenapi/utils/auth" "github.com/google/uuid" "github.com/gorilla/websocket" "github.com/zeromicro/go-zero/core/logx" @@ -54,11 +55,11 @@ func DataTransferHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { defer conn.Close() rsp := types.DataTransferRsp{} // 解析JWT token,并对空用户进行判断 - /*claims, err := svcCtx.ParseJwtToken(r) + claims, err := svcCtx.ParseJwtToken(r) // 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息 if err != nil { - rsp.MsgType = constants.WEBSOCKET_UNAUTH - rsp.Message = "unAuth" + rsp.T = constants.WEBSOCKET_UNAUTH + rsp.D = "unAuth" b, _ := json.Marshal(rsp) _ = conn.WriteMessage(websocket.TextMessage, b) return @@ -68,20 +69,20 @@ func DataTransferHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { _, err = auth.GetUserInfoFormMapClaims(claims) // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 if err != nil { - rsp.MsgType = constants.WEBSOCKET_UNAUTH - rsp.Message = "unAuth!!" + rsp.T = constants.WEBSOCKET_UNAUTH + rsp.D = "unAuth!!" b, _ := json.Marshal(rsp) _ = conn.WriteMessage(websocket.TextMessage, b) return } } else { // 如果claims为nil,则认为用户身份为白板用户 - rsp.MsgType = constants.WEBSOCKET_UNAUTH - rsp.Message = "unAuth!!!" + rsp.T = constants.WEBSOCKET_UNAUTH + rsp.D = "unAuth!!!" b, _ := json.Marshal(rsp) _ = conn.WriteMessage(websocket.TextMessage, b) return - }*/ + } //生成连接唯一标识 flag := uuid.New().String() + time.Now().Format("20060102150405") ws := wsConnectItem{