sendMessage.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Author renyupeng
  2. # coding=utf-8
  3. # @Time : 2021/11/3 4:00 下午
  4. # @Site :
  5. # @File : sendMessage.py
  6. # @Software: PyCharm
  7. # @contact: renyupeng@c-top.com.cn
  8. # @Tel 1501435553
  9. import json
  10. import logging
  11. import traceback
  12. import requests
  13. class feishuMsg:
  14. @classmethod
  15. def send_robot_msg(cls, msg_content):
  16. try:
  17. url = 'https://open.feishu.cn/open-apis/bot/v2/hook/c567fbee-be1f-4143-987e-19decdade0d2'
  18. headers = {
  19. 'Content-Type': 'application/json'
  20. }
  21. req_data = {
  22. "msg_type": "text",
  23. "content": {
  24. "text": str(msg_content)
  25. }
  26. }
  27. data = json.dumps(req_data)
  28. logging.info("send_robot_msg req_url:{}, req_data:{}".format(url, data))
  29. response = requests.post(url=url, data=data, headers=headers)
  30. result = response.json()
  31. print(result)
  32. logging.info("send_robot_msg response:{}".format(response.json()))
  33. if result.get("StatusCode") == 0:
  34. logging.info("钉钉通知发送成功")
  35. return True
  36. else:
  37. logging.error("钉钉通知发送失败,请检查!")
  38. return False
  39. except Exception as e:
  40. logging.error("send_robot_msg Error:{}".format(traceback.format_exc()))