fix
This commit is contained in:
@@ -152,7 +152,7 @@ func (l *DataTransferLogic) DataTransfer(req *types.DataTransferReq, w http.Resp
|
||||
isAuth, userInfo = l.checkAuth(r)
|
||||
if !isAuth {
|
||||
//未授权响应消息
|
||||
l.unAuthResponse(conn, isFirefoxBrowser)
|
||||
l.unAuthResponse(conn, isFirefoxBrowser, "unAuth")
|
||||
conn.Close()
|
||||
return
|
||||
}
|
||||
@@ -184,34 +184,37 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
|
||||
return wsConnectItem{}, err
|
||||
}
|
||||
if oldWid != "" {
|
||||
//解析传入的wid是不是属于自己的用户的
|
||||
decryptionWid, err := encryption_decryption.CBCDecrypt(oldWid)
|
||||
if err != nil {
|
||||
logx.Error(err, ":", oldWid)
|
||||
return wsConnectItem{}, errors.New("解码wid失败")
|
||||
}
|
||||
lendecryptionWid := len(decryptionWid)
|
||||
//合成client后缀,不是同个后缀的不能复用
|
||||
userPart := getUserJoinPart(userInfo.UserId, userInfo.GuestId, userAgent)
|
||||
lenUserPart := len(userPart)
|
||||
canUseOldWid := true
|
||||
//长度太短
|
||||
if lendecryptionWid <= lenUserPart {
|
||||
logx.Info("复用的连接标识太短,不符合重用条件")
|
||||
canUseOldWid = false
|
||||
}
|
||||
//尾部不同不能复用
|
||||
if decryptionWid[lendecryptionWid-lenUserPart:] != userPart {
|
||||
logx.Info("尾部用户信息不同,不符合重用条件")
|
||||
canUseOldWid = false
|
||||
}
|
||||
//存在是不能给他申请重新绑定
|
||||
if _, ok := mapConnPool.Load(oldWid); ok {
|
||||
logx.Info("复用的连接标识已被其他客户端使用,不符合重用条件")
|
||||
canUseOldWid = false
|
||||
}
|
||||
//检测通过可以用旧的
|
||||
if canUseOldWid {
|
||||
for i := 0; i < 1; i++ {
|
||||
oldWid, err = encryption_decryption.NumberStrToBase64Str(oldWid)
|
||||
if err != nil {
|
||||
logx.Error("wid转base64失败:", err)
|
||||
break
|
||||
}
|
||||
//解析传入的wid是不是属于自己的用户的
|
||||
decryptionWid, err := encryption_decryption.CBCDecrypt(oldWid)
|
||||
if err != nil {
|
||||
logx.Error("解密wid失败:", err)
|
||||
break
|
||||
}
|
||||
lendecryptionWid := len(decryptionWid)
|
||||
//合成client后缀,不是同个后缀的不能复用
|
||||
userPart := getUserJoinPart(userInfo.UserId, userInfo.GuestId, userAgent)
|
||||
lenUserPart := len(userPart)
|
||||
//长度太短
|
||||
if lendecryptionWid <= lenUserPart {
|
||||
logx.Error("复用的连接标识太短,不符合重用条件")
|
||||
break
|
||||
}
|
||||
//尾部不同不能复用
|
||||
if decryptionWid[lendecryptionWid-lenUserPart:] != userPart {
|
||||
logx.Error("尾部用户信息不同,不符合重用条件")
|
||||
break
|
||||
}
|
||||
//存在是不能给他申请重新绑定
|
||||
if _, ok := mapConnPool.Load(oldWid); ok {
|
||||
logx.Error("复用的连接标识已被其他客户端使用,不符合重用条件")
|
||||
break
|
||||
}
|
||||
logx.Info("====复用旧的ws连接成功====")
|
||||
uniqueId = oldWid
|
||||
}
|
||||
@@ -275,7 +278,7 @@ func (l *DataTransferLogic) getUniqueId(userInfo *auth.UserInfo, userAgent strin
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return uniqueId, nil
|
||||
return encryption_decryption.Base64StrToNumberStr(uniqueId), nil
|
||||
}
|
||||
|
||||
// 鉴权
|
||||
@@ -293,10 +296,10 @@ func (l *DataTransferLogic) checkAuth(r *http.Request) (isAuth bool, userInfo *a
|
||||
}
|
||||
|
||||
// 鉴权失败通知
|
||||
func (l *DataTransferLogic) unAuthResponse(conn *websocket.Conn, isFirefoxBrowser bool) {
|
||||
func (l *DataTransferLogic) unAuthResponse(conn *websocket.Conn, isFirefoxBrowser bool, errMessage string) {
|
||||
rsp := websocket_data.DataTransferData{
|
||||
T: constants.WEBSOCKET_UNAUTH,
|
||||
D: websocket_data.ConnectUnAuth{Message: "unAuth"},
|
||||
D: websocket_data.ConnectUnAuth{Message: errMessage},
|
||||
}
|
||||
b, _ := json.Marshal(rsp)
|
||||
if isFirefoxBrowser {
|
||||
|
||||
Reference in New Issue
Block a user