feat: add wehchat template message push
This commit is contained in:
@@ -28,6 +28,7 @@ type SendMessageService struct {
|
||||
Title string
|
||||
Text string
|
||||
HTML string
|
||||
URL string
|
||||
MarkDown string
|
||||
CallerIp string
|
||||
|
||||
@@ -184,6 +185,15 @@ func (sm *SendMessageService) Send(task models.TaskIns) (string, error) {
|
||||
sm.LogsAndStatusMark(sm.TransError(errMsg), errStrIsSuccess(errMsg))
|
||||
continue
|
||||
}
|
||||
// 微信公众号模板消息的实例发送
|
||||
wca, ok := msgObj.(send_way_service.WeChatOFAccount)
|
||||
if ok {
|
||||
cs := WeChatOfAccountService{}
|
||||
res, errMsg := cs.SendWeChatOfAccountMessage(wca, ins.SendTasksIns, typeC, sm.Title, content, sm.URL)
|
||||
sm.LogsAndStatusMark(fmt.Sprintf("返回内容:%s", res), sm.Status)
|
||||
sm.LogsAndStatusMark(sm.TransError(errMsg), errStrIsSuccess(errMsg))
|
||||
continue
|
||||
}
|
||||
sm.LogsAndStatusMark(fmt.Sprintf("发送失败:未知渠道的发信实例: %s\n", ins.ID), SendFail)
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
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 WeChatOfAccountService struct {
|
||||
}
|
||||
|
||||
// SendWeChatOfAccountMessage 执行发送微信公众号模板消息
|
||||
func (s *WeChatOfAccountService) SendWeChatOfAccountMessage(auth send_way_service.WeChatOFAccount, ins models.SendTasksIns, typeC string, title string, content string, url string) (string, string) {
|
||||
insService := send_ins_service.SendTaskInsService{}
|
||||
errStr, c := insService.ValidateDiffIns(ins)
|
||||
if errStr != "" {
|
||||
return errStr, ""
|
||||
}
|
||||
config, ok := c.(models.InsWeChatAccountConfig)
|
||||
if !ok {
|
||||
return "微信公众号模板消息config校验失败", ""
|
||||
}
|
||||
var (
|
||||
err error
|
||||
res string
|
||||
errMsg string
|
||||
)
|
||||
cli := message.WeChatOFAccount{
|
||||
AppID: auth.AppID,
|
||||
AppSecret: auth.APPSecret,
|
||||
TemplateID: auth.TempID,
|
||||
ToUser: config.ToAccount,
|
||||
URL: url,
|
||||
}
|
||||
res, err = cli.Send(title, content)
|
||||
if err != nil {
|
||||
errMsg = fmt.Sprintf("发送失败:%s", ins.ContentType)
|
||||
}
|
||||
return res, errMsg
|
||||
}
|
||||
Reference in New Issue
Block a user