feat:完善信息

This commit is contained in:
henry
2021-09-29 16:43:40 +08:00
parent c556053feb
commit 3d84af2e0c
6 changed files with 68 additions and 4 deletions

20
app/basic/api/sms.go Normal file
View File

@ -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)
}

View File

@ -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{}
}
}

View File

@ -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"

View File

@ -1,7 +1,7 @@
package api
import (
"SciencesServer/app/common/api"
"SciencesServer/app/basic/api"
"SciencesServer/app/enterprise/controller"
"github.com/gin-gonic/gin"
)

View File

@ -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 图形