Ai
1 Star 1 Fork 0

Coder4/wxwork-group-robot

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
robot.go 1.39 KB
一键复制 编辑 原始数据 按行查看 历史
lihy 提交于 2021-07-29 19:22 +08:00 . FIX: pkg name
package wxgrobot
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
type MentionedOption struct {
userIdList []string
mobileList []string
}
func NewEmptyOption() *MentionedOption {
return &MentionedOption{[]string{}, []string{}}
}
func NewMentionAllOption() *MentionedOption {
return &MentionedOption{[]string{"@all"}, []string{}}
}
func NewMentionMobileOption(mobileList ...string) *MentionedOption {
return &MentionedOption{[]string{}, mobileList}
}
func SendTextMsg(key string, content string, mentionedOption *MentionedOption) bool {
return sendMsg(key, "text", content, mentionedOption)
}
func SendMarkdownMsg(key string, content string, mentionedOption *MentionedOption) bool {
return sendMsg(key, "markdown", content, mentionedOption)
}
func sendMsg(key string, typeStr string, content string, mentionedOption *MentionedOption) bool {
b1, _ := json.Marshal(mentionedOption.userIdList)
b2, _ := json.Marshal(mentionedOption.mobileList)
dataJsonStr := fmt.Sprintf(`{"msgtype": "%s", "%s": {"content": "%s", "mentioned_list": %s, "mentioned_mobile_list": %s}}`, typeStr, typeStr, content, string(b1), string(b2))
fmt.Println(dataJsonStr)
resp, err := http.Post(
fmt.Sprintf(`https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=%s`, key),
"application/json",
bytes.NewBuffer([]byte(dataJsonStr)))
if err != nil {
return false
} else {
defer resp.Body.Close()
return true
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/coder4/wxwork-group-robot.git
git@gitee.com:coder4/wxwork-group-robot.git
coder4
wxwork-group-robot
wxwork-group-robot
master

搜索帮助