企业微信视频号去水印解析机器人搭建指南
介绍如何基于企业微信 API 和 Python Flask 框架搭建一个视频号去水印解析机器人。主要步骤包括注册企业微信应用并配置消息接收权限,部署云服务器环境(安装 Python、Nginx、SSL 证书),编写回调代码处理视频素材 ID 并调用解析接口获取无水印链接,最后通过 Nginx 反向代理启动服务。用户转发视频号给机器人即可自动回复下载链接。

介绍如何基于企业微信 API 和 Python Flask 框架搭建一个视频号去水印解析机器人。主要步骤包括注册企业微信应用并配置消息接收权限,部署云服务器环境(安装 Python、Nginx、SSL 证书),编写回调代码处理视频素材 ID 并调用解析接口获取无水印链接,最后通过 Nginx 反向代理启动服务。用户转发视频号给机器人即可自动回复下载链接。

用户将微信视频号视频转发给机器人 → 机器人自动提取视频号原始链接 → 解析无水印视频地址 → 回复给用户
http://你的服务器公网 IP/wechat/callbackubuntu@xxx:~$ 即为成功)。在终端中执行以下命令:
# 1. 更新系统软件(Ubuntu 系统)
sudo apt update && sudo apt upgrade -y
# 2. 安装 Python3、pip3
sudo apt install python3 python3-pip -y
# 3. 安装 Flask、requests、加密库
pip3 install flask requests pycryptodome gunicorn
# 4. 安装 Nginx
sudo apt install nginx -y
# 5. 安装 Certbot(申请免费 SSL 证书)
sudo apt install certbot python3-certbot-nginx -y
执行完后,输入 python3 --version,显示 Python 3.8.x 以上即为成功。
在终端执行以下命令(替换为你的服务器公网 IP):
sudo certbot --nginx -d 你的服务器公网 IP
提示'Successfully obtained certificate'即为申请成功。
mkdir -p /home/ubuntu/video_parse_bot
cd /home/ubuntu/video_parse_bot
nano video_bot.py
from flask import Flask, request, jsonify
import requests
from Crypto.Cipher import AES
import base64
import json
import time
# -------------------------- 替换为你的企业微信信息(必改!)--------------------------
CORP_ID = "你的企业ID" # 步骤 1.2 记录的企业 ID(wxXXXXXXX)
CORP_SECRET = "你的应用 Secret" # 步骤 1.2 记录的应用 Secret
AGENT_ID = "你的 AgentId" # 步骤 1.2 记录的 AgentId(数字,如 1000002)
TOKEN = "videoparse2025" # 步骤 1.3 自定义的 Token
ENCODING_AES_KEY = "你的 EncodingAESKey" # 步骤 1.3 生成的 EncodingAESKey
# -------------------------- 替换为你的解析接口(必改!)--------------------------
PARSE_API = "https://your-parser-api.com/parse" # 替换为你的解析接口
# ----------------------------------------------------------------------------------
app = Flask(__name__)
# 1. 缓存 access_token(2 小时过期,避免重复调用接口)
access_token_cache = {
"token": None,
"expire_time": 0
}
def get_access_token():
"""获取企业微信 access_token(接口调用凭证)"""
global access_token_cache
if access_token_cache["token"] and time.time() < access_token_cache["expire_time"]:
return access_token_cache["token"]
url = f"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={CORP_ID}&corpsecret={CORP_SECRET}"
try:
res = requests.get(url, timeout=)
res.raise_for_status()
data = res.json()
data.get() == :
access_token = data[]
access_token_cache[] = access_token
access_token_cache[] = time.time() +
access_token
:
()
Exception e:
()
():
:
aes_key = base64.b64decode(ENCODING_AES_KEY + )
cipher = AES.new(aes_key, AES.MODE_CBC, aes_key[:])
decrypt_data = cipher.decrypt(base64.b64decode(encrypt_msg))
msg_len = .from_bytes(decrypt_data[:], byteorder=)
real_msg = decrypt_data[:+msg_len].decode()
json.loads(real_msg)
Exception e:
()
():
access_token = get_access_token()
access_token:
url =
:
res = requests.get(url, timeout=)
res.raise_for_status()
data = res.json()
data.get():
()
data[]
:
()
Exception e:
()
():
original_url:
:
encoded_url = requests.utils.quote(original_url)
parse_url =
res = requests.get(parse_url, timeout=)
res.raise_for_status()
data = res.json()
data.get() == data.get(, {}).get():
data[][]
data.get() data.get():
data[]
:
()
Exception e:
()
():
access_token = get_access_token()
access_token:
url =
data = {
: user_id,
: (AGENT_ID),
: ,
: {: content},
: ,
: ,
:
}
:
res = requests.post(url, json=data, timeout=)
res.raise_for_status()
result = res.json()
result.get() == :
()
:
()
Exception e:
()
():
msg_signature = request.args.get()
timestamp = request.args.get()
nonce = request.args.get()
encrypt_msg = request.data.decode(, errors=)
real_msg = decrypt_msg(msg_signature, timestamp, nonce, encrypt_msg)
real_msg:
jsonify({: -, : })
()
real_msg.get() == real_msg.get():
user_id = real_msg.get()
video_id = real_msg[].get()
original_url = extract_weixin_video_url(video_id)
no_watermark_url = parse_video_no_watermark(original_url)
reply_content =
send_msg_to_user(user_id, reply_content)
:
user_id = real_msg.get()
send_msg_to_user(user_id, )
jsonify({: , : })
__name__ == :
app.run(host=, port=, debug=)
sudo nano /etc/nginx/sites-available/default
server {
listen 80;
listen [::]:80;
server_name 你的服务器公网 IP; # 替换为你的服务器 IP 或域名
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name 你的服务器公网 IP; # 替换为你的服务器 IP 或域名
ssl_certificate /etc/letsencrypt/live/你的服务器公网 IP/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/你的服务器公网 IP/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
location /wechat/callback {
proxy_pass http://127.0.0.1:8080; # 转发到本地 8080 端口
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
cd /home/ubuntu/video_parse_bot
nohup gunicorn -w 4 -b 127.0.0.1:8080 video_bot:app &
ps aux | grep gunicorn
tail -f nohup.out
https://你的服务器公网 IP/wechat/callback(注意是 HTTPS 开头)。
微信公众号「极客日志」,在微信中扫描左侧二维码关注。展示文案:极客日志 zeeklog
解析常见 curl 参数并生成 fetch、axios、PHP curl 或 Python requests 示例代码。 在线工具,curl 转代码在线工具,online
将字符串编码和解码为其 Base64 格式表示形式即可。 在线工具,Base64 字符串编码/解码在线工具,online
将字符串、文件或图像转换为其 Base64 表示形式。 在线工具,Base64 文件转换器在线工具,online
将 Markdown(GFM)转为 HTML 片段,浏览器内 marked 解析;与 HTML转Markdown 互为补充。 在线工具,Markdown转HTML在线工具,online
将 HTML 片段转为 GitHub Flavored Markdown,支持标题、列表、链接、代码块与表格等;浏览器内处理,可链接预填。 在线工具,HTML转Markdown在线工具,online
通过删除不必要的空白来缩小和压缩JSON。 在线工具,JSON 压缩在线工具,online