分两步:
1.在钉钉群---智能群助手里添加机器人,拿到webhook链接,设置关键词。
2.写python代码,用requests请求接口的方式。参考代码和实现结果如下。
# python发钉钉消息
import json,requests
def sendDing(msg):
dingding_url = 'https://oapi.dingtalk.com/robot/send?access_token=xxxx'
data = {"msgtype": "text","text": {"content": "自动化测试结果:"+str(msg)}}
headers = {'Content-Type':'application/json;charset=UTF-8'}
send_data = json.dumps(data).encode('utf-8')
ret = requests.post(url=dingding_url,data=send_data,headers=headers)
print(ret.text)
sendDing("成功")