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

python企微发私信

import requests
import json

企业微信配置

CORP_ID = ‘ww9’ #企业号
CORP_SECRET = ‘Lc0XxbHS’ #管理企业–应用管理–程序号
AGENT_ID = ‘100003’ #管理企业–应用管理–程序号
TO_USER = ‘用户账号’ #管理企业–账号–想发的账号

获取access_token

def get_access_token():
url = f’https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={CORP_ID}&corpsecret={CORP_SECRET}’
resp = requests.get(url)
return resp.json().get(‘access_token’)

上传文件(临时素材,有效期为3天)

def upload_file(access_token, file_path):
url = f’https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token={access_token}&type=file’
files = {‘media’: open(file_path, ‘rb’)}
resp = requests.post(url, files=files)
return resp.json().get(‘media_id’)

发送文件消息

def send_file_message(access_token, media_id, to_user):
url = f’https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={access_token}’
data = {
“touser”: to_user,
“msgtype”: “file”,
“agentid”: AGENT_ID,
“file”: {
“media_id”: media_id
},
“safe”: 0
}
resp = requests.post(url, data=json.dumps(data, ensure_ascii=False).encode(‘utf-8’))
return resp.json()

主流程

if name == ‘main’:
token = get_access_token()
if not token:
print(“获取access_token失败”)
else:
media_id = upload_file(token, ‘C:\Users\Administrator\Downloads\111.xlsx’) # 替换为实际文件路径

    if media_id:result = send_file_message(token, media_id, TO_USER)print(result)else:print("文件上传失败")media_id2 = upload_file(token, 'C:\\Users\\Administrator\\Downloads\\222.xlsx')  # 替换为实际文件路径if media_id:result = send_file_message(token, media_id2, TO_USER)print(result)else:print("文件上传失败")media_id3 = upload_file(token, 'C:\\Users\\Administrator\\Downloads\\333.xlsx')  # 替换为实际文件路径if media_id:result = send_file_message(token, media_id3, TO_USER)print(result)else:print("文件上传失败")media_id4 = upload_file(token, 'C:\\Users\\Administrator\\Downloads\\444.xlsx')  # 替换为实际文件路径if media_id:result = send_file_message(token, media_id4, TO_USER)print(result)else:print("文件上传失败")

使用pyarmor对python项目进行licence加密

pip install pyarmor

pyarmor gen -e “2025-07-02T17:20:00” hello.py

目录多了个文件夹dist
pyarmor gen main.py --pack onefile -O dist01

http://www.xdnf.cn/news/18461.html

相关文章:

  • 【React ✨】从零搭建 React 项目:脚手架与工程化实战(2025 版)
  • 文字学的多维透视:从符号系统到文化实践
  • 2025年09月计算机二级MySQL选择题每日一练——第五期
  • Go语言实战案例-Redis连接与字符串操作
  • 井云智能体封装小程序:独立部署多开版 | 自定义LOGO/域名,打造专属AI智能体平台
  • IDEA控制台乱码(Tomcat)解决方法
  • IDEA相关的设置和技巧
  • 机器人 - 无人机基础(5) - 飞控中的传感器(ing)
  • CTFshow Pwn入门 - pwn 19
  • 《天龙八部》角色安全攻防全解析:从渗透测试视角看江湖成败
  • 【Golang】有关任务窃取调度器和抢占式调度器的笔记
  • STM32F1 USART介绍及应用
  • 开发指南134-路由传递参数
  • 支持蓝牙标签打印的固定资产管理系统源码(JAVA)
  • linux编程----网络通信(TCP)
  • LLM实践系列:利用LLM重构数据科学流程04 - 智能特征工程
  • 博士招生 | 英国谢菲尔德大学 招收计算机博士
  • 项目中优惠券计算逻辑全解析(处理高并发)
  • Unreal Engine UStaticMeshComponent
  • JUC之CompletionService
  • DFS序与树链剖分入门
  • 开发避坑指南(35):mybaits if标签test条件判断等号=解析异常解决方案
  • 文件系统层面的可用块数量可用空间和比例
  • AI重塑职业教育:个性化学习计划提效率、VR实操模拟强技能,对接就业新路径
  • 拿到手一个前端项目,应该如何启动
  • 开发避坑指南(34):mysql深度分页查询优化方案
  • Ubuntu解决makefile交叉编译的问题
  • Android Jetpack | Hilt
  • 机器人爆发、汽车换代,速腾聚创开始讲新故事
  • WindowsAPI|每天了解几个winAPI接口之网络配置相关文档Iphlpapi.h详细分析八