package util import ( "bytes" "encoding/json" "jygit.jydev.jianyu360.cn/BaseService/ossService/config" "log" "net/http" ) type WeixinMessage struct { MsgType string `json:"msgtype"` Text struct { Content string `json:"content"` } `json:"text"` } // SendWeixinNotification 发送企业微信机器人告警 func SendWeixinNotification(message string) error { webhookURL := config.AppConfig.Weixin.WebhookURL msg := WeixinMessage{MsgType: "text"} msg.Text.Content = message data, err := json.Marshal(msg) if err != nil { return err } resp, err := http.Post(webhookURL, "application/json", bytes.NewReader(data)) if err != nil { log.Println("SendWeixinNotification error", err) return err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return err } return nil }