- refactor verify code
This commit is contained in:
@@ -2,9 +2,6 @@ package mobile
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
@@ -15,12 +12,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
DefVerifyCodeDuration = 5 * time.Minute
|
||||
TestVerifyCode = "123456"
|
||||
)
|
||||
|
||||
const (
|
||||
AuthType = auth2.AuthTypeMobile
|
||||
AuthType = auth2.AuthTypeMobile
|
||||
TestVerifyCode = "123456"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -42,15 +35,13 @@ func init() {
|
||||
|
||||
// 特殊接口
|
||||
func (a *Auther) SendVerifyCode(mobileNumber string) error {
|
||||
code := fmt.Sprintf("%06d", rand.Intn(1000000))
|
||||
globals.SugarLogger.Debugf("SendVerifyCode mobileNumber:%s, code:%s", mobileNumber, code)
|
||||
|
||||
code := a.GenerateVerifyCode(mobileNumber)
|
||||
smsClient := aliyunsmsclient.New("http://dysmsapi.aliyuncs.com/")
|
||||
_, err := smsClient.Execute(globals.AliKey, globals.AliSecret, mobileNumber, "京西菜市", "SMS_84655036", string(utils.MustMarshal(map[string]interface{}{
|
||||
"code": code,
|
||||
})))
|
||||
if err == nil {
|
||||
api.Cacher.Set(mobileNumber, code, DefVerifyCodeDuration)
|
||||
a.SaveVerifyCode(mobileNumber, code)
|
||||
} else {
|
||||
globals.SugarLogger.Infof("SendVerifyCode mobileNumber:%s failed with error:%v", mobileNumber, err)
|
||||
}
|
||||
@@ -65,8 +56,7 @@ func (a *Auther) VerifySecret(mobileNumber, code string) (authBindEx *auth2.Auth
|
||||
err = nil
|
||||
} else {
|
||||
if value := api.Cacher.Get(mobileNumber); value != nil {
|
||||
if code == value.(string) {
|
||||
api.Cacher.Del(mobileNumber)
|
||||
if a.VerifyCode(mobileNumber, code) {
|
||||
err = nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user