使用釘釘機器人做一個監控
阿新 • • 發佈:2020-12-09
生成access token
-
點選頭像->機器人管理->自定義(通過webhook接入自定義服務)->新增->選擇一個安全配置
-
得到一個webhook地址,https://oapi.dingtalk.com/robot/send?access_token=xxx
傳送訊息
def send_message(text): send_url = 'https://oapi.dingtalk.com/robot/send?access_token=xxx' headers = { 'Content-Type': 'application/json', "Charset": "UTF-8" } data = { "msgtype": "markdown", "markdown": { "title": "python", "text": text }, "at": { # "atMobiles": [ # "18788888888" # ], "isAtAll": True } } resp = requests.post(url=send_url, headers=headers, json=data) print(resp.json()) if __name__ == '__main__': text = """ #### 深圳天氣 > 20度,西北風1級,空氣良89,相對溫度73% > ![screenshot](https://img95.699pic.com/photo/50055/5642.jpg_wh860.jpg) > ###### 10點21分發布 [天氣](https://www.baidu.com) """ send_message(text)