import requests import json def send_message(title, text, mobile): webhook_url = 'https://oapi.dingtalk.com/robot/send?access_token=b0eea0bbf097ce3badb4c832d2cd0267a50486f395ec8beca6e2042102bb295b' # 替换为实际的Webhook URL headers = {'Content-Type': 'application/json'} message = { 'msgtype': 'markdown', 'markdown': { 'title': title, 'text': text }, "at": { "atMobiles": mobile, "isAtAll": False } } try: response = requests.post(webhook_url, data=json.dumps(message), headers=headers) if response.status_code == 200: print('消息发送成功!', message) print('响应内容:', response.text) else: print('消息发送失败,状态码:', response.status_code) print('响应内容:', response.text) except requests.exceptions.RequestException as e: print('请求异常:', e) if __name__ == "__main__": send_message('测试标题', '这是测试内容', '13724387318')