使用钉钉机器人做一个监控
生成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)
结果
你要是觉得写的还不错,就点个关注,可以评论区留下足迹,以后方便查看.
你要是觉得写的很辣鸡,评论区欢迎来对线!
欢迎转载!