python学习python3中调用钉钉机器人

2022-08-27 08:08:12

在钉钉群中配置好机器人,获取webhook链接,设置好关键词
官方配置文档:链接

代码如下,默认发送链接消息,可改为文字消息

def send_msg():
	url="webhook链接"
    headers={'Content-Type':'application/json;charset=utf-8'}# data_text = {# "msgtype": "text",# "text": {#     "content": "要发送的文字消息"# },#     "isAtAll": False  #此处为是否@所有人# }#发送链接消息
    data_link={"msgtype":"link","link":{"text":"任务通知-这是一条消息",#消息内容"title":"历史的车轮滚滚向前",#消息标题"picUrl":"https://i.loli.net/2021/09/26/JNTYrWKywd34Lqb.jpg",#图片链接"messageUrl":"https://developers.dingtalk.com/document/robots/custom-robot-access/title-zob-eyu-qse"#消息跳转链接}}# 发送文字消息# r = requests.post(url,data=json.dumps(data_text),headers=headers)# 发送链接消息
    r= requests.post(url,data=json.dumps(data_link),headers=headers)return r.text
  • 作者:小邑走天下
  • 原文链接:https://blog.csdn.net/weixin_42133116/article/details/120488522
    更新时间:2022-08-27 08:08:12