feat:优化项目信息
This commit is contained in:
@ -7,7 +7,7 @@ import (
|
||||
|
||||
type Sms struct{}
|
||||
|
||||
func (a *Sms) sCaptcha(c *gin.Context) {
|
||||
func (*Sms) Captcha(c *gin.Context) {
|
||||
form := &struct {
|
||||
Mobile string `json:"mobile" form:"mobile" binding:"required"`
|
||||
}{}
|
||||
@ -16,5 +16,18 @@ func (a *Sms) sCaptcha(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
err := controller.NewSms()().Captcha(form.Mobile)
|
||||
APIResponse(err)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*Sms) CaptchaValidate(c *gin.Context) {
|
||||
form := &struct {
|
||||
Mobile string `json:"mobile" form:"mobile" binding:"required"`
|
||||
Captcha string `json:"captcha" form:"captcha" binding:"required"`
|
||||
}{}
|
||||
if err := Bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := controller.NewSms()().CaptchaValidate(form.Mobile, form.Captcha)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
@ -4,18 +4,26 @@ import (
|
||||
"SciencesServer/app/handle"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Sms struct{}
|
||||
|
||||
type SmsHandle func() *Sms
|
||||
|
||||
func (c *Sms) captchaCallback(mobile, code string) error {
|
||||
//content := fmt.Sprintf("【汇安科技】您的验证码是%s,三分钟内有效", code)
|
||||
// 发送短信
|
||||
//_ = platform.NewSms().Send()(platform.SmsSendModeForGroup, &platform.SmsParam{
|
||||
// Mobile: []string{mobile}, Content: content,
|
||||
//})
|
||||
type (
|
||||
CaptchaCallback struct {
|
||||
Token string `json:"token"`
|
||||
EffectTime int `json:"effect_time"`
|
||||
}
|
||||
)
|
||||
|
||||
// tokenEffectTime Token有效期,单位s
|
||||
var tokenEffectTime = 5 * 60
|
||||
|
||||
func (c *Sms) captchaCallback(mobile, code string, callback func() error) error {
|
||||
content := fmt.Sprintf("【中科云】您的验证码是%s,三分钟内有效", code)
|
||||
fmt.Println(content)
|
||||
// 执行保存数据库
|
||||
//mSysSmsLogs := model.NewSysSmsLogs()
|
||||
//mSysSmsLogs.Mobile = mobile
|
||||
@ -23,6 +31,14 @@ func (c *Sms) captchaCallback(mobile, code string) error {
|
||||
//mSysSmsLogs.Usage = model2.SysSmsLogsUsageForCaptcha
|
||||
//
|
||||
//return model2.Create(mSysSmsLogs.SysSmsLogs)
|
||||
|
||||
// 发送短信
|
||||
//_ = platform.NewSms().Send()(platform.SmsSendModeForGroup, &platform.SmsParam{
|
||||
// Mobile: []string{mobile}, Content: content,
|
||||
//})
|
||||
if callback != nil {
|
||||
//_ = callback()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -32,11 +48,32 @@ func (c *Sms) Captcha(mobile string) error {
|
||||
return errors.New("手机格式不正确")
|
||||
}
|
||||
if err := handle.NewCaptcha().Sms(6, mobile, c.captchaCallback); err != nil {
|
||||
return errors.New("操作错误")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Sms) CaptchaValidate(mobile, captcha string) (*CaptchaCallback, error) {
|
||||
if !utils.ValidateMobile(mobile) {
|
||||
return nil, errors.New("手机格式不正确")
|
||||
}
|
||||
pass, err := handle.NewCaptcha().Validate(&handle.CaptchaSms{
|
||||
Mobile: mobile,
|
||||
Captcha: captcha,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !pass {
|
||||
return nil, errors.New("手机号或验证码错误")
|
||||
}
|
||||
return &CaptchaCallback{
|
||||
Token: utils.JWTEncrypt(tokenEffectTime, map[string]interface{}{
|
||||
"mobile": mobile,
|
||||
}),
|
||||
EffectTime: tokenEffectTime,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewSms() SmsHandle {
|
||||
return func() *Sms {
|
||||
return &Sms{}
|
||||
|
Reference in New Issue
Block a user