diff --git a/cmd/main.go b/cmd/main.go index 9ad3059..d8bab49 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -26,7 +26,7 @@ _/ ____\______ ____ _____ _____ ____ __ _ _______ ____ ____ \/ \/ \/ \//_____/ `) fmt.Println("-----------------------------------------------------------------------------------------") fmt.Println("-----------------------------------------------------------------------------------------") - flag.BoolVar(&liveMode, "livemode", false, "即时模式关闭") + flag.BoolVar(&liveMode, "livemode", true, "即时模式默认关闭") flag.Parse() if !liveMode { fmt.Println("目前是定时任务模式") diff --git a/qywechat/send.go b/qywechat/send.go index 1ea796b..4cf3d67 100644 --- a/qywechat/send.go +++ b/qywechat/send.go @@ -1,9 +1,12 @@ package qywechat import ( - "bytes" + "encoding/json" + "fmt" + "io" "log" "net/http" + "strings" ) //企业微信机器人发送 @@ -12,22 +15,33 @@ const webhookURL = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=7b50e0c func Send(repContent string) { // 替换为你的企业微信机器人Webhook URL - + jsonData, err := json.Marshal(repContent) + if err != nil { + fmt.Println("转换为JSON时出错:", err) + return + } + repContent = string(jsonData) + // 去掉最后三个字符和第一个引号 + repContent = repContent[:len(repContent)-3] + repContent = repContent[1:] + fmt.Println(repContent) // 创建消息体 - requestBody := []byte(`{ - "msgtype": "text", - "text": { - "content": "` + repContent + `" - } - }`) + repContent = fmt.Sprintf(`{"msgtype": "text", "text": {"content": "%s"}}`, repContent) + //repContent = strings.Replace(repContent, "\\", "", 9) + //lastIndex := strings.LastIndex(repContent, "\\") + //if lastIndex != -1 { + // repContent = repContent[:lastIndex] + repContent[lastIndex+1:] + //} // 发送HTTP POST请求到企业微信机器人Webhook - resp, err := http.Post(webhookURL, "application/json", bytes.NewBuffer(requestBody)) + fmt.Println(repContent) + resp, err := http.Post(webhookURL, "application/json", strings.NewReader(repContent)) if err != nil { log.Fatalf("发送企业微信机器人失败,错误是: %v", err) } defer resp.Body.Close() - + body, _ := io.ReadAll(resp.Body) + fmt.Println(resp.StatusCode, string(body)) log.Println("发送企业微信机器人成功") } diff --git a/周报.xlsx b/周报.xlsx index 74bdf66..704d01d 100644 Binary files a/周报.xlsx and b/周报.xlsx differ