func weworkAlarm(text string, mentionAll bool) {
mentionAllStr := ""
if mentionAll {
mentionAllStr = "@all"
}
dataJsonStr := fmt.Sprintf(`{"msgtype": "text", "text": {"content": "%s", "mentioned_list": [%s]}}`, text, mentionAllStr)
fmt.Println(dataJsonStr)
resp, err := http.Post(
"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxx",
"application/json",
bytes.NewBuffer([]byte(dataJsonStr)))
if err != nil {
fmt.Println("weworkAlarm request error")
}
defer resp.Body.Close()
}
顺道演示了go http post json的用法