37 lines
769 B
Go
37 lines
769 B
Go
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
|
||
}
|