send_feishu_msg.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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()))
  43. @staticmethod
  44. def send_cookie_robot_msg(msg_content):
  45. try:
  46. url = 'https://open.feishu.cn/open-apis/bot/v2/hook/4c20b26f-6a58-4ebf-9754-80ab1b35387e'
  47. req_head = {"Content-Type": "application/json"}
  48. req_data = {
  49. "msg_type": "text",
  50. "content": {
  51. "text": msg_content
  52. }
  53. }
  54. data = json.dumps(req_data)
  55. logging.info("send_robot_msg req_url:{}, req_data:{}".format(url, data))
  56. response = requests.post(url=url, data=data, headers=req_head)
  57. result = response.json()
  58. logging.info("send_robot_msg response:{}".format(response.json()))
  59. if result.get("StatusCode") == 0:
  60. logging.info("飞书通知发送成功")
  61. return True
  62. else:
  63. logging.error("飞书通知发送失败,请检查!")
  64. return False
  65. except Exception as e:
  66. logging.error("send_robot_msg Error:{}".format(traceback.format_exc()))