find-object-bundle-builder/FindVerticalBundleBuilder/Tools/ipm/wechat_alert.py

33 lines
1.0 KiB
Python

#!/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=25b70526-e844-46a2-a8e6-3ce69827ba9b" 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")