# -*- coding: utf-8 -*-
import requests
def send_weixin(content, url: str, mentionedList: list, notifyAll: bool = False):
if notifyAll:
mentionedList.append("@all")
headers = {"Content-Type": "application/json"} # http数据头,类型为json
data = {
"msgtype": "text",
"text": {
"content": content, # 让群机器人发送的消息内容。
"mentioned_list": mentionedList,
}
}
r = requests.post(url, headers=headers, json=data) # 利用requests库发送post请求
return r
def send_weixin_md(content, url: str):
"""
content示例
send_weixin("实时新增用户反馈<font color=\"warning\">132例</font>,请相关同事注意。\n
>类型:<font color=\"comment\">用户反馈</font>
>普通用户反馈:<font color=\"comment\">117例</font>
>VIP用户反馈:<font color=\"comment\">15例</font>")
<@zhikangdeng>,<@rosinzhang>
"""
url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=你的webhook密钥" # 这里就是群机器人的Webhook地址
headers = {"Content-Type": "application/json"} # http数据头,类型为json
data = {
"msgtype": "markdown",
"markdown": {
"content": content,
}
}
r = requests.post(url, headers=headers, json=data) # 利用requests库发送post请求
return r
def send_weixin_images(title, description, url: str, jumpLinkUrl, picurl):
"""
:param title:标题,不超过128个字节,超过会自动截断
:param description:描述,不超过512个字节,超过会自动截断
:param url:群机器人的Webhook地址
:param jumpLinkUrl:点击后跳转的链接。
:param picurl:图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图 1068*455,小图150*150。
:return:返回结果
"""
url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=你的webhook密钥" #
headers = {"Content-Type": "application/json"} # http数据头,类型为json
data = {
"msgtype": "news",
"news": {
"articles": [
{
"title": title,
"description": description,
"url": jumpLinkUrl,
"picurl": picurl
}
]
}
}
r = requests.post(url, headers=headers, json=data) # 利用requests库发送post请求
return r
企微机器人通知脚本
最新推荐文章于 2024-08-15 14:07:26 发布