package main import ( "encoding/json" "github.com/aarongao/tools" "github.com/aliyun/alibaba-cloud-sdk-go/services/dysmsapi" "github.com/davecgh/go-spew/spew" "time" ) var lastState = 0 func main() { for { time.Sleep(600 * time.Second) httpState, body, error := tools.GET("http://leyoutu.st-i.com.cn/api/v1.1/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) println("ERROR---------------------1:",rlen) spew.Dump(oBody) } else { sms(2) } } else { println("ERROR---------------------2:",httpState) spew.Dump(error) 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) } }