用Python的requests模块,来测试“钉钉机器人的Webhook是否生效”,能否自动发送钉钉群消息,并艾特@ 任意人

# -*- coding: utf-8 -*-
import requests
import json

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 # 如果你想@ 全部,改为True
            }
        }
        return requests.post(self.url, json.dumps(json_text), headers=self.__headers).content
class DingTalk_Disaster(DingTalk_Base):
    def __init__(self):
        super().__init__()
        self.url = '填写机器人的Webhook'
if __name__ == '__main__':
    ding = DingTalk_Disaster()
    ding.send_msg('这里是发送的内容') 
发布了94 篇原创文章 · 获赞 8 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/woshiyigerenlaide/article/details/104332331