以下代码仅定义文本类型的数据
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,data):
json_text = {
"msttype": "text",
"content": data
}
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 = 'https://xxx.xxx.com/gateway/robot/webhook/send?xxx=xxx'
if __name__ == '__main__':
ding = DingTalk_Disaster()
ding.send_msg("你好")