云服务器内容精选

  • 接收状态报告 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 package main import ( "fmt" "net/url" "strings" ) func main() { // 短信平台上报状态报告数据样例(urlencode) //success_body := "sequence=1&total=1&updateTime=2018-10-31T08%3A43%3A41Z&source=2&smsMsgId=2ea20735-f856-4376-afbf-570bd70a46ee_11840135&status=DELIVRD"; failed_body := "sequence=1&total=1&updateTime=2018-10-31T08%3A43%3A41Z&source=2&smsMsgId=2ea20735-f856-4376-afbf-570bd70a46ee_11840135&status=E200027"; //onSmsStatusReport(success_body); onSmsStatusReport(failed_body); } func onSmsStatusReport(data string) { ss, _ := url.QueryUnescape(data) params := strings.Split(ss, "&") keyValues := make(map[string]string) for i := range params { temp := strings.Split(params[i],"=") keyValues[temp[0]] = temp[1]; } status := keyValues["status"]; if status == "DELIVRD" { fmt.Println("Send sms success. smsMsgId: " + keyValues["smsMsgId"]) } else { fmt.Println("Send sms failed. smsMsgId: " + keyValues["smsMsgId"]) fmt.Println("Failed status: " + keyValues["status"]) } }
  • 接收上行短信 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 package main import ( "fmt" "net/url" "strings" ) func main() { upData := "from=%2B86151****6789&to=1069***2019&body=***********&smsMsgId=9692b5be-c427-4525-8e73-cf4a6ac5b3f7"; onSmsUpData(upData); } func onSmsUpData(data string) { ss, _ := url.QueryUnescape(data) params := strings.Split(ss, "&") keyValues := make(map[string]string) for i := range params { temp := strings.Split(params[i],"=") keyValues[temp[0]] = temp[1]; } body := keyValues["body"]; fmt.Println("Sms up data. Body: " + body) }