python学习

Python学习九十六天:Python调用钉钉机器人推送消息

2019-05-30  本文已影响8人  暖A暖

1.创建钉钉机器人

2.推送消息

import requests
import json
class DingTalk_Base:
    def __init__(self):
        self.__headers = {'Content-Type': 'application/json;charset=utf-8'}
        self.url = ''
    def send_msg(self,text):
        json_text = {
            "msgtype": "text",
            "text": {
                "content": text
            },
            "at": {
                "atMobiles": [
                    ""
                ],
                "isAtAll": False
            }
        }
        return requests.post(self.url, json.dumps(json_text), headers=self.__headers).content
class DingTalk_Disaster(DingTalk_Base):
    def __init__(self):
        super().__init__()
        # 填写机器人的url
        self.url = ''
if __name__ == '__main__':
    ding = DingTalk_Disaster()
    ding.send_msg('')

参考:https://www.9xkd.com/user/plan-view.html?id=4213850024

上一篇下一篇

猜你喜欢

热点阅读