# 脚本名称:钉钉机器人消息推送
# 应用场景:任务通知、定时推送、监控告警、交互查询
# 官方文档参考:https://open.dingtalk.com/document/group/custom-robot-access


import request
import json


def ding_talk(access_token, title, markdown):
    headers = {'Content-Type': 'application/json'}
    data = {
          "msgtype": "markdown",
          "markdown": {
             "title": title,
             "text": markdown,
          },
          "at": {
              "isAtAll": False
          }
    }

    # 发送请求
    response = request.post('http://oapi.dingtalk.com/robot/send?access_token=' + access_token,
                            headers=headers, data=json.dumps(data))

    return json.loads(response.text)


if __name__ == '__main__':
    # 钉群机器人token
    access_token = "xxxxxxxxxxxxxxxxxxxxxxxxx"
    markdown = "### TEST"
    ding_talk(access_token, title="test", markdown=markdown)




↙↙↙阅读原文可查看相关链接,并与作者交流