feat: add qyweixin message
This commit is contained in:
@@ -35,6 +35,10 @@ func (sw *SendTaskInsService) ValidateDiffIns(ins models.SendTasksIns) (string,
|
||||
var Config models.InsDtalkConfig
|
||||
return "", Config
|
||||
}
|
||||
if ins.WayType == "QyWeiXin" {
|
||||
var Config models.InsQyWeiXinConfig
|
||||
return "", Config
|
||||
}
|
||||
if ins.WayType == "Custom" {
|
||||
var Config models.InsCustomConfig
|
||||
err := json.Unmarshal([]byte(ins.Config), &Config)
|
||||
|
||||
@@ -139,6 +139,15 @@ func (sm *SendMessageService) Send() string {
|
||||
sm.LogsAndStatusMark(sm.TransError(errMsg), errStrIsSuccess(errMsg))
|
||||
continue
|
||||
}
|
||||
// 企业微信类型的实例发送
|
||||
qywxAuth, ok := msgObj.(send_way_service.WayDetailQyWeiXin)
|
||||
if ok {
|
||||
es := QyWeiXinService{}
|
||||
res, errMsg := es.SendQyWeiXinMessage(qywxAuth, ins.SendTasksIns, typeC, sm.Title, content)
|
||||
sm.LogsAndStatusMark(fmt.Sprintf("返回内容:%s", res), sm.Status)
|
||||
sm.LogsAndStatusMark(sm.TransError(errMsg), errStrIsSuccess(errMsg))
|
||||
continue
|
||||
}
|
||||
// 自定义webhook类型的实例发送
|
||||
customAuth, ok := msgObj.(send_way_service.WayDetailCustom)
|
||||
if ok {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package send_message_service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"message-nest/models"
|
||||
"message-nest/pkg/message"
|
||||
"message-nest/service/send_ins_service"
|
||||
"message-nest/service/send_way_service"
|
||||
)
|
||||
|
||||
type QyWeiXinService struct {
|
||||
}
|
||||
|
||||
// SendDtalkMessage 执行发送钉钉
|
||||
func (s *QyWeiXinService) SendQyWeiXinMessage(auth send_way_service.WayDetailQyWeiXin, ins models.SendTasksIns, typeC string, title string, content string) (string, string) {
|
||||
insService := send_ins_service.SendTaskInsService{}
|
||||
errStr, c := insService.ValidateDiffIns(ins)
|
||||
if errStr != "" {
|
||||
return errStr, ""
|
||||
}
|
||||
_, ok := c.(models.InsQyWeiXinConfig)
|
||||
if !ok {
|
||||
return "企业微信config校验失败", ""
|
||||
}
|
||||
|
||||
errMsg := ""
|
||||
var res []byte
|
||||
var err error
|
||||
cli := message.QyWeiXin{
|
||||
AccessToken: auth.AccessToken,
|
||||
}
|
||||
if typeC == "text" {
|
||||
res, err = cli.SendMessageText(content)
|
||||
if err != nil {
|
||||
errMsg = fmt.Sprintf("发送失败:%s", ins.ContentType)
|
||||
}
|
||||
} else if typeC == "markdown" {
|
||||
res, err = cli.SendMessageMarkdown(title, content)
|
||||
if err != nil {
|
||||
errMsg = fmt.Sprintf("发送失败:%s", ins.ContentType)
|
||||
}
|
||||
} else {
|
||||
errMsg = fmt.Sprintf("未知的企业微信发送内容类型:%s", ins.ContentType)
|
||||
}
|
||||
return string(res), errMsg
|
||||
}
|
||||
@@ -38,6 +38,11 @@ type WayDetailDTalk struct {
|
||||
Secret string `json:"secret" validate:"max=100" label:"钉钉加签秘钥"`
|
||||
}
|
||||
|
||||
// WayDetailQyWeiXin 企业微信渠道明细字段
|
||||
type WayDetailQyWeiXin struct {
|
||||
AccessToken string `json:"access_token" validate:"required,max=100" label:"企业微信access_token"`
|
||||
}
|
||||
|
||||
// WayDetailCustom 自定义渠道
|
||||
type WayDetailCustom struct {
|
||||
Webhook string `json:"webhook" validate:"required,max=200" label:"自定义的webhook地址"`
|
||||
@@ -108,6 +113,14 @@ func (sw *SendWay) ValidateDiffWay() (string, interface{}) {
|
||||
}
|
||||
_, Msg := app.CommonPlaygroundValid(dtalk)
|
||||
return Msg, dtalk
|
||||
} else if sw.Type == "QyWeiXin" {
|
||||
var config WayDetailQyWeiXin
|
||||
err := json.Unmarshal([]byte(sw.Auth), &config)
|
||||
if err != nil {
|
||||
return "企业微信auth反序列化失败!", empty
|
||||
}
|
||||
_, Msg := app.CommonPlaygroundValid(config)
|
||||
return Msg, config
|
||||
} else if sw.Type == "Custom" {
|
||||
var custom WayDetailCustom
|
||||
err := json.Unmarshal([]byte(sw.Auth), &custom)
|
||||
@@ -142,6 +155,17 @@ func (sw *SendWay) TestSendWay(msgObj interface{}) (string, string) {
|
||||
}
|
||||
return "", string(res)
|
||||
}
|
||||
qywxAuth, ok := msgObj.(WayDetailQyWeiXin)
|
||||
if ok {
|
||||
var cli = message.QyWeiXin{
|
||||
AccessToken: qywxAuth.AccessToken,
|
||||
}
|
||||
res, err := cli.SendMessageText(testMsg)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("发送失败:%s", err), string(res)
|
||||
}
|
||||
return "", string(res)
|
||||
}
|
||||
customAuth, ok := msgObj.(WayDetailCustom)
|
||||
if ok {
|
||||
var cli = message.CustomWebhook{}
|
||||
|
||||
Reference in New Issue
Block a user