DingTalkUtils.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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=ba21cd5591c44593ca7cac05902835e33298c7bf566a5381dc3f01e41c8d5c30"
  9. headers = {'Content-Type': 'application/json;charset=utf-8'}
  10. members = ["13726204048", "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("该下班了","13726204048,11")
  35. # 发送的内容得加上趣程