当前位置: 首页 > news >正文

【python_往企业微信群中发送文件】

python_往企业微信群中发送文件

这个是用企业微信群机器人的功能,没有用到后台应用。群机器人

#-*- coding:utf-8-*
import requests#类型:voice,file
file_type="file"
file_path="D:\desktop\不过.jpg"
webhookkey="xxxx"#1.上传临时素材
def get_media_id(path):url=f"https://qyapi.weixin.qq.com/cgi-bin/webhook/upload_media?key={webhookkey}&type={file_type}"data={file_type:open(path,"rb")}response = requests.post(url=url,files=data)print(response.json())return response.json()["media_id"]# get_media_id(file_path)#2.推送消息
def send_message():url=f"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key={webhookkey}"headers={"Content-Type":"application/x-www-form-urlencoded"}params={"msgtype": "file","file": {"media_id": get_media_id(file_path)}
}response = requests.post(url=url,headers=headers,json=params)print(response.json())return response.json()send_message()

效果:
在这里插入图片描述

http://www.lryc.cn/news/323811.html

相关文章:

  • 华为校招机试 - 循环依赖(20240320)
  • 基于Spring Boot技术的幼儿园管理系统
  • 查找众数及中位数 - 华为OD统一考试(C卷)
  • bash命令执行.sh文件 windows python环境
  • refreactive vue3
  • 【项目实践Day06】异步请求与同步请求+Ajax+微信小程序上实现发送异步请求
  • Elasticsearch面试系列-01
  • QT tableWidget横向纵向设置
  • Unity Mesh简化为Cube mesh
  • openGauss学习笔记-249 openGauss性能调优-使用Plan Hint进行调优-Join顺序的Hint
  • 大规模预训练语言模型的可解释性研究与实践
  • Rust常用库之序列化和反序列化库serde(使用 Serde 处理json)
  • java设计模式(2)---六大原则
  • 数学建模(层次分析法 python代码 案例)
  • Gitlab介绍
  • Amuse .NET application for stable diffusion
  • 【机器学习-05】模型的评估与选择
  • 【11】工程化
  • Python中requests、aiohttp、httpx性能对比
  • 网络原理(5)——IP协议(网络层)
  • GE IS200AEPAH1BKE IS215WEPAH2BB是两种不同的压力测量模块
  • Rust 与 C++ ,孰优孰劣?
  • MySQL、Oracle的时间类型字段自动更新:insert插入、update更新时,自动更新时间戳
  • Testng框架集成新业务
  • springboot 单元测试
  • LeetCode---126双周赛
  • [python] ETL 工作流程 Prefect
  • html第一次作业
  • 基于java实现的KTV点歌系统
  • GPT+向量数据库+Function calling=垂直领域小助手