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
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_IDTENCENT_SECRET_KEYDB_HOSTDB_PASSWORDWECHAT_APPIDWECHAT_SECRETJWT_SECRETADMIN_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/loginPOST /api/v1/auth/refreshGET /api/v1/user/profilePUT /api/v1/user/profilePOST /api/v1/user/phonePOST /api/v1/device/bindPOST /api/v1/device/unbindGET /api/v1/device/listGET /api/v1/device/:device_idGET /api/v1/device/command/pendingPOST /api/v1/device/eventGET /api/v1/subscriptionPOST /api/v1/subscription/purchasePOST /api/v1/subscription/verifyGET /api/v1/treatment/historyPOST /api/v1/treatment/syncGET /api/v1/firmware/latest
管理后台接口:
POST /api/v1/admin/loginGET /api/v1/admin/dashboardGET /api/v1/admin/devicesGET /api/v1/admin/devices/:device_idPOST /api/v1/admin/devices/:device_id/commandPOST /api/v1/admin/devices/:device_id/unbindGET /api/v1/admin/usersGET /api/v1/admin/users/:user_idGET /api/v1/admin/subscriptionsPOST /api/v1/admin/subscriptionsGET /api/v1/admin/recordsGET /api/v1/admin/logsGET /api/v1/admin/settingsPOST /api/v1/admin/settingsGET /api/v1/admin/devices/:device_id/commandsGET /api/v1/admin/firmwarePOST /api/v1/admin/firmwarePOST /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。