1
This commit is contained in:
@ -3,17 +3,18 @@ package authservice
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/bytedance/sonic"
|
||||
log "github.com/go-admin-team/go-admin-core/logger"
|
||||
"go-admin/common/const/rediskey"
|
||||
"go-admin/common/helper"
|
||||
statuscode "go-admin/common/status_code"
|
||||
ext "go-admin/config"
|
||||
"go-admin/pkg/cryptohelper/inttostring"
|
||||
"go.uber.org/zap"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
log "github.com/go-admin-team/go-admin-core/logger"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
//
|
||||
@ -461,7 +462,8 @@ import (
|
||||
// return true
|
||||
//}
|
||||
|
||||
func SendGoToneSms(phone, area string) int {
|
||||
// smsType 0-注册 1-重置密码
|
||||
func SendGoToneSms(phone, area string, smsType int) int {
|
||||
//smsCode =
|
||||
smsString := inttostring.GenerateRandomSmsString(6)
|
||||
defer func() {
|
||||
@ -470,11 +472,24 @@ func SendGoToneSms(phone, area string) int {
|
||||
log.Error("SendRegisterEmail Error:", r)
|
||||
}
|
||||
}()
|
||||
get := helper.DefaultRedis.Get(fmt.Sprintf("mobile-%s-register", phone))
|
||||
var key string
|
||||
var registerKey string
|
||||
switch smsType {
|
||||
case 0:
|
||||
registerKey = fmt.Sprintf("mobile-%s-register", phone)
|
||||
key = fmt.Sprintf(rediskey.PCRegisterMobile, phone)
|
||||
case 1:
|
||||
registerKey = fmt.Sprintf("mobile-%s-resetpwd", phone)
|
||||
key = fmt.Sprintf(rediskey.PCResetPwdMobile, phone)
|
||||
default:
|
||||
return statuscode.GoToneSmsTypeErr
|
||||
}
|
||||
|
||||
get := helper.DefaultRedis.Get(registerKey)
|
||||
if get.Val() != "" { //说明邮箱操作频繁
|
||||
return statuscode.GoToneSmsOrderTooOften
|
||||
}
|
||||
key := fmt.Sprintf(rediskey.PCRegisterMobile, phone)
|
||||
|
||||
if err := helper.DefaultRedis.SetStringExpire(key, smsString, time.Second*300); err != nil {
|
||||
log.Error("sendEmail setRedis Error:", zap.Error(err))
|
||||
return statuscode.ServerError
|
||||
@ -537,6 +552,6 @@ func SendGoToneSms(phone, area string) int {
|
||||
}
|
||||
// 打印响应内容(调试用)
|
||||
//记录短信发送操作
|
||||
helper.DefaultRedis.SetStringExpire(fmt.Sprintf("mobile-%s-register", phone), "register", time.Second*60)
|
||||
helper.DefaultRedis.SetStringExpire(registerKey, "1", time.Second*60)
|
||||
return statuscode.OK
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user