代码
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
const webhook_url = "https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
func dingToInfo(s string) bool {
content, data := make(map[string]string), make(map[string]interface{})
content["content"] = s
data["msgtype"] = "text"
data["text"] = content
b, _ := json.Marshal(data)
resp, err := http.Post(webhook_url,
"application/json",
bytes.NewBuffer(b))
if err != nil {
fmt.Println(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
return true
}
func main() {
dingToInfo("报警")
}
有疑问加站长微信联系(非本文作者)