diff --git a/api/controller/Login.go b/api/controller/Login.go index 2f0ae59..5d98d58 100644 --- a/api/controller/Login.go +++ b/api/controller/Login.go @@ -32,6 +32,18 @@ func (r *Login) LoginPhone(c *gin.Context) { return } + // 检测验证码 + code, _ := global.Redis.Get(c, "login_code_count_"+req.Mobile).Result() + if code == "" { + responses.FailWithMessage("验证码失效", c) + return + } + + if req.Code != code { + responses.FailWithMessage("验证码错误", c) + return + } + // 检测用户信息 userDao := dao.UserDao{} maps := make(map[string]interface{}) diff --git a/api/requests/Login.go b/api/requests/Login.go index 60314ce..92cec89 100644 --- a/api/requests/Login.go +++ b/api/requests/Login.go @@ -15,6 +15,7 @@ type LoginWx struct { // LoginPhone 手机号登录 type LoginPhone struct { Mobile string `json:"mobile" form:"mobile" label:"手机号" validate:"required"` + Code string `json:"code" form:"code" label:"手机号" validate:"required"` Source int `json:"source" form:"source" label:"来源)" validate:"required"` // (1:app 2:公众号 LoginIp string `json:"login_ip" form:"login_ip" label:"登录ip"` } diff --git a/api/service/Public.go b/api/service/Public.go index dee0e3d..8bd62af 100644 --- a/api/service/Public.go +++ b/api/service/Public.go @@ -68,7 +68,7 @@ func (r *PublicService) GetPhoneCode(scene int, phone string) (bool, error) { } // 设置验证码有效期 - _, err = global.Redis.Set(context.Background(), "login_code_"+phone, code, 60*30*time.Second).Result() + _, err = global.Redis.Set(context.Background(), "login_code_"+phone, code, 60*5*time.Second).Result() if err != nil { return false, errors.New("验证码发送失败,请您稍后再试") }