开启左侧

企微机器人告诉脚本

[复制链接]
在线会员 mwQIzsAK2 发表于 2025-2-6 20:56:06 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
  1. # -*- coding: utf-8 -*-
  2. import requests
  3. def send_weixin(content, url: str, mentionedList: list, notifyAll: bool = False):
  4.     if notifyAll:
  5.         mentionedList.append("@all")
  6.     headers = {"Content-Type": "application/json"}  # http数据头,范例为json
  7.     data = {
  8.         "msgtype": "text",
  9.         "text": {
  10.             "content": content,  # 让群机械人收收的消息实质。
  11.             "mentioned_list": mentionedList,
  12.         }
  13.     }
  14.     r = requests.post(url, headers=headers, json=data)  #使用 requests库收收post恳求
  15.     return r
  16. def send_weixin_md(content, url: str):
  17.     """
  18.         content示例
  19.         send_weixin("及时新删用户反应<font color="warning">132例</font>,请相干共事留神。\n
  20.              >范例:<font color="co妹妹ent">用户反应</font>
  21.              >一般用户反应:<font color="co妹妹ent">117例</font>
  22.              >VIP用户反应:<font color="co妹妹ent">15例</font>")
  23.              <@zhikangdeng>,<@rosinzhang>
  24.     """
  25.     url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=您的webhook稀钥"  # 那里即是群机械人的Webhook地点
  26.     headers = {"Content-Type": "application/json"}  # http数据头,范例为json
  27.     data = {
  28.         "msgtype": "markdown",
  29.         "markdown": {
  30.             "content": content,
  31.         }
  32.     }
  33.     r = requests.post(url, headers=headers, json=data)  #使用 requests库收收post恳求
  34.     return r
  35. def send_weixin_images(title, description, url: str, jumpLinkUrl, picurl):
  36.     """
  37.     :param title:题目,没有超越128个字节,超越会主动截断
  38.     :param description:描绘,没有超越512个字节,超越会主动截断
  39.     :param url:群机械人的Webhook地点
  40.     :param jumpLinkUrl:面打后跳转的链交。
  41.     :param picurl:图文消息的图片链交,撑持JPG、PNG格局,较佳的结果为年夜图 1068*455,小图150*150。
  42.     :return:前去成果
  43.     """
  44.     url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=您的webhook稀钥"  #
  45.     headers = {"Content-Type": "application/json"}  # http数据头,范例为json
  46.     data = {
  47.         "msgtype": "news",
  48.         "news": {
  49.             "articles": [
  50.                 {
  51.                     "title": title,
  52.                     "description": description,
  53.                     "url": jumpLinkUrl,
  54.                     "picurl": picurl
  55.                 }
  56.             ]
  57.         }
  58.     }
  59.     r = requests.post(url, headers=headers, json=data)  #使用 requests库收收post恳求
  60.     return r
复造代码
您需要登录后才可以回帖 登录 | 立即注册 qq_login

本版积分规则

发布主题
阅读排行更多+
用专业创造成效
400-778-7781
周一至周五 9:00-18:00
意见反馈:server@mailiao.group
紧急联系:181-67184787
ftqrcode

扫一扫关注我们

Powered by 职贝云数A新零售门户 X3.5© 2004-2025 职贝云数 Inc.( 蜀ICP备2024104722号 )