1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- """
- @desc 钉钉报警
- @auth ck
- 手机号是str,用","分隔,如果不填,默认@所有人
- """
- import requests
- import random
- url = "https://oapi.dingtalk.com/robot/send?access_token=ca2fe03f4c4932f4017c2a7724a6beee94072313cd3325667576856f79156382"
- headers = {'Content-Type': 'application/json;charset=utf-8'}
- members = ["17752557125", "15902760898", "17757147568", "18860455786"]
- class DingTalkUtils:
- """
- @phone Str
- 可多个,按英文逗号隔开
- 可填 【ramdom】 随机发送
- """
- def send(msg, phone=""):
- if phone == "all":
- 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}}
- requests.post(url=url, headers=headers, json=data)
- if __name__ == '__main__':
- DingTalkUtils.send("xxx","188604557876,11232")
|