sms.go
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package v1
import (
"bytes"
"encoding/json"
"github.com/astaxie/beego/validation"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
sms "openapi/pkg/application/sms/service"
"openapi/pkg/constant"
protocol "openapi/pkg/domain"
"openapi/pkg/infrastructure/utils"
"openapi/pkg/port/beego/controllers"
)
type SmsController struct {
controllers.BaseController
}
//短信验证码 SmsCode
// @router /smsCode [post]
func (this *SmsController) SmsCode() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.SmsCodeRequest
decoder := json.NewDecoder(bytes.NewBuffer(this.ByteBody))
decoder.UseNumber()
if err := decoder.Decode(&request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if utils.IsProductEnv(constant.RunMode) {
valid := validation.Validation{}
if !valid.Mobile(request.Phone, "mobile").Ok {
msg = protocol.BadRequestParam(1001)
return
}
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(sms.SmsCode(header, request))
}
//检查短信验证码 CheckSmsCode
// @router /checkSmsCode [post]
func (this *SmsController) CheckSmsCode() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.CheckSmsCodeRequest
decoder := json.NewDecoder(bytes.NewBuffer(this.ByteBody))
decoder.UseNumber()
if err := decoder.Decode(&request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if utils.IsProductEnv(constant.RunMode) {
valid := validation.Validation{}
if !valid.Mobile(request.Phone, "mobile").Ok {
msg = protocol.BadRequestParam(1002)
return
}
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(sms.CheckSmsCode(header, request))
}
//发送短信通知 sendSmsNotice
// @router /sendSmsNotice [post]
func (this *SmsController) SendSmsNotice() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.SendSmsNoticeRequest
decoder := json.NewDecoder(bytes.NewBuffer(this.ByteBody))
decoder.UseNumber()
if err := decoder.Decode(&request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if utils.IsProductEnv(constant.RunMode) {
valid := validation.Validation{}
if !valid.Mobile(request.Phone, "mobile").Ok {
msg = protocol.BadRequestParam(1002)
return
}
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(sms.SendSmsNotice(header, request))
}