Monitor.go
1.29 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
package main
import (
"encoding/json"
"github.com/aarongao/tools"
"github.com/aliyun/alibaba-cloud-sdk-go/services/dysmsapi"
"time"
)
var lastState = 0
func main() {
for {
time.Sleep(180 * time.Second)
httpState, body, error := tools.GET("http://leyoutu.st-i.com.cn/AllScenic")
if httpState == 200 && error == nil {
oBody := tools.ResponseSeccess{}
json.Unmarshal([]byte(body), &oBody)
rlen := len(oBody.Result.([]interface{}))
if oBody.ErrCode != 0 || rlen == 0 {
sms(1)
} else {
sms(2)
}
} else {
sms(1)
}
}
}
func sms(state int) {
stateString := ""
if state == 1{
stateString = "Fail"
}
if state == 2{
stateString = "Success"
}
println("state:",stateString)
if lastState == 0 {
lastState = state
}
if lastState != state{
lastState = state
client, err := dysmsapi.NewClientWithAccessKey("cn-hangzhou", "LTAI4FdQeNMQXRU6u5J3EFQc", "PwvyF5rRNBWLDya41WrCpvENevYZGi")
request := dysmsapi.CreateSendSmsRequest()
request.Scheme = "https"
request.PhoneNumbers = "18616619599"
request.SignName = "乐游图"
request.TemplateCode = "SMS_182595013"
request.TemplateParam = "{\"code\":\"" + stateString +"\"}"
response, err := client.SendSms(request)
if err != nil {
println(err.Error())
}
println("SMS:", response.Code)
}
}