# wechat-uploader-imger-typora **Repository Path**: HermitLoneWolf/wechat-uploader-imger-typora ## Basic Information - **Project Name**: wechat-uploader-imger-typora - **Description**: 用于typora自动上传图片到微信公众号素材库的小程序 - **Primary Language**: Python - **License**: GPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-08-18 - **Last Updated**: 2025-08-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: Markdown, Python, wechat, Typora ## README # 微信公众号图床上传工具 为微信公众号内容创作者提供便捷的本地图片上传至微信图床的工具,支持一键上传并生成可直接使用的 URL。 ## 功能特点 - 图片上传:支持从本地路径上传多个图片文件 - URL 生成:上传成功后输出可直接使用的微信图片 URL - Typora 集成:支持与 Typora 图像上传服务一键集成,自动上传并替换图片链接 - Token 缓存:自动缓存 access_token,7000 秒内重复运行无需重新请求 - 多平台支持 - 独立部署:支持编译为独立可执行文件(如 exe),便于分发 ## 准备步骤 | 步骤 | 操作要点 | |------|----------| | ① 获取凭证 | 在「微信公众号后台 → 设置与开发 → 基本配置」里复制 **AppID** 和 **AppSecret** | | ② 下载程序 | 拿到 `wechat_uploader_imger_typora.exe`(或源码 `wechat_uploader_imger_typora.py`) | | ③ 放到同一目录 | 建议新建空文件夹,把程序放进去即可 | ## 首次运行配置(一次性设置) 1. **双击程序**(或命令行运行 `python wechat_uploader_imger_typora.py`) 2. 程序会自动生成 `config.json` 并提示: ``` 已生成配置文件:D:\Tools\wechat_uploader\config.json 请先修改其中的 AppID 和 AppSecret,再重新运行! ``` 3. 用记事本打开 `config.json`,填入真实值后保存: ```json { "AppID": "xxxxxxxxxx", "AppSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" } ``` 4. 再次双击即可完成配置 ## 上传图片 ### Windows 命令行使用 ```bash # Windows CMD / PowerShell wechat_uploader_imger_typora.exe "D:\imgs\demo1.png" "D:\imgs\demo2.jpg" # 或直接运行源码 python wechat_uploader_imger_typora.py demo1.png demo2.jpg ``` ### 结果输出 上传成功后,终端会显示: ``` Upload Success: http://mmbiz.qpic.cn/mmbiz_png/xxxxxxxx/640 http://mmbiz.qpic.cn/mmbiz_jpg/xxxxxxxx/640 ``` 复制对应 URL 即可在 **Markdown / Typora / 微信图文** 中直接引用。 ## Typora 一键集成 1. 打开 Typora → 偏好设置 → 图像 → 上传服务 → 自定义命令 2. 填写命令: ``` # 编译好的exe文件 "xxxxxx(程序路径)\wechat_uploader_imger_typora.exe" # 直接使用程序 python xxxxxx(程序路径)\wechat_uploader_imger_typora.py ``` 3. 勾选「插入时自动上传图片」 以后点击 **上传图片** 图片即可自动上传并替换为微信 URL 4. 错误排查 上传报错后点击**Typora → 偏好设置 → 图像 → 上传服务 → 验证上传选项**查看错误提示 ## 常见错误排查 | 现象 | 原因与解决方案 | |------|----------------| | `errcode:41002` | `config.json` 里 AppID 为空 → 重新填写 | | `errcode:40164` | 当前公网 IP 未加入公众号后台 **IP 白名单** → 把控制台打印的 IP 加到**微信公众号**【设置与开发 → 基本配置 → IP 白名单】 | > **注意事项:** > 1. IP 地址添加到白名单后并不会立马生效,请稍后再试 > 2. 不要透露 config.json 和 token.json 中的内容,以防造成不必要的损失 ## 编译为可执行文件 使用 pyinstaller 编译为独立可执行文件: ```bash pyinstaller -F -w wechat_uploader_imger_typora.py ``` 完成后在 `dist\wechat_uploader_imger_typora.exe` 得到可执行文件。把 `wechat_uploader_imger_typora.exe` 发给任何 Windows 电脑即可运行,无需安装 Python。