38 lines
997 B
Go
38 lines
997 B
Go
package notifer
|
||
|
||
import (
|
||
"aiweek/option"
|
||
"encoding/json"
|
||
"fmt"
|
||
"io"
|
||
"log"
|
||
"net/http"
|
||
"strings"
|
||
)
|
||
|
||
func SendWechat(repContent string) {
|
||
// 替换为你的企业微信机器人Webhook URL
|
||
jsonData, err := json.Marshal(repContent)
|
||
if err != nil {
|
||
fmt.Println("转换为JSON时出错:", err)
|
||
return
|
||
}
|
||
repContent = string(jsonData)
|
||
// 创建消息体
|
||
repContent = fmt.Sprintf(`{"msgtype": "text", "text": {"content": %s}}`, repContent)
|
||
fmt.Println(repContent)
|
||
// 发送HTTP POST请求到企业微信机器人Webhook
|
||
resp, err := http.Post(option.WECHAT_WEBHOOK, "application/json", strings.NewReader(repContent))
|
||
if err != nil {
|
||
log.Printf("发送企业微信机器人失败,错误是: %v", err)
|
||
}
|
||
defer resp.Body.Close()
|
||
body, err := io.ReadAll(resp.Body)
|
||
if err != nil {
|
||
log.Printf("发送企业微信机器人失败,错误是: %v", err)
|
||
}
|
||
|
||
log.Printf("发送企业微信机器人完成,状态码为:%v,返回体为:%v", resp.StatusCode, string(body))
|
||
|
||
}
|