目前钉钉支持群聊消息的通过接口发送,需要建立群聊:
1、创建群聊
2、群聊设置自定义机器人:
根据提示自定义设置,最后获取webhook地址
3、发送消息实现:
def sendDing(msg):
'''
发送钉钉消息功能
'''
dingding_url = 'https://oapi.dingtalk.com/robot/send?access_token=******'
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)