This commit is contained in:
laodaming 2023-08-23 16:13:14 +08:00
parent 25bf157977
commit a8457b7dad
2 changed files with 5 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package logic
//websocket连接
import (
"bytes"
"encoding/hex"
"encoding/json"
"fusenapi/constants"
"fusenapi/server/websocket/internal/websocket_data"
@ -159,7 +160,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.User
// 获取唯一id
func (l *DataTransferLogic) getUniqueId(userInfo auth.UserInfo) string {
//后面拼接上用户id
uniqueId := uuid.New().String() + getUserJoinPart(userInfo.UserId, userInfo.GuestId)
uniqueId := hex.EncodeToString([]byte(uuid.New().String())) + getUserJoinPart(userInfo.UserId, userInfo.GuestId)
if _, ok := mapConnPool.Load(uniqueId); ok {
uniqueId = l.getUniqueId(userInfo)
}

View File

@ -18,8 +18,8 @@ func (w *wsConnectItem) reuseLastConnect(data []byte) {
return
}
lenClientId := len(clientId)
//id长度不对
if lenClientId > 100 {
//id长度太长
if lenClientId > 500 {
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR, "length of client id is to long"))
return
}
@ -65,5 +65,5 @@ func (w *wsConnectItem) reuseLastConnect(data []byte) {
// 获取用户拼接部分(复用标识用到)
func getUserJoinPart(userId, guestId int64) string {
return fmt.Sprintf("_%d_%d", userId, guestId)
return fmt.Sprintf("i%di%d", userId, guestId)
}