
第一步:先需要知道 python怎么调用钉钉机器人
class dingHook(object):
#钉钉发送markdown方法
def markdown(self,project,text,text1):
self.url ="https://oapi.dingtalk.com/robot/send?access_token=
此处是我的机器人Webhook 地址请替换"data={
"msgtype":"markdown",
"markdown": {
"title":"小白",
"text":f'### **{project}**\n'+
f"> {text}\n\n" +
#"> \n"+
f"> ##### {text1} \n"
#"> ###### 具体可查看邮件[链接](C:/Users/lenovo/Desktop/12.html) \n"
},
"at": {
"atMobiles": [
"1860176xxxx",
""
],
"isAtAll":False
}
}
data = json.dumps(data).encode(encoding='UTF8')
head = {"Content-Type":"application/json"}
response = requests.post(self.url,data=data,headers=head)
#调用钉钉返回结果转json格式
res_code = json.loads(response.text)
#print(res_code['errcode'])
if res_code['errcode'] ==0:
print('钉钉消息推送成功!')
# Logger().write(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+' ' +"钉钉消息推送成功\n")
else:
print('钉钉消息推送失败!')
#Logger().write(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) +"钉钉消息推送失败\n")
上面的Webhook地址获取方法



钉钉官方机器人支持好几种调用方法markdown只是其中一种,感兴趣的童鞋可以去官网自取。
网友评论