-
Notifications
You must be signed in to change notification settings - Fork 0
/
sms.go
53 lines (42 loc) · 1.03 KB
/
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
49
50
51
52
53
package main
import (
"errors"
"net/url"
"strings"
"github.com/go-resty/resty/v2"
)
const APIBaseURL = "https://oms.every8d.com/API21/HTTP/sendSMS.ashx"
type SMSClient struct {
username string
password string
notifyNumbers []string
client *resty.Client
}
func NewSMSClient(username, password string, notifyNumbers []string) *SMSClient {
c := resty.New()
return &SMSClient{
username: username,
password: password,
notifyNumbers: notifyNumbers,
client: c,
}
}
func (c *SMSClient) Send(msg string) error {
params := url.Values{}
params.Set("UID", c.username)
params.Set("PWD", c.password)
params.Set("SB", "")
params.Set("MSG", msg)
params.Set("DEST", strings.Join(c.notifyNumbers, ","))
params.Set("ST", "")
params.Set("RETRYTIME", "5")
res, err := c.client.R().SetQueryParamsFromValues(params).Get(APIBaseURL)
if err != nil {
return err
}
resFields := strings.Split(res.String(), ",")
if resFields[0] == "-99" {
return errors.New("send sms: unknown error")
}
return nil
}