From 631415f2e0476eed54d737b7c71acbbf4d73268f Mon Sep 17 00:00:00 2001 From: eryajf Date: Thu, 5 Oct 2023 16:20:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E6=97=B6=E7=A7=BB=E9=99=A4=E5=8D=95?= =?UTF-8?q?=E6=B5=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- message_test.go | 303 ------------------------------------------------ 1 file changed, 303 deletions(-) delete mode 100644 message_test.go diff --git a/message_test.go b/message_test.go deleted file mode 100644 index a96a5ca..0000000 --- a/message_test.go +++ /dev/null @@ -1,303 +0,0 @@ -package workwx - -import ( - "bufio" - "fmt" - "net/http" - "os" - "testing" -) - -var ( - wxclient *WorkwxApp - // 企业ID - corpID string = "xxxxxxx" - // 应用ID - agentID int64 = 007 - // 应用秘钥 - agentSecret string = "xxxxxxxxxx" - // 测试接收消息的用户ID - userID string = "userid" -) - -func init() { - var wx = New(corpID) - wxclient = wx.WithApp(agentSecret, agentID) - wxclient.SpawnAccessTokenRefresher() // 自动刷新token -} - -func TestSendTextMessage(t *testing.T) { - recipient := Recipient{ - UserIDs: []string{userID}, - PartyIDs: []string{}, - TagIDs: []string{}, - ChatID: "", - } - err := wxclient.SendTextMessage(&recipient, "这是一条普通文本消息", false) - if err != nil { - fmt.Printf("get err: %v\n", err) - } -} - -func TestSendMarkdownMessage(t *testing.T) { - recipient := Recipient{ - UserIDs: []string{userID}, - PartyIDs: []string{}, - TagIDs: []string{}, - ChatID: "", - } - _ = wxclient.SendMarkdownMessage(&recipient, "您的会议室已经预定,稍后会同步到`邮箱` \n>**事项详情** \n>事 项:开会 \n>组织者:@miglioguan \n>参与者:@miglioguan、@kunliu、@jamdeezhou、@kanexiong、@kisonwang \n> \n>会议室:广州TIT 1楼 301 \n>日 期:2018年5月18日 \n>时 间:上午9:00-11:00 \n> \n>请准时参加会议。 \n> \n>如需修改会议信息,请点击:[修改会议信息](https://work.weixin.qq.com)", false) -} - -func TestSendImageMessage(t *testing.T) { - recipient := Recipient{ - UserIDs: []string{userID}, - PartyIDs: []string{}, - TagIDs: []string{}, - ChatID: "", - } - url := "https://wwcdn.weixin.qq.com/node/wework/images/202201062104.366e5ee28e.png" - resp, err := http.Get(url) - if err != nil { - fmt.Println("HTTP GET请求失败:", err) - return - } - defer resp.Body.Close() - reader := resp.Body - - rst, err := wxclient.UploadTempImageMedia(&Media{ - filename: "test.jpg", - filesize: 0, - stream: reader, - }) - if err != nil { - fmt.Printf("upload temp image failed: %v\n", err) - } - _ = wxclient.SendImageMessage(&recipient, rst.MediaID, false) -} - -func TestSendFileMessage(t *testing.T) { - recipient := Recipient{ - UserIDs: []string{userID}, - PartyIDs: []string{}, - TagIDs: []string{}, - ChatID: "", - } - file, err := os.Open("go.mod") - if err != nil { - fmt.Println("Error opening file:", err) - return - } - defer file.Close() - - reader := bufio.NewReader(file) - - rst, err := wxclient.UploadTempFileMedia(&Media{ - filename: "go.mod", - filesize: 0, - stream: reader, - }) - if err != nil { - fmt.Printf("upload temp file failed: %v\n", err) - } - _ = wxclient.SendFileMessage(&recipient, rst.MediaID, false) -} - -func TestSendTextCardMessage(t *testing.T) { - recipient := Recipient{ - UserIDs: []string{userID}, - PartyIDs: []string{}, - TagIDs: []string{}, - ChatID: "", - } - _ = wxclient.SendTextCardMessage( - &recipient, "领奖通知", "
2016年9月26日
恭喜你抽中iPhone 7一台,领奖码:xxxx
请于2016年10月10日前联系行政同事领取
", "https://wiki.eryajf.net", "更多", false) -} - -func TestSendNewsMessage(t *testing.T) { - recipient := Recipient{ - UserIDs: []string{userID}, - PartyIDs: []string{}, - TagIDs: []string{}, - ChatID: "", - } - - msgObj := []Article{ - {Title: "中秋节礼品领取", - Description: "今年中秋节公司有豪礼相送", - URL: "https://wiki.eryajf.net", - PicURL: "http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png", - AppID: "", - PagePath: ""}, - {Title: "中秋节礼品领取2", - Description: "今年中秋节公司有豪礼相送2", - URL: "https://wiki.eryajf.net", - PicURL: "http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png", - AppID: "", - PagePath: ""}, - } - - _ = wxclient.SendNewsMessage(&recipient, msgObj, false) -} -func TestSendMPNewsMessage(t *testing.T) { - recipient := Recipient{ - UserIDs: []string{userID}, - PartyIDs: []string{}, - TagIDs: []string{}, - ChatID: "", - } - - url := "http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png" - resp, err := http.Get(url) - if err != nil { - fmt.Println("HTTP GET请求失败:", err) - return - } - defer resp.Body.Close() - reader := resp.Body - - rst, err := wxclient.UploadTempImageMedia(&Media{ - filename: "test.jpg", - filesize: 0, - stream: reader, - }) - if err != nil { - fmt.Printf("upload temp image failed: %v\n", err) - } - - msgObj := []MPArticle{ - {Title: "中秋节礼品领取", - ThumbMediaID: rst.MediaID, - Author: "eryajf", - ContentSourceURL: "https://wiki.eryajf.net", - Content: "这是正文里边的内容。", - Digest: "这里是图文消息的描述"}, - } - - _ = wxclient.SendMPNewsMessage(&recipient, msgObj, false) -} - -func TestSendTaskCardMessage(t *testing.T) { - recipient := Recipient{ - UserIDs: []string{userID}, - PartyIDs: []string{}, - TagIDs: []string{}, - ChatID: "", - } - btn := []TaskCardBtn{ - { - Key: "yes", - Name: "通过", - ReplaceName: "已通过", - Color: "blue", - IsBold: false, - }, { - Key: "no", - Name: "拒绝", - ReplaceName: "已拒绝", - Color: "red", - IsBold: false, - }} - _ = wxclient.SendTaskCardMessage(&recipient, "请审核该条信息", "这是说明信息", "https://wiki.eryajf.net", "aaadb", btn, false) -} - -func TestSendTemplateCardTextNoticeMessage(t *testing.T) { - recipient := Recipient{ - UserIDs: []string{userID}, - PartyIDs: []string{}, - TagIDs: []string{}, - ChatID: "", - } - msgObj := TemplateCard{ - CardType: CardTypeTextNotice, - Source: Source{ - IconURL: "https://wwcdn.weixin.qq.com/node/wework/images/202201062104.366e5ee28e.png", - Desc: "企业微信logo", - DescColor: 0, - }, - ActionMenu: ActionMenu{ - Desc: "卡片副交互辅助文本说明", - ActionList: []ActionList{ - {Text: "接受推送", Key: "A"}, - {Text: "不再推送", Key: "B"}, - }, - }, - // 确保唯一 - TaskID: "aaacddada", - MainTitle: MainTitle{ - Title: "欢迎使用企业微信", - Desc: "你的朋友也都在用。", - }, - QuoteArea: QuoteArea{ - Type: 0, - URL: "baidu.com", - Title: "百度", - QuoteText: "去往百度", - }, - EmphasisContent: EmphasisContent{ - Title: "100", - Desc: "核心数据", - }, - SubTitleText: "下载企业微信还能抢红包!", - CardAction: CardAction{ - Type: 1, - URL: "qq.com", - Appid: "aaaaaaa", - Pagepath: "/index.html", - }, - } - err := wxclient.SendTemplateCardMessage(&recipient, msgObj, false) - if err != nil { - fmt.Printf("get err: %v\n", err) - } -} - -func TestSendTemplateCardVoteInTeractionMessage(t *testing.T) { - recipient := Recipient{ - UserIDs: []string{userID}, - PartyIDs: []string{}, - TagIDs: []string{}, - ChatID: "", - } - msgObj := TemplateCard{ - CardType: CardTypeVoteInteraction, - Source: Source{ - IconURL: "https://wwcdn.weixin.qq.com/node/wework/images/202201062104.366e5ee28e.png", - Desc: "企业微信logo", - }, - // 确保唯一 - TaskID: "1", - MainTitle: MainTitle{ - Title: "欢迎使用企业微信", - Desc: "你的朋友也都在用。", - }, - CheckBox: CheckBox{ - QuestionKey: "qa1", - OptionList: []struct { - ID string `json:"id"` - Text string `json:"text"` - IsChecked bool `json:"is_checked"` - }{ - { - ID: "op1", - Text: "选项1", - IsChecked: false, - }, - { - ID: "op2", - Text: "选项2", - IsChecked: false, - }, - }, - Mode: 0, - }, - SubmitButton: SubmitButton{ - Text: "提交", - Key: "key", - }, - } - err := wxclient.SendTemplateCardMessage(&recipient, msgObj, false) - if err != nil { - fmt.Printf("get err: %v\n", err) - } -}