当前位置:网站首页>Golang接入钉钉通知
Golang接入钉钉通知
2022-06-09 11:45:00 【raoxiaoya】
设置与接入
1、创建一个钉钉群
2、打开群设置,智能群助手,添加机器人,自定义Webhook接入
3、设置机器人名字,开启消息推送,复制Webhook地址
4、安全设置,选择自定义关键词,最多可添加十个
发送消息
采用post方式向上面复制的地址发送请求即可
消息协议:https://open.dingtalk.com/document/robots/message-types-and-data-format
/* -- @Time : 2022/6/8 11:24 -- @Author : raoxiaoya -- @Desc : */
package dingtalk
import (
"encoding/json"
"errors"
"voteapi/pkg/curl"
)
type Response struct {
Errcode int
Errmsg string
}
const KeywordMonitor = "Monitor"
const MessageRobot = "https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxxxxxx"
// 发送简单文本消息
func SendDingTalkMessage(messageContent, messagePrefix string) (err error) {
defer func() {
if er := recover(); er != nil {
err = errors.New("SendDingTalkMessage panic")
}
}()
headers := map[string]string{
"Content-Type": "application/json",
}
text := map[string]string{
"content": messagePrefix + ": " + messageContent,
}
postData := map[string]interface{
}{
"msgtype": "text",
"text": text,
}
body, _ := json.Marshal(postData)
resp, err := curl.HttpRequest(MessageRobot, "POST", headers, string(body))
if err != nil {
return err
}
var re Response
_ = json.Unmarshal([]byte(resp), &re)
if re.Errcode > 0 {
return errors.New(resp)
}
return nil
}
调用
dingtalk.SendDingTalkMessage(fmt.Sprintf("service [%s] reboot success", v.Name), dingtalk.KeywordMonitor)
边栏推荐
- MySQL SQL语句优化
- 6. < tag backtracking and cutting problems > lt.131 Split palindrome string
- Preparation guide for the 2022 soft exam network engineer exam
- Zotero | Literature Association
- 6. exchange the nodes in the linked list in pairs
- Zotero | 文献关联
- 06 | the first step of China Taiwan landing: enterprise strategy decomposition and current situation research (Discovery)
- Excel | App_WorkbookActive中存在错误不能设置类 Addin 的Installed属性
- 【堆排|快排】Top-k问题
- 企评家用杜邦分析法剖析:华东建筑集团股份有限公司企业财务状况
猜你喜欢

06 | the first step of China Taiwan landing: enterprise strategy decomposition and current situation research (Discovery)

flutter Dio示例

Do you dare to deliver your microservices independently?

Error in Library (patroon): there is no program package named 'patroon'

Safari的Favorites项不显示在主页上

Origin 2022b | 更新及安装 | 中英文切换

5.<tag-回溯和切割问题>lt.93.复原IP地址

5. bracket generation

13. < tag binary tree and BST foundation > lt.450 Delete node DBC in binary search tree

接力AlphaFold!星药科技重磅发布TBind-开启分子蛋白复合物结构预测新纪元
随机推荐
炒作剽窃、内鬼欺诈 OpenSea上常见的NFT骗局及安全建议
curator - 创建客户端
虚拟机出现entering emergency mode,使用xfs_rapair出现Device or resource busy解决
Zotero | 文献关联
flutter Dio示例
Preparation guide for the 2022 soft exam network engineer exam
8.<tag-回溯和全排列>lt.46. 全排列 + lt.47. 全排列 II
LeetCode相机最小问题
匿名内部类与局部变量
Software project management
Redission 使用
8. < tag backtracking and full arrangement > lt.46 Full Permutation + lt.47 Full arrangement II
谢孟军:中国 Go 语言领军人创业第五年
IPO,联结一切的桥梁
期货开户云,开户可靠安全吗??
中国科学院院刊 | 包云岗:加速发展关键核心技术,必须把握技术发展的自身规律
go语言time.Format的坑
Calculate the result of a string formula
Error in Library (patroon): there is no program package named 'patroon'
Redis data structure and introduction