调用钉钉群的 webhook 发送群消息,也可以 @ 相关人员
自定义机器人接入——钉钉官方文档
https://open.dingtalk.com/document/robots/custom-robot-access
消息类型和数据格式——钉钉官方文档
这主要是发送消息的数据格式
https://open.dingtalk.com/document/robots/message-types-and-data-format
钉钉群创建机器人
钉钉群——右上角群设置——机器人——添加机器人——选择[自定义机器人]
这里建议选择【自定义关键词】 这样不需要加签,会稍微方便一点
这里需要保留好 Webhook, 我们主要就是使用这个来发送消息
自定义关键字 的作用就是如果你发送的内容里面包含这些关键字就可以发送钉钉群消息,反之则发送不了
代码部分
只需要调用这个方法就可以,复制直接就可以使用,其中:
webhook 就是创建钉钉机器人时复制的webhook
content 就是想要发送的内容
atPhones 就是想要@对象的手机号
func SendDingMsgNoSecret(webhook, content string, atPhones []string) error {
// 组合数据并传输
dingUrl := webhook
data := make(map[string]interface{
})
data["msgtype"] = "text"
data["text"] = map[string]string{
"content": content}
// 创建at部分的数据
atData := map[string]interface{
}{
"atMobiles": atPhones,
"isAtAll": false,
}