chore: update WeChat corp message channel
This commit is contained in:
@@ -73,6 +73,12 @@ type wechatCorpMessageRequest struct {
|
|||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
} `json:"textcard"`
|
} `json:"textcard"`
|
||||||
|
Text struct {
|
||||||
|
Content string `json:"content"`
|
||||||
|
} `json:"text"`
|
||||||
|
Markdown struct {
|
||||||
|
Content string `json:"content"`
|
||||||
|
} `json:"markdown"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type wechatCorpMessageResponse struct {
|
type wechatCorpMessageResponse struct {
|
||||||
@@ -84,16 +90,27 @@ func SendWeChatCorpMessage(message *Message, user *model.User) error {
|
|||||||
if user.WeChatCorpAccountId == "" {
|
if user.WeChatCorpAccountId == "" {
|
||||||
return errors.New("未配置微信企业号消息推送方式")
|
return errors.New("未配置微信企业号消息推送方式")
|
||||||
}
|
}
|
||||||
values := wechatCorpMessageRequest{
|
// https://developer.work.weixin.qq.com/document/path/90236
|
||||||
MessageType: "textcard",
|
messageRequest := wechatCorpMessageRequest{
|
||||||
ToUser: user.WeChatCorpAccountUserId,
|
ToUser: user.WeChatCorpAccountUserId,
|
||||||
AgentId: user.WeChatCorpAccountAgentId,
|
AgentId: user.WeChatCorpAccountAgentId,
|
||||||
}
|
}
|
||||||
values.TextCard.Title = message.Title
|
if message.Content == "" {
|
||||||
values.TextCard.Description = message.Description
|
messageRequest.MessageType = "text"
|
||||||
// TODO: render content and set URL
|
messageRequest.Text.Content = message.Description
|
||||||
values.TextCard.URL = common.ServerAddress
|
} else {
|
||||||
jsonData, err := json.Marshal(values)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ type User struct {
|
|||||||
WeChatCorpAccountSecret string `json:"wechat_corp_account_secret" gorm:"column:wechat_corp_account_secret"`
|
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"`
|
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"`
|
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"`
|
LarkWebhookURL string `json:"lark_webhook_url"`
|
||||||
LarkWebhookSecret string `json:"lark_webhook_secret"`
|
LarkWebhookSecret string `json:"lark_webhook_secret"`
|
||||||
DingWebhookURL string `json:"ding_webhook_url"`
|
DingWebhookURL string `json:"ding_webhook_url"`
|
||||||
|
|||||||
Reference in New Issue
Block a user