class DingtalkMsg:
def __init__(self):
self.dingUrl = 'xxx上报的地址'
self.headers = {'Content-Type': 'application/json'}
self.msgtype = 'markdown'
self.typeDic = {'markdown': {'title': '默认标题', 'text': '默认内容'}}
def sendDingSuccess(self, title, text, at=''):
# 发送给钉钉机器人
data = {}
data['msgtype'] = self.msgtype
data[self.msgtype] = self.typeDic[self.msgtype]
if title:
data[self.msgtype]['title'] = title
if title:
data[self.msgtype]['text'] = text
if at:
atMobiles = [str(phone) for phone in at.split(',')]
data['at'] = {'atMobiles': atMobiles, 'isAtAll': 'false'}
s = json.dumps(data)
return {requests.post(self.dingUrl, data=s, headers=self.headers), s}
网友评论