ai-week/qywechat/send.go

34 lines
722 B
Go
Raw Normal View History

2024-05-01 11:24:18 +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 {
log.Fatalf("Failed to send message: %v", err)
}
defer resp.Body.Close()
log.Println("Message sent successfully!")
}