123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import requests
- import platform
- # 企业微信联系人
- MOBILE_LIST = [
- "15639297172", # 张金坤
- ]
- if platform.system() not in ['Darwin', 'Windows']:
- PLATFORM_RUL = "http://pycaptcha.spdata.jianyu360.com"
- else:
- PLATFORM_RUL = "http://127.0.0.1:2119"
- def post_data(platform, limit, usage, msg, allow_reset=False):
- """
- :param platform:平台名称
- :param limit:限制次数
- :param usage:使用次数
- :param msg: 通知内容
- :param allow_reset: 解除限制
- :return:
- """
- label = "<font color=\"warning\">{}</font>".format(msg)
- platform = ">平台名称: <font color=\"comment\">{}</font>".format(platform)
- c0 = ">调用上限: <font color=\"comment\">{}次</font>".format(limit)
- c1 = ">调用次数: <font color=\"comment\">{}次</font>".format(usage)
- msg = "{}\n {}\n > {}\n > {}\n".format(label, platform, c0, c1)
- if allow_reset:
- c2 = f"[解除限制]({PLATFORM_RUL}/v1/images/reset)"
- msg = "{}[{}]\n > {}\n > {}\n {}".format(label, c2, platform, c0, c1)
- content = msg
- markdown = {"msgtype": "markdown", "markdown": {"content": content}}
- text = {
- "msgtype": "text",
- "text": {
- "content": " 请以下同事注意",
- "mentioned_mobile_list": MOBILE_LIST
- }
- }
- body = {'markdown': markdown, 'text': text}
- return body
- def robot_webhook(data):
- url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send"
- headers = {"Content-Type": "application/json"}
- params = {"key": "683a19fe-c72d-464f-acbe-489656f06b05"}
- response = requests.post(url, headers=headers, params=params, json=data)
- return response.json()
- def send_msg(platform, limit, usage, msg, **kwargs):
- contents = post_data(platform, limit, usage, msg, **kwargs)
- for _, content in contents.items():
- response = robot_webhook(content)
- print('企业微信机器人 >>> ', response)
|