Skip to content

Commands Serve

packy edited this page Jun 18, 2026 · 1 revision

serve — 中转服务

启动中转 HTTP 服务(固定 IP 代理微信 API),解决 IP 白名单问题。

用法

wx-newspic serve --api-key "sk-your-key" --port 3000

参数说明

参数 必填 默认值 说明
--api-key, -k API Key 认证密钥
--port, -p 3000 监听端口
--host 0.0.0.0 监听地址
--app-id 凭证配置 微信 APP_ID
--app-secret 凭证配置 微信 APP_SECRET
--log-level info 日志级别

功能

  • 微信 API 请求转发(解决 IP 白名单问题)
  • access_token 自动缓存和续期
  • 图片上传中转
  • 统一错误处理

服务持久化

systemd(推荐)

创建 /etc/systemd/system/wx-newspic.service

[Unit]
Description=wx-newspic Relay Server
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/env wx-newspic serve --api-key "sk-your-key" --port 3000
Restart=always
RestartSec=5
User=your-user
Environment=WECHAT_APP_ID=your_app_id
Environment=WECHAT_APP_SECRET=your_app_secret

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable wx-newspic
sudo systemctl start wx-newspic

pm2

npm install -g pm2
pm2 start wx-newspic -- serve --api-key "sk-your-key" --port 3000
pm2 save
pm2 startup

screen/tmux

screen -S wx-newspic
wx-newspic serve --api-key "sk-your-key" --port 3000
# Ctrl+A D 脱离

Clone this wiki locally