DingTalkUtils.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. """
  2. @desc 钉钉报警
  3. @auth ck
  4. 手机号是str,用","分隔,如果不填,默认@所有人
  5. """
  6. import requests
  7. import random
  8. url = "https://oapi.dingtalk.com/robot/send?access_token=ca2fe03f4c4932f4017c2a7724a6beee94072313cd3325667576856f79156382"
  9. headers = {'Content-Type': 'application/json;charset=utf-8'}
  10. members = ["17752557125", "15902760898", "17757147568", "18860455786"]
  11. class DingTalkUtils:
  12. """
  13. @phone Str
  14. 可多个,按英文逗号隔开
  15. 可填 【ramdom】 随机发送
  16. """
  17. def send(msg, phone=""):
  18. if phone == "all":
  19. isAtall = True
  20. atMobiles = []
  21. elif phone == "random":
  22. isAtall = False
  23. atMobiles = []
  24. atMobiles.append(random.choice(members))
  25. else:
  26. isAtall = False
  27. atMobiles =phone.split(",")
  28. data = {'msgtype': 'text',
  29. "at": {"isAtAll": isAtall,
  30. "atMobiles": atMobiles},
  31. "text": {"content": msg}}
  32. requests.post(url=url, headers=headers, json=data)
  33. if __name__ == '__main__':
  34. DingTalkUtils.send("xxx","188604557876,11232")