2022-07-21 23:08:34 +08:00
|
|
|
# wechat-bot
|
|
|
|
|
2022-07-21 23:10:41 +08:00
|
|
|
企业微信群机器人接口 Golang 封装
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"github.com/vimsucks/wxwork-bot-go"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
bot := wxworkbot.New("YOUR_BOT_KEY_HERE")
|
|
|
|
// or Markdown, Image, News
|
|
|
|
|
|
|
|
// 文本消息
|
|
|
|
text := wxworkbot.Text{
|
|
|
|
Content: "Hello World",
|
|
|
|
MentionedList: []string{"foo", "bar"},
|
|
|
|
MentionedMobileList: []string{"@all"},
|
|
|
|
}
|
|
|
|
err := bot.Send(text)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Markdown 消息
|
|
|
|
markdown := wxworkbot.Markdown{
|
|
|
|
Content: "# 测试",
|
|
|
|
}
|
|
|
|
err = bot.Send(markdown)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 图片消息
|
|
|
|
image := wxworkbot.Image{
|
|
|
|
Base64: "iVBORw0KGgoAAAANSUhEUgAAA3AAAANyCAIAAACsQL6LAAAMUGlDQ1BJQ0MgUHJvZmlsZQAASImVlwdcU1cXwO8bmSSsQARkhL1EGQIBZISwIgjIFEQlJIGEEWNCUHEjpQrWLaKgVrQqYtE6AKkT9yiK2zqKUlSUWhy4UPluBtTab/y+8/vd9/4599xzzzm57717AdCr4ctk+ag+AAXSQnlCZChrQlo6i9QJyMAc6ABj4MgXKGSc+PgYAGXw/nd5cwMgqvtVN5Wvf/b/VzEQihQCAJB4yFlChaAA8n4A8BKBTF4IAJEN9bbTC2UqzoBsJIcBQpapOEfDpSrO0nCV2iYpgQt5FwBkGp8vzwFAtxn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9Q902s20V2z5tl27v2JGw42Sdb13dTvOdy+rRemV9966MXZd/DPuxucGtYfNu5u6KPWCPcs/TnzJ/urE3em/rPva+hv32+2sOMA6UNyKNMxt7m8RNHc1pze0Hxx5sbQloOfDzyJ+3H7I+VH3Y+PCyI9QjpUcGjhYf7TsmO9ZzPOd4Z+uU1jsnJpy4dnL8ybZT0afOno44feIM58zRs4FnD53zP3fwPPt80wWfC40XvS8e+MX7lwNtPm2Nl3wvNV/2u9zSPqb9yJXgK8evhl09fY137cL12OvtN5Jv3LqZcbPjlvDWk9v5t1/8WvRr/535dwl3y+/p36u8b36/9jfn33Z3+HQcfhD24OLDxId3OgWdz35X/P6xq/QR/VHlY6vHdU88nxzqjui+/HTi065nsmf9PWV/GPxR89zp+f4/Q/682Duht+uF/MXAyyWvTF9tfz36dWtffN/9NwVv+t+WvzN9t+M9+/2ZD6kfHvdP/0j6WPXJ+VPL5+jPdw
|
|
|
|
MD5: "a5cd19abd4e9d558f5bd90ac5bc39221",
|
|
|
|
}
|
|
|
|
err = bot.Send(image)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 图文消息
|
|
|
|
news := wxworkbot.News{
|
|
|
|
Articles: []wxworkbot.NewsArticle{
|
|
|
|
{
|
|
|
|
Title: "测试1",
|
|
|
|
Description: "测试1",
|
|
|
|
URL: "https://baidu.com",
|
|
|
|
PicURL: "http://wx2.sinaimg.cn/large/006ARE9vgy1fzwp2mu4loj30c80c80td.jpg",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Title: "测试2",
|
|
|
|
Description: "测试2",
|
|
|
|
URL: "https://baidu.com",
|
|
|
|
PicURL: "http://wx2.sinaimg.cn/large/006ARE9vgy1fzwp2mu4loj30c80c80td.jpg",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
err = bot.Send(news)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|