钉钉消息通知机器人python版

时间:2022-08-16 08:48:45

参考官方文档https://open-doc.dingtalk.com/microapp/serverapi2/qf2nxq

#coding=utf8
import requests
import json
url='https://oapi.dingtalk.com/robot/send?access_token=。。。'
# data=  {"actionCard": {
#         "title": "虚拟机数量监控",
#         "text": "没有虚拟机在运行哦",
#         "hideAvatar": "0",
#         "btnOrientation": "0",
#         "btns": [
#             {
#                 "title": "去关闭",
#                 "actionURL": "。。。"
#             }
#         ]
#     },
#     "msgtype": "actionCard"}
data={"msgtype": "text", 
        "text": {
             "content": "今日虚拟机数量:0,如需关闭请登录。。。"
        }
      }
header={'Content-Type': 'application/json'}
data=json.dumps(data,encoding='utf8')
res=requests.post(url,data=data,headers=header)
print res.text