send_feishu_msg.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. """
  4. Author renyupeng
  5. coding=utf-8
  6. @Time : 2023/2/7 下午
  7. @Site :
  8. @File : send_feishu_msg.py
  9. @Software: PyCharm
  10. @contact: renyupeng@c-top.com.cn
  11. @Tel 1501435553
  12. encoding=utf-8
  13. """
  14. import logging
  15. import json
  16. import requests
  17. import traceback
  18. class SendFeiShuMsg:
  19. @staticmethod
  20. def send_robot_msg(msg_content):
  21. try:
  22. url = 'https://open.feishu.cn/open-apis/bot/v2/hook/7abdd37f-4a8e-4d6c-840e-ed78e892f019'
  23. req_head = {"Content-Type": "application/json"}
  24. req_data = {
  25. "msg_type": "text",
  26. "content": {
  27. "text": msg_content
  28. }
  29. }
  30. data = json.dumps(req_data)
  31. logging.info("send_robot_msg req_url:{}, req_data:{}".format(url, data))
  32. response = requests.post(url=url, data=data, headers=req_head)
  33. result = response.json()
  34. logging.info("send_robot_msg response:{}".format(response.json()))
  35. if result.get("StatusCode") == 0:
  36. logging.info("飞书通知发送成功")
  37. return True
  38. else:
  39. logging.error("飞书通知发送失败,请检查!")
  40. return False
  41. except Exception as e:
  42. logging.error("send_robot_msg Error:{}".format(traceback.format_exc()))