package handle import ( "base-framework/pkg/config" "base-framework/pkg/reponse" "base-framework/pkg/router" "base-framework/pkg/utils/jwt" ) // Login 登录接口 func Login(c *router.Context) { // 绑定请求体 var req struct { OrgID string `json:"orgId"` UserID string `json:"userId"` Password string `json:"password"` } if err := c.BindJSON(&req); err != nil { reponse.Error(c).Message("请求体不能为空").Send() return } if req.OrgID == "" { reponse.Error(c).Message("机构码不能为空").Send() return } // 参数校验 if req.UserID == "" { reponse.Error(c).Message("账户不能为空").Send() return } if req.Password == "" { reponse.Error(c).Message("密码不能为空").Send() return } // 检查是否有该机构号 hasOrg := false for k := range config.GetDBConfigs() { if k == req.OrgID { hasOrg = true break } } if !hasOrg { reponse.Error(c).Code(reponse.CodeInvalidOrgCode).Send() return } // 生成Token token, err := jwt.CreateToken(req.OrgID, req.UserID) if err != nil { reponse.Error(c).Message("生成令牌失败") return } reponse.Success(c).Data( map[string]string{ "token": token, }).Send() }