xdd-plus/models/qywx.go
2021-08-15 09:48:05 +08:00

41 lines
751 B
Go

package models
import (
"time"
"github.com/beego/beego/v2/client/httplib"
)
type QywxConfig struct {
QywxKey string
Content string
}
type QywxNotifyMessage struct {
Msgtype string `json:"msgtype"`
Text struct {
Content string `json:"content"`
} `json:"text"`
}
func qywxNotify(c *QywxConfig) {
// if Config.TelegramBotToken == "" {
// }
if c.QywxKey == "" {
c.QywxKey = Config.QywxKey
}
if c.QywxKey == "" {
return
}
wx := QywxNotifyMessage{
Msgtype: "text",
}
wx.Text.Content = c.Content
req := httplib.Post("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=" + c.QywxKey)
req.Header("Content-Type", "application/json")
req, _ = req.JSONBody(wx)
req.SetTimeout(time.Second*2, time.Second*2)
req.Response()
}