diff --git a/module/usercenter/SMSVerificationCode.go b/module/usercenter/SMSVerificationCode.go index 7414f6d..d2d64c3 100644 --- a/module/usercenter/SMSVerificationCode.go +++ b/module/usercenter/SMSVerificationCode.go @@ -8,26 +8,26 @@ import ( "time" ) -var regSMSVerificationCode sync.Map +var loginOrregSMSVerificationCode sync.Map // 登记注册用验证码 -func StoreRegSMSVerificationCode(mobile string) (string, error) { - codeInterface, ok := regSMSVerificationCode.Load(mobile) +func StoreLoginOrloginOrRegSMSVerificationCode(mobile string) (string, error) { + codeInterface, ok := loginOrregSMSVerificationCode.Load(mobile) if ok { return codeInterface.(string), nil } verificationCode := randCharNumber(6) - regSMSVerificationCode.Store(mobile, verificationCode) + loginOrregSMSVerificationCode.Store(mobile, verificationCode) go func(mobile string) { time.Sleep(time.Second * 5 * 60) - regSMSVerificationCode.Delete(mobile) + loginOrregSMSVerificationCode.Delete(mobile) }(mobile) return verificationCode, nil } // 验证注册验证码 -func RegSMSVerification(mobile, verificationCode string) bool { - codeInterface, ok := regSMSVerificationCode.LoadAndDelete(mobile) +func LoginOrRegSMSVerification(mobile, verificationCode string) bool { + codeInterface, ok := loginOrregSMSVerificationCode.LoadAndDelete(mobile) if !ok { return false } diff --git a/module/usercenter/api.user.go b/module/usercenter/api.user.go index 4e4065f..ae6e449 100644 --- a/module/usercenter/api.user.go +++ b/module/usercenter/api.user.go @@ -30,7 +30,7 @@ func InitManageApi() { towgo.SetFunc(_methodHead+"/user/regByMobile", userRegByMobile) //获取注册短信验证码 - towgo.SetFunc(_methodHead+"/user/getRegSMSVerificationCode", getRegSMSVerificationCode) + towgo.SetFunc(_methodHead+"/user/getLoginOrRegSMSVerificationCode", getLoginOrRegSMSVerificationCode) //修改密码 F towgo.SetFunc(_methodHead+"/user/changepassword", userChangepassword) @@ -45,7 +45,7 @@ func isPhoneNumber(input string) bool { return reg.MatchString(input) } -func getRegSMSVerificationCode(rpcConn towgo.JsonRpcConnection) { +func getLoginOrRegSMSVerificationCode(rpcConn towgo.JsonRpcConnection) { var params struct { Mobile string `json:"mobile"` } @@ -56,7 +56,7 @@ func getRegSMSVerificationCode(rpcConn towgo.JsonRpcConnection) { return } - code, err := StoreRegSMSVerificationCode(params.Mobile) + code, err := StoreLoginOrloginOrRegSMSVerificationCode(params.Mobile) if err != nil { rpcConn.WriteError(500, err.Error()) return @@ -92,7 +92,7 @@ func userRegByMobile(rpcConn towgo.JsonRpcConnection) { return } - if !RegSMSVerification(params.Mobile, params.VerificationCode) { + if !LoginOrRegSMSVerification(params.Mobile, params.VerificationCode) { rpcConn.WriteError(500, "验证码错误") return } @@ -186,7 +186,7 @@ func userLoginOrRegByMobile(rpcConn towgo.JsonRpcConnection) { return } - if !RegSMSVerification(params.Mobile, params.VerificationCode) { + if !LoginOrRegSMSVerification(params.Mobile, params.VerificationCode) { rpcConn.WriteError(500, "验证码错误") return }