python 钉钉发送通知接口

2020-06-23  本文已影响0人  路破格

token值从机器人webhook获取

#-*- coding=utf-8 -*-
#-*- encoding:utf-8 -*-

import json
import requests

def send_dingding_robot(
        body = "",
        token = ""):
    request_url = "https://oapi.dingtalk.com/robot/send?access_token=%s" % token
    # 纯文本格式
    datas = {
        "msgtype": "text",
        "text": {"content": body}
    }
    # markdown格式,支持html标签,如<font color=#17a2b8>test</font>
    #datas = {
    #    "msgtype": "markdown",
    #    "markdown": {
    #        "title": "钉钉机器人",
    #        "text": body
    #    }
    #}
    http_headers = {"Content-Type": "application/json"}
    request_datas = json.dumps(datas)
    req = requests.post(
        url = request_url,
        data = request_datas,
        headers = http_headers,
        timeout = 10
    )
    req.close()
上一篇下一篇

猜你喜欢

热点阅读