美文网首页
python 钉钉发送通知接口

python 钉钉发送通知接口

作者: 路破格 | 来源:发表于2020-06-23 16:53 被阅读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()

相关文章

网友评论

      本文标题:python 钉钉发送通知接口

      本文链接:https://www.haomeiwen.com/subject/xvmhfktx.html