2024-05-01 20:03:20 +08:00
|
|
|
package qywechat
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
//企业微信机器人发送
|
|
|
|
|
|
|
|
const webhookURL = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=7b50e0c4-8a35-4f29-b652-25e1d6142c2b"
|
|
|
|
|
|
|
|
func Send(repContent string) {
|
|
|
|
// 替换为你的企业微信机器人Webhook URL
|
|
|
|
|
|
|
|
// 创建消息体
|
|
|
|
requestBody := []byte(`{
|
|
|
|
"msgtype": "text",
|
|
|
|
"text": {
|
|
|
|
"content": "` + repContent + `"
|
|
|
|
}
|
|
|
|
}`)
|
|
|
|
|
|
|
|
// 发送HTTP POST请求到企业微信机器人Webhook
|
|
|
|
resp, err := http.Post(webhookURL, "application/json", bytes.NewBuffer(requestBody))
|
|
|
|
if err != nil {
|
2024-05-02 12:38:42 +08:00
|
|
|
log.Fatalf("发送企业微信机器人失败,错误是: %v", err)
|
2024-05-01 20:03:20 +08:00
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
2024-05-02 12:38:42 +08:00
|
|
|
log.Println("发送企业微信机器人成功")
|
2024-05-01 20:03:20 +08:00
|
|
|
|
|
|
|
}
|