Skip to content

Commit

Permalink
Merge pull request #177 from eryajf/develop
Browse files Browse the repository at this point in the history
feat: ✨ 修复了news类型无法使用的问题,添加了message的测试,新增模板卡片消息
  • Loading branch information
xen0n authored Jan 3, 2024
2 parents a92c991 + 631415f commit 7aa1881
Show file tree
Hide file tree
Showing 3 changed files with 323 additions and 37 deletions.
30 changes: 19 additions & 11 deletions cmd/workwxctl/commands/cmd_send_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func cmdSendMessage(c *cli.Context) error {
url := c.String(flagURL)
picURL := c.String(flagPicURL)
buttonText := c.String(flagButtonText)
sourceContentURL := c.String(flagSourceContentURL)
// sourceContentURL := c.String(flagSourceContentURL)
digest := c.String(flagDigest)

app := cfg.MakeWorkwxApp()
Expand Down Expand Up @@ -73,21 +73,29 @@ func cmdSendMessage(c *cli.Context) error {
case "news":
err = app.SendNewsMessage(
&recipient,
title,
description,
url,
picURL,
[]workwx.Article{
workwx.Article{
Title: title,
Description: description,
URL: url,
PicURL: picURL,
AppID: "",
PagePath: "",
},
},
isSafe,
)
case "mpnews":
err = app.SendMPNewsMessage(
&recipient,
title,
thumbMediaID,
author,
sourceContentURL,
content,
digest,
[]workwx.MPArticle{workwx.MPArticle{
Title: title,
ThumbMediaID: thumbMediaID,
Author: author,
ContentSourceURL: content,
Content: content,
Digest: digest,
}},
isSafe,
)
default:
Expand Down
44 changes: 19 additions & 25 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,14 @@ func (c *WorkwxApp) SendTextCardMessage(
// 否则为单纯的【发送应用消息】接口调用。
func (c *WorkwxApp) SendNewsMessage(
recipient *Recipient,
title string,
description string,
url string,
picURL string,
articles []Article,
isSafe bool,
) error {
return c.sendMessage(
recipient,
"news",
map[string]interface{}{
"title": title,
"description": description, // TODO: 零值
"url": url,
"picurl": picURL, // TODO: 零值
"articles": articles,
}, isSafe,
)
}
Expand All @@ -146,29 +140,14 @@ func (c *WorkwxApp) SendNewsMessage(
// 否则为单纯的【发送应用消息】接口调用。
func (c *WorkwxApp) SendMPNewsMessage(
recipient *Recipient,
title string,
thumbMediaID string,
author string,
sourceContentURL string,
content string,
digest string,
mparticles []MPArticle,
isSafe bool,
) error {
return c.sendMessage(
recipient,
"mpnews",
map[string]interface{}{
// TODO: 支持发送多条图文
"articles": []interface{}{
map[string]interface{}{
"title": title,
"thumb_media_id": thumbMediaID,
"author": author, // TODO: 零值
"content_source_url": sourceContentURL, // TODO: 零值
"content": content,
"digest": digest,
},
},
"articles": mparticles,
}, isSafe,
)
}
Expand Down Expand Up @@ -210,6 +189,21 @@ func (c *WorkwxApp) SendTaskCardMessage(
)
}

// SendTemplateCardMessage 发送卡片模板消息
func (c *WorkwxApp) SendTemplateCardMessage(
recipient *Recipient,
templateCard TemplateCard,
isSafe bool,
) error {
return c.sendMessage(
recipient,
"template_card",
map[string]interface{}{
"template_card": templateCard,
}, isSafe,
)
}

// sendMessage 发送消息底层接口
//
// 收件人参数如果仅设置了 `ChatID` 字段,则为【发送消息到群聊会话】接口调用;
Expand Down
Loading

0 comments on commit 7aa1881

Please sign in to comment.