sms.go
853 字节
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
package sms
const (
SendSingle SendType = 1
SendList SendType = 2
SendSingleByTpl SendType = 10
)
const DefaultSmsCodeTimeOut int64 = 60 * 2
type (
SendType int
ISmsService interface {
Send(option *Options) error
}
Options struct {
Phone string
Content string
SendType SendType
TplId int
TplValues map[string]interface{}
}
option func(o *Options)
)
func NewOptions(options ...option) *Options {
o := &Options{}
for i := range options {
options[i](o)
}
return o
}
func WithPhone(phone string) option {
return func(o *Options) {
o.Phone = phone
}
}
func WithSendType(sendType SendType) option {
return func(o *Options) {
o.SendType = sendType
}
}
func WithTpl(tplId int, tplValues map[string]interface{}) option {
return func(o *Options) {
o.TplId = tplId
o.TplValues = tplValues
}
}