安装Python第三方库:requests。
pip install requests
# -*- coding: utf-8 -*-
import requests
def push_report(web_hook,content):
header = {
"Content-Type": "application/json;charset=UTF-8"
}
message_body = {
"msg_type": "text",
"content": {
"text": content
}
}
ChatRob = requests.post(url=web_hook, json=message_body, headers=header)
opener = ChatRob.json()
if opener["StatusMessage"] == "success":
print(u"%s 通知消息发送成功!" % opener)
else:
print(u"通知消息发送失败,原因:{}".format(opener))
if __name__ == '__main__':
# webhook 来自于 获取机器人webhook:复制webhook 中的那个值
webhook = "https://open.feishu.cn/open-apis/bot/v2/hook/XXXXXX"
push_report(webhook,"content")