v-alarm/internal/dingTalk.go
2025-08-28 17:41:46 +08:00

37 lines
769 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package internal
import (
"encoding/json"
"fmt"
"net/http"
"strings"
"git.mmeiblog.cn/mei/v-alarm/configs"
)
func SendDingTalkNotification(message string) error {
msg := map[string]any{
"msgtype": "text",
"text": map[string]string{"content": message},
}
jsonBytes, err := json.Marshal(msg)
if err != nil {
return err
}
req, err := http.NewRequest("POST", configs.DingTalkURL, strings.NewReader(string(jsonBytes)))
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("钉钉API请求失败状态码: %d", resp.StatusCode)
}
return nil
}