文件
jw-beauty/server
Guoguo 78ea1a03c5 feat: WeChat Pay V3 integration (fill credentials to activate)
Server:
- New lib/wxpay.js: native crypto RSA-SHA256 signing, JSAPI prepay,
  AES-256-GCM notify decryption, order query (no npm deps)
- New dao/payment-order.dao.js: createOrder, markPrepay,
  markPaidAndActivateSubscription (idempotent + transactional)
- New routes/payment.js: GET order status, POST order sync
- New routes/payment-notify.js: WeChat async callback handler with
  signature verification, amount/appid/mchid validation
- Modified subscription/purchase: auto-detects wxpay config, returns
  real payment_params or mock fallback
- Schema: payment_orders table with out_trade_no unique key
- app.js: express.raw() for notify path, payment routes mounted
- config.js: wxpay block with 7 env vars
- .env.example: all WeChat Pay fields documented
- .gitignore: certs/, *.pem, *.p12

Miniprogram:
- subscribe-plans doPurchase: calls real purchase API, falls back to
  mockPurchase only when server returns mock:true
- Added syncAndRedirect for post-payment order confirmation
- api.js: getPaymentOrder, syncPaymentOrder
- Removed "模拟支付"/"测试环境" from UI text
2026-05-18 03:07:59 -07:00
..

Hox 腾讯云函数后端

本目录是 Hox 项目的腾讯云后端骨架,目标架构为:腾讯云函数 SCF Node.js + 腾讯云数据库 MySQL + 腾讯云 COS。

配置

本地配置文件为 .env,不会提交到 Git。提交用模板为 .env.example

当前已按项目默认值预置:

配置
COS Bucket jw-bucket-1426323813
地域 ap-guangzhou
数据库 jw_beauty
数据库用户 root
临时后台账号 admin
临时后台密码 admin

你需要补充 .env 中的真实值:

  • TENCENT_SECRET_ID
  • TENCENT_SECRET_KEY
  • DB_HOST
  • DB_PASSWORD
  • WECHAT_APPID
  • WECHAT_SECRET
  • JWT_SECRET
  • ADMIN_JWT_SECRET

本地运行

cd server
npm install
npm run db:init
npm start

健康检查:

curl http://localhost:3000/health

SCF 入口

腾讯云函数入口:

index.main_handler

HTTP 触发器或函数 URL 需要透传:

  • HTTP method
  • path
  • headers
  • queryStringParameters
  • body

已实现接口

小程序接口:

  • POST /api/v1/auth/login
  • POST /api/v1/auth/refresh
  • GET /api/v1/user/profile
  • PUT /api/v1/user/profile
  • POST /api/v1/user/phone
  • POST /api/v1/device/bind
  • POST /api/v1/device/unbind
  • GET /api/v1/device/list
  • GET /api/v1/device/:device_id
  • GET /api/v1/device/command/pending
  • POST /api/v1/device/event
  • GET /api/v1/subscription
  • POST /api/v1/subscription/purchase
  • POST /api/v1/subscription/verify
  • GET /api/v1/treatment/history
  • POST /api/v1/treatment/sync
  • GET /api/v1/firmware/latest

管理后台接口:

  • POST /api/v1/admin/login
  • GET /api/v1/admin/dashboard
  • GET /api/v1/admin/devices
  • GET /api/v1/admin/devices/:device_id
  • POST /api/v1/admin/devices/:device_id/command
  • POST /api/v1/admin/devices/:device_id/unbind
  • GET /api/v1/admin/users
  • GET /api/v1/admin/users/:user_id
  • GET /api/v1/admin/subscriptions
  • POST /api/v1/admin/subscriptions
  • GET /api/v1/admin/records
  • GET /api/v1/admin/logs
  • GET /api/v1/admin/settings
  • POST /api/v1/admin/settings
  • GET /api/v1/admin/devices/:device_id/commands
  • GET /api/v1/admin/firmware
  • POST /api/v1/admin/firmware
  • POST /api/v1/admin/firmware/:firmware_id/status

数据库

表结构在:

sql/schema.sql

初始化脚本会创建表并插入临时管理员账号。

重要说明

  • 当前微信支付只保留接口骨架,未接入真实微信支付回调。
  • /api/v1/device/command/pending 已接入 device_commands,小程序拉取后执行 BLE 指令并回传结果。
  • /api/v1/firmware/latest 会读取 firmware_files 并生成 COS 签名 URL,后台可通过固件接口登记 COS 对象 key。
  • 生产环境必须替换 admin/admin 和所有默认 secret。