diff --git a/app/common/api/api.go b/app/basic/api/base.go similarity index 100% rename from app/common/api/api.go rename to app/basic/api/base.go diff --git a/app/basic/api/sms.go b/app/basic/api/sms.go new file mode 100644 index 0000000..c298e1b --- /dev/null +++ b/app/basic/api/sms.go @@ -0,0 +1,20 @@ +package api + +import ( + "SciencesServer/app/basic/controller" + "github.com/gin-gonic/gin" +) + +type Sms struct{} + +func (a *Sms) sCaptcha(c *gin.Context) { + form := &struct { + Mobile string `json:"mobile" form:"mobile" binding:"required"` + }{} + if err := Bind(form)(c); err != nil { + APIFailure(err.(error))(c) + return + } + err := controller.NewSms()().Captcha(form.Mobile) + APIResponse(err) +} diff --git a/app/basic/controller/sms.go b/app/basic/controller/sms.go new file mode 100644 index 0000000..428ef63 --- /dev/null +++ b/app/basic/controller/sms.go @@ -0,0 +1,44 @@ +package controller + +import ( + "SciencesServer/app/handle" + "SciencesServer/utils" + "errors" +) + +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, + //}) + // 执行保存数据库 + //mSysSmsLogs := model.NewSysSmsLogs() + //mSysSmsLogs.Mobile = mobile + //mSysSmsLogs.Content = content + //mSysSmsLogs.Usage = model2.SysSmsLogsUsageForCaptcha + // + //return model2.Create(mSysSmsLogs.SysSmsLogs) + return nil +} + +// Captcha 验证码事件 +func (c *Sms) Captcha(mobile string) error { + if !utils.ValidateMobile(mobile) { + return errors.New("手机格式不正确") + } + if err := handle.NewCaptcha().Sms(6, mobile, c.captchaCallback); err != nil { + return errors.New("操作错误") + } + return nil +} + +func NewSms() SmsHandle { + return func() *Sms { + return &Sms{} + } +} diff --git a/app/enterprise/api/account.go b/app/enterprise/api/account.go index f2ead78..a591405 100644 --- a/app/enterprise/api/account.go +++ b/app/enterprise/api/account.go @@ -1,7 +1,7 @@ package api import ( - "SciencesServer/app/common/api" + "SciencesServer/app/basic/api" "SciencesServer/app/enterprise/controller/account" "SciencesServer/app/service" "github.com/gin-gonic/gin" diff --git a/app/enterprise/api/config.go b/app/enterprise/api/config.go index 81a14f1..5f69eea 100644 --- a/app/enterprise/api/config.go +++ b/app/enterprise/api/config.go @@ -1,7 +1,7 @@ package api import ( - "SciencesServer/app/common/api" + "SciencesServer/app/basic/api" "SciencesServer/app/enterprise/controller" "github.com/gin-gonic/gin" ) diff --git a/app/handle/captcha.go b/app/handle/captcha.go index d090323..a87d6a7 100644 --- a/app/handle/captcha.go +++ b/app/handle/captcha.go @@ -28,7 +28,7 @@ type ( } ) -type SmsCallback func(content string) error +type SmsCallback func(mobile, code string) error const ( // SmsCaptchaEffectiveTime 短信验证码有效时间 @@ -61,7 +61,7 @@ func (this *Captcha) Sms(length int, mobile string, callback SmsCallback) error } // 发送短信 //NewSms().Handle(mobile) - return callback(mobile) + return callback(mobile, code) } // Image 图形