diff --git a/channel/wechat-corp-account.go b/channel/wechat-corp-account.go index 40c90f0..29e4bf3 100644 --- a/channel/wechat-corp-account.go +++ b/channel/wechat-corp-account.go @@ -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 } diff --git a/model/user.go b/model/user.go index 273cfdc..5432ced 100644 --- a/model/user.go +++ b/model/user.go @@ -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"`