/
sms.go
48 lines (37 loc) · 949 Bytes
/
sms.go
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
import (
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
type Sms interface {
// 短信接口名称
Name() string
Send(msg *Message) (*SmsResult, error)
}
type Message struct {
SourceId string `json:"sourceId"` // 短信的源Id, 用于追踪
Phone string `json:"phone"` // 接收短信的电话
Content string `json:"content"` // 内容
Signature string `json:"signature"` // 短信签名
}
// 短信发送接口
type SmsResult struct {
MessageId string `json:"messageId"` // 短信平台商返回的消息Id
Message string `json:"message"`
Success bool `json:"success"`
ResData string `json:"resData"` // 原始返回数据
}
func init() {
}
func New() Sms {
var sms Sms
provider := viper.GetString("sms.provider")
logrus.Info("当前使用短信网关: ", provider)
switch provider {
case "gangao":
sms = new(GangaoSms)
case "awssns":
sms = new(AwsSms)
}
return sms
}