feat:完善信息
This commit is contained in:
20
app/basic/api/sms.go
Normal file
20
app/basic/api/sms.go
Normal 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)
|
||||||
|
}
|
44
app/basic/controller/sms.go
Normal file
44
app/basic/controller/sms.go
Normal 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{}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"SciencesServer/app/common/api"
|
"SciencesServer/app/basic/api"
|
||||||
"SciencesServer/app/enterprise/controller/account"
|
"SciencesServer/app/enterprise/controller/account"
|
||||||
"SciencesServer/app/service"
|
"SciencesServer/app/service"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"SciencesServer/app/common/api"
|
"SciencesServer/app/basic/api"
|
||||||
"SciencesServer/app/enterprise/controller"
|
"SciencesServer/app/enterprise/controller"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
@ -28,7 +28,7 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
type SmsCallback func(content string) error
|
type SmsCallback func(mobile, code string) error
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// SmsCaptchaEffectiveTime 短信验证码有效时间
|
// SmsCaptchaEffectiveTime 短信验证码有效时间
|
||||||
@ -61,7 +61,7 @@ func (this *Captcha) Sms(length int, mobile string, callback SmsCallback) error
|
|||||||
}
|
}
|
||||||
// 发送短信
|
// 发送短信
|
||||||
//NewSms().Handle(mobile)
|
//NewSms().Handle(mobile)
|
||||||
return callback(mobile)
|
return callback(mobile, code)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Image 图形
|
// Image 图形
|
||||||
|
Reference in New Issue
Block a user