美文网首页
python消息上报钉钉群

python消息上报钉钉群

作者: 不能没有音乐 | 来源:发表于2020-12-06 18:28 被阅读0次
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}

相关文章

网友评论

      本文标题:python消息上报钉钉群

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