123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- """
- @desc 钉钉报警
- @auth ck
- 手机号是str,用","分隔,如果不填,默认@所有人
- """
- import requests
- import random
- url = "https://oapi.dingtalk.com/robot/send?access_token=ba21cd5591c44593ca7cac05902835e33298c7bf566a5381dc3f01e41c8d5c30"
- headers = {'Content-Type': 'application/json;charset=utf-8'}
- members = ["13726204048", "18860455786"]
- class DingTalkUtils:
- """
- @phone Str
- 不填:默认@所有人
- 可多个,按英文逗号隔开
- 可填 【ramdom】 随机发送
- """
- def send(msg, phone=""):
- if phone == "":
- isAtall = True
- atMobiles = []
- elif phone == "random":
- isAtall = False
- atMobiles = []
- atMobiles.append(random.choice(members))
- else:
- isAtall = False
- atMobiles =phone.split(",")
- data = {'msgtype': 'text',
- "at": {"isAtAll": isAtall,
- "atMobiles": atMobiles},
- "text": {"content": msg+"\n[趣程]"}}
- requests.post(url=url, headers=headers, json=data)
- if __name__ == '__main__':
- DingTalkUtils.send("该下班了","13726204048,11")
- # 发送的内容得加上趣程
|