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

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()

效果:

相关推荐
岁月宁静3 分钟前
三、《从零手撸 Agent》 · system prompt 与核心参数:调好你的旋钮
后端·python·agent
吴声子夜歌5 分钟前
ApacheCommons——commons-lang3(Java 基础语言增强)(二)
java·开发语言·apache
卷无止境6 分钟前
除了写代码,AI智能体还能帮开发者做什么
人工智能·python
传奇开心果编程7 分钟前
【Rust入门知识点学与练】第1课变量与打印
开发语言·学习·rust
我不会起名字32211 分钟前
一天一道算法题(26):栈的简单应用
java·数据结构·python·算法·leetcode·golang·
爱吃苹果的梨叔15 分钟前
AI 算力监控中心怎么建?分布式坐席 + 大屏联动 + 过程回放
人工智能·分布式·python
JarmanYuo16 分钟前
YOLO 涨点研究(六):网络结构改进之小目标增强篇1——无人机视角下的车辆与行人检测
人工智能·pytorch·python·yolo·计算机视觉·无人机
2601_9622972521 分钟前
python自带缓存lru_cache用法及扩展的使用_python
python·缓存·装饰器·lru_cache·my_cache
招财小梗26 分钟前
沈阳AI企业咨询可定制数字化方案吗?
大数据·人工智能·python