This commit is contained in:
laodaming 2023-07-25 19:43:28 +08:00
parent 59edb394fa
commit 0657307265

View File

@ -7,6 +7,7 @@ import (
"fusenapi/server/websocket/internal/logic" "fusenapi/server/websocket/internal/logic"
"fusenapi/server/websocket/internal/svc" "fusenapi/server/websocket/internal/svc"
"fusenapi/server/websocket/internal/types" "fusenapi/server/websocket/internal/types"
"fusenapi/utils/auth"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/logx"
@ -54,11 +55,11 @@ func DataTransferHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
defer conn.Close() defer conn.Close()
rsp := types.DataTransferRsp{} rsp := types.DataTransferRsp{}
// 解析JWT token,并对空用户进行判断 // 解析JWT token,并对空用户进行判断
/*claims, err := svcCtx.ParseJwtToken(r) claims, err := svcCtx.ParseJwtToken(r)
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息 // 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
if err != nil { if err != nil {
rsp.MsgType = constants.WEBSOCKET_UNAUTH rsp.T = constants.WEBSOCKET_UNAUTH
rsp.Message = "unAuth" rsp.D = "unAuth"
b, _ := json.Marshal(rsp) b, _ := json.Marshal(rsp)
_ = conn.WriteMessage(websocket.TextMessage, b) _ = conn.WriteMessage(websocket.TextMessage, b)
return return
@ -68,20 +69,20 @@ func DataTransferHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
_, err = auth.GetUserInfoFormMapClaims(claims) _, err = auth.GetUserInfoFormMapClaims(claims)
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
if err != nil { if err != nil {
rsp.MsgType = constants.WEBSOCKET_UNAUTH rsp.T = constants.WEBSOCKET_UNAUTH
rsp.Message = "unAuth!!" rsp.D = "unAuth!!"
b, _ := json.Marshal(rsp) b, _ := json.Marshal(rsp)
_ = conn.WriteMessage(websocket.TextMessage, b) _ = conn.WriteMessage(websocket.TextMessage, b)
return return
} }
} else { } else {
// 如果claims为nil,则认为用户身份为白板用户 // 如果claims为nil,则认为用户身份为白板用户
rsp.MsgType = constants.WEBSOCKET_UNAUTH rsp.T = constants.WEBSOCKET_UNAUTH
rsp.Message = "unAuth!!!" rsp.D = "unAuth!!!"
b, _ := json.Marshal(rsp) b, _ := json.Marshal(rsp)
_ = conn.WriteMessage(websocket.TextMessage, b) _ = conn.WriteMessage(websocket.TextMessage, b)
return return
}*/ }
//生成连接唯一标识 //生成连接唯一标识
flag := uuid.New().String() + time.Now().Format("20060102150405") flag := uuid.New().String() + time.Now().Format("20060102150405")
ws := wsConnectItem{ ws := wsConnectItem{