學習了Go語言后,打算利用最近比較空一點,寫一個前端部署工具,不需要每次都復制粘貼的麻煩,我們希望再部署開始之前和部署結束后推送釘釘消息
創建一個釘釘機器人
這個比較簡單
添加完后會給你一個webhook就是我們發送消息的地址
推送消息
show code!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
func SendDingMsg(msg string) { //請求地址模板 webHook := `https://oapi.dingtalk.com/robot/send?access_token=04c381fc31944ad2905f31733e31fa15570ae12efc857062dab16b605a369e4c` content := `{"msgtype": "text", "text": {"content": "`+ msg + `"} }` //創建一個請求 req, err := http.NewRequest("POST", webHook, strings.NewReader(content)) if err != nil { // handle error } client := &http.Client{} //設置請求頭 req.Header.Set("Content-Type", "application/json; charset=utf-8") //發送請求 resp, err := client.Do(req) //關閉請求 defer resp.Body.Close() if err != nil { // handle error } } |
發送成功!
到此這篇關于Go語言使用釘釘機器人推送消息的實現示例的文章就介紹到這了,更多相關Go 釘釘機器人推送消息內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文鏈接:https://blog.csdn.net/deng1456694385/article/details/89888971