-
Notifications
You must be signed in to change notification settings - Fork 0
/
SmsNotify.go
53 lines (45 loc) · 1.1 KB
/
SmsNotify.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 Common
import (
"fmt"
"net/url"
// "Common/logger"
)
var (
SMS_UUID = "80341" // uid
SMS_AUTH = GetMd5String("alxx" + "alxx88") // md5(code + pwd)
)
//func init() {
// sms := &SmsNotify{}
// // sms.SetPhone("18621669012") //zoulifeng
// // sms.SetPhone("18158139355") //lili
// // sms.SetPhone("15221975446") //zhouxueshi
// logger.BackupNohup(sms)
//}
type SmsNotify struct {
phoneList []string
}
func (s *SmsNotify) SetPhone(phone string) {
s.phoneList = append(s.phoneList, phone)
}
func (s SmsNotify) Notify(info string) {
for _, phone := range s.phoneList {
SendSMS(phone, info)
}
}
func SendSMS(phone, info string) error {
v := url.Values{}
v.Set("uid", SMS_UUID)
v.Set("auth", SMS_AUTH)
v.Set("mobile", phone)
v.Set("expid", "0")
v.Set("encode", "utf-8")
v.Set("msg", info)
req := v.Encode()
resp, err := SendHttpReq([]byte(req), "http://sms.10690221.com:9011/hy/", Http_req_get, nil, GetHttpClient(30))
if err != nil {
fmt.Printf("SendSMS : ", err.Error())
return err
}
fmt.Printf("SendSMS : phone=%s, resp=%s\n", phone, string(resp))
return nil
}