package controller import ( "encoding/json" "fmt" "github.com/fonchain_enterprise/fonchain-main/pkg/cache" projectConf "github.com/fonchain_enterprise/fonchain-main/pkg/config" "github.com/fonchain_enterprise/fonchain-main/pkg/e" "github.com/fonchain_enterprise/fonchain-main/pkg/model" "github.com/fonchain_enterprise/fonchain-main/pkg/service" websocketServer "github.com/fonchain_enterprise/fonchain-main/pkg/service/websocket/server" "github.com/gin-gonic/gin" "github.com/google/uuid" "go.uber.org/zap" "strconv" "time" ) func Info(c *gin.Context) { userId := c.PostForm("userId") client := websocketServer.GlobalClientManager.GetUserClient(userId) client.SendMsg([]byte(fmt.Sprintf("userId:%s", userId))) service.ResponseQuickMsg(c, e.Ok, "ok", nil) } func Login(ctx *gin.Context) { if projectConf.Env == "dev" { userIdS := ctx.PostForm("userId") nickName := ctx.PostForm("nickName") userId, _ := strconv.Atoi(userIdS) ctx.Set("mLoginInfo", model.LoginInfo{ ID: uint64(userId), NickName: nickName, }) } var uuidStr string jwtInfo, _ := ctx.Get("jwtInfo") zap.L().Info("websocketLogin", zap.Any("jwtInfo", jwtInfo)) mLoginInfo, _ := ctx.Get("mLoginInfo") zap.L().Info("websocketLogin", zap.Any("mLoginInfo", mLoginInfo)) if mLoginInfoAny, exists := ctx.Get("mLoginInfo"); exists { userInfo := mLoginInfoAny.(model.LoginInfo) uuidStr = uuid.New().String() userInfoBytes, _ := json.Marshal(userInfo) cache.RedisClient.SetNX(uuidStr, string(userInfoBytes), time.Second*60) } else { service.ResponseQuickMsg(ctx, e.Failed, e.ErrNotLogin, nil) return } service.ResponseQuickMsg(ctx, e.Ok, "ok", struct { SocketKey string `json:"socketKey"` }{ SocketKey: uuidStr, }) return }