- # -*- 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="co妹妹ent">用户反应</font>
- >一般用户反应:<font color="co妹妹ent">117例</font>
- >VIP用户反应:<font color="co妹妹ent">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
复造代码 |