chore: update WeChat corp message channel

This commit is contained in:
JustSong
2022-11-22 10:16:12 +08:00
parent e47bebf16a
commit 8247192977
2 changed files with 27 additions and 9 deletions
+26 -9
View File
@@ -73,6 +73,12 @@ type wechatCorpMessageRequest struct {
Description string `json:"description"`
URL string `json:"url"`
} `json:"textcard"`
Text struct {
Content string `json:"content"`
} `json:"text"`
Markdown struct {
Content string `json:"content"`
} `json:"markdown"`
}
type wechatCorpMessageResponse struct {
@@ -84,16 +90,27 @@ func SendWeChatCorpMessage(message *Message, user *model.User) error {
if user.WeChatCorpAccountId == "" {
return errors.New("未配置微信企业号消息推送方式")
}
values := wechatCorpMessageRequest{
MessageType: "textcard",
ToUser: user.WeChatCorpAccountUserId,
AgentId: user.WeChatCorpAccountAgentId,
// https://developer.work.weixin.qq.com/document/path/90236
messageRequest := wechatCorpMessageRequest{
ToUser: user.WeChatCorpAccountUserId,
AgentId: user.WeChatCorpAccountAgentId,
}
values.TextCard.Title = message.Title
values.TextCard.Description = message.Description
// TODO: render content and set URL
values.TextCard.URL = common.ServerAddress
jsonData, err := json.Marshal(values)
if message.Content == "" {
messageRequest.MessageType = "text"
messageRequest.Text.Content = message.Description
} else {
if user.WeChatCorpAccountClientType == "plugin" {
messageRequest.MessageType = "textcard"
messageRequest.TextCard.Title = message.Title
messageRequest.TextCard.Description = message.Description
// TODO: render content and set URL
messageRequest.TextCard.URL = common.ServerAddress
} else {
messageRequest.MessageType = "markdown"
messageRequest.Markdown.Content = message.Content
}
}
jsonData, err := json.Marshal(messageRequest)
if err != nil {
return err
}
+1
View File
@@ -27,6 +27,7 @@ type User struct {
WeChatCorpAccountSecret string `json:"wechat_corp_account_secret" gorm:"column:wechat_corp_account_secret"`
WeChatCorpAccountAgentId string `json:"wechat_corp_account_agent_id" gorm:"column:wechat_corp_account_agent_id"`
WeChatCorpAccountUserId string `json:"wechat_corp_account_user_id" gorm:"column:wechat_corp_account_user_id"`
WeChatCorpAccountClientType string `json:"wechat_corp_account_client_type" gorm:"wechat_corp_account_client_type;default=plugin"`
LarkWebhookURL string `json:"lark_webhook_url"`
LarkWebhookSecret string `json:"lark_webhook_secret"`
DingWebhookURL string `json:"ding_webhook_url"`