package services import ( "go-msa-auth/internal/models" "time" ) // AuthRequest 客户端请求结构 type AuthRequest struct { UUID string `json:"uuid" binding:"required"` DeviceID string `json:"deviceId" binding:"required"` } // AuthResponse 服务端响应结构 type AuthResponse struct { IsLegal bool `json:"isLegal"` ServerTime string `json:"serverTime"` } // HandleAuth 处理授权逻辑 func HandleAuth(req AuthRequest) AuthResponse { authCode, err := models.FindAuthCode(req.UUID) if err != nil { // UUID 不存在 return AuthResponse{ IsLegal: false, ServerTime: time.Now().Format(time.RFC3339), } } if authCode.DeviceID == "" { // 如果 DeviceID 未绑定,绑定当前 DeviceID authCode.DeviceID = req.DeviceID models.SaveAuthCode(authCode) return AuthResponse{ IsLegal: true, ServerTime: time.Now().Format(time.RFC3339), } } // 如果 DeviceID 已绑定 return AuthResponse{ IsLegal: false, ServerTime: time.Now().Format(time.RFC3339), } }