Files
2026-07-12 14:45:05 +08:00

69 lines
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 微信支付 Native 页面
基于 Express + EJS + JSON 文件存储的微信支付 Native 模式演示项目。
## 功能
- 商品列表展示
- 微信支付 Native 统一下单,生成支付二维码
- 前端轮询订单状态,支付成功自动跳转
- 微信支付异步通知回调处理(验签 + 更新订单)
- 订单记录查询页
- 数据以 JSON 文件存储,无需数据库
## 目录结构
```
├── app.js # Express 入口
├── config.js # 微信支付配置(已 gitignore
├── config.example.js # 配置模板
├── data/orders.json # 订单数据文件
├── utils/storage.js # JSON 文件读写封装
├── routes/
│ ├── index.js # 首页路由
│ └── pay.js # 支付相关路由
├── views/
│ ├── index.ejs # 商品列表
│ ├── pay.ejs # 支付页(二维码 + 轮询)
│ ├── success.ejs # 支付成功页
│ └── orders.ejs # 订单记录
└── public/css/style.css
```
## 使用
```bash
# 安装依赖
npm install
# 修改配置
cp config.example.js config.js
# 编辑 config.js,填入微信支付凭据
# 启动
npm start
```
访问 `http://localhost:3000`
## 接口
| 路由 | 说明 |
|------|------|
| `GET /` | 商品列表 |
| `GET /pay/create/:productId` | 创建订单、生成二维码 |
| `GET /pay/status/:orderId` | 查询订单状态(轮询用) |
| `POST /pay/notify` | 微信支付回调通知 |
| `GET /pay/success/:orderId` | 支付成功页 |
| `GET /pay/orders` | 订单记录 |
## 技术栈
- Express 4
- EJS 模板引擎
- qrcode(服务端生成二维码 Data URL)
- axios(调用微信 API
- xml2js(解析微信 XML 响应)
- uuid(生成订单号)
- JSON 文件存储(`data/orders.json`