#!/usr/bin/env python
# coding:utf-8
import json
import requests

class wechat_alert:
    def alert(self, message, at_people_list=[], hook_url=None):
        try:
            webhook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=08e26ad6-9b88-41ee-8864-bb84150c70d6" if hook_url == None else hook_url
            header = {
                "Content-Type": "application/json",
                "Charset": "UTF-8"
            }

            print(message)
            msg = {
                "msgtype": "text",
                "text": {
                    "content": message,
                    "mentioned_mobile_list": at_people_list,
                },
            }
            print(str(msg))
            message_json = json.dumps(msg)
            info = requests.post(url=webhook, data=message_json, headers=header)
            print(info.text)
        except Exception as e:
            print("alert failed!!! error message:" + repr(e))

# if __name__ == '__main__':
#     alert = wechat_alert()
#     alert.alert("test message")
