|
|
@@ -0,0 +1,146 @@
|
|
|
+# Story 010.003: system-config-auth-payment-integration
|
|
|
+
|
|
|
+## Status
|
|
|
+Draft
|
|
|
+
|
|
|
+## Story
|
|
|
+**As a** 系统管理员,
|
|
|
+**I want** 将系统配置模块集成到认证和支付模块中,
|
|
|
+**so that** 小程序登录和支付功能可以使用租户特定的配置参数
|
|
|
+
|
|
|
+## Acceptance Criteria
|
|
|
+1. 修改MiniAuthService,从系统配置获取微信小程序AppID和Secret
|
|
|
+2. 修改PaymentMtService,从系统配置获取微信支付商户配置
|
|
|
+3. 在认证和支付服务中添加租户ID参数支持
|
|
|
+4. 验证现有功能保持完整,无回归
|
|
|
+5. 创建集成测试验证配置集成功能
|
|
|
+
|
|
|
+## Tasks / Subtasks
|
|
|
+- [ ] 修改MiniAuthService支持系统配置 (AC: 1, 3)
|
|
|
+ - [ ] 在MiniAuthService构造函数中注入SystemConfigServiceMt依赖 [packages/core-module-mt/auth-module-mt/src/services/mini-auth.service.mt.ts:12-15](packages/core-module-mt/auth-module-mt/src/services/mini-auth.service.mt.ts#L12-L15)
|
|
|
+ - [ ] 修改getOpenIdByCode方法,从系统配置获取AppID和Secret [packages/core-module-mt/auth-module-mt/src/services/mini-auth.service.mt.ts:69-97](packages/core-module-mt/auth-module-mt/src/services/mini-auth.service.mt.ts#L69-L97)
|
|
|
+ - [ ] 添加租户ID参数到miniLogin方法 [packages/core-module-mt/auth-module-mt/src/services/mini-auth.service.mt.ts:17-41](packages/core-module-mt/auth-module-mt/src/services/mini-auth.service.mt.ts#L17-L41)
|
|
|
+ - [ ] 更新mini-login路由支持租户ID参数 [packages/core-module-mt/auth-module-mt/src/routes/mini-login.route.mt.ts](packages/core-module-mt/auth-module-mt/src/routes/mini-login.route.mt.ts)
|
|
|
+- [ ] 修改PaymentMtService支持系统配置 (AC: 2, 3)
|
|
|
+ - [ ] 在PaymentMtService构造函数中注入SystemConfigServiceMt依赖 [packages/mini-payment-mt/src/services/payment.mt.service.ts:20-22](packages/mini-payment-mt/src/services/payment.mt.service.ts#L20-L22)
|
|
|
+ - [ ] 修改构造函数,从系统配置获取支付参数 [packages/mini-payment-mt/src/services/payment.mt.service.ts:27-36](packages/mini-payment-mt/src/services/payment.mt.service.ts#L27-L36)
|
|
|
+ - [ ] 添加租户ID参数到createPayment方法 [packages/mini-payment-mt/src/services/payment.mt.service.ts:62-69](packages/mini-payment-mt/src/services/payment.mt.service.ts#L62-L69)
|
|
|
+ - [ ] 更新支付路由支持租户ID参数 [packages/mini-payment-mt/src/routes/payment/create.mt.ts](packages/mini-payment-mt/src/routes/payment/create.mt.ts)
|
|
|
+- [ ] 实现系统配置键定义 (AC: 1, 2)
|
|
|
+ - [ ] 定义认证配置键:`wx.mini.app.id`, `wx.mini.app.secret`
|
|
|
+ - [ ] 定义支付配置键:`wx.payment.merchant.id`, `wx.payment.v3.key`, `wx.payment.cert.serial.no`, `wx.payment.public.key`, `wx.payment.private.key`, `wx.payment.notify.url`
|
|
|
+ - [ ] 创建配置键常量文件 [packages/core-module-mt/system-config-module-mt/src/constants/config-keys.constants.mt.ts](packages/core-module-mt/system-config-module-mt/src/constants/config-keys.constants.mt.ts)
|
|
|
+- [ ] 创建集成测试验证配置集成 (AC: 5)
|
|
|
+ - [ ] 创建认证模块系统配置集成测试 [packages/core-module-mt/auth-module-mt/tests/integration/system-config-integration.test.ts](packages/core-module-mt/auth-module-mt/tests/integration/system-config-integration.test.ts)
|
|
|
+ - [ ] 创建支付模块系统配置集成测试 [packages/mini-payment-mt/tests/integration/system-config-integration.test.ts](packages/mini-payment-mt/tests/integration/system-config-integration.test.ts)
|
|
|
+ - [ ] 测试认证配置读取功能
|
|
|
+ - [ ] 测试支付配置读取功能
|
|
|
+ - [ ] 测试租户配置隔离
|
|
|
+- [ ] 验证现有功能无回归 (AC: 4)
|
|
|
+ - [ ] 运行现有认证模块测试 [packages/core-module-mt/auth-module-mt/tests/integration/auth.integration.test.ts](packages/core-module-mt/auth-module-mt/tests/integration/auth.integration.test.ts)
|
|
|
+ - [ ] 运行现有支付模块测试 [packages/mini-payment-mt/tests/integration/payment-routes.integration.test.ts](packages/mini-payment-mt/tests/integration/payment-routes.integration.test.ts)
|
|
|
+ - [ ] 验证小程序登录功能正常
|
|
|
+ - [ ] 验证支付创建功能正常
|
|
|
+
|
|
|
+## Dev Notes
|
|
|
+
|
|
|
+### 技术栈信息 [Source: architecture/tech-stack.md]
|
|
|
+- **运行时**: Node.js 20.18.3
|
|
|
+- **框架**: Hono 4.8.5 (Web框架和API路由)
|
|
|
+- **数据库**: PostgreSQL 17 (通过TypeORM)
|
|
|
+- **ORM**: TypeORM 0.3.25 (实体管理)
|
|
|
+- **缓存**: Redis 7.0.0 (会话管理和缓存)
|
|
|
+
|
|
|
+### 项目结构信息 [Source: architecture/source-tree.md]
|
|
|
+- **认证模块位置**: `packages/core-module-mt/auth-module-mt/`
|
|
|
+- **支付模块位置**: `packages/mini-payment-mt/`
|
|
|
+- **系统配置模块位置**: `packages/core-module-mt/system-config-module-mt/`
|
|
|
+- **共享工具位置**: `packages/shared-utils/`
|
|
|
+
|
|
|
+### 认证模块现有结构 [Source: packages/core-module-mt/auth-module-mt/src/services/mini-auth.service.mt.ts]
|
|
|
+- **MiniAuthService**: 处理小程序登录和用户管理
|
|
|
+- **环境变量依赖**: 目前从process.env获取WX_MINI_APP_ID和WX_MINI_APP_SECRET
|
|
|
+- **方法**: miniLogin, getOpenIdByCode, updateUserProfile, decryptPhoneNumber
|
|
|
+- **参考文件**: [packages/core-module-mt/auth-module-mt/src/services/mini-auth.service.mt.ts](packages/core-module-mt/auth-module-mt/src/services/mini-auth.service.mt.ts)
|
|
|
+
|
|
|
+### 支付模块现有结构 [Source: packages/mini-payment-mt/src/services/payment.mt.service.ts]
|
|
|
+- **PaymentMtService**: 继承GenericCrudService,处理微信小程序支付,支持多租户
|
|
|
+- **环境变量依赖**: 目前从process.env获取WECHAT_MERCHANT_ID, WX_MINI_APP_ID, WECHAT_V3_KEY等
|
|
|
+- **方法**: createPayment, handlePaymentCallback, getPaymentStatus
|
|
|
+- **租户支持**: 已支持tenantId参数,继承GenericCrudService的多租户功能
|
|
|
+- **参考文件**: [packages/mini-payment-mt/src/services/payment.mt.service.ts](packages/mini-payment-mt/src/services/payment.mt.service.ts)
|
|
|
+
|
|
|
+### 系统配置模块现有结构 [Source: packages/core-module-mt/system-config-module-mt/src/services/system-config.service.mt.ts]
|
|
|
+- **SystemConfigServiceMt**: 继承GenericCrudService,支持多租户和Redis缓存
|
|
|
+- **缓存方法**: getConfigByKey, getConfigsByKeys, setConfig, deleteConfig
|
|
|
+- **缓存策略**: 正常值1小时TTL,空值5分钟TTL
|
|
|
+- **参考文件**: [packages/core-module-mt/system-config-module-mt/src/services/system-config.service.mt.ts](packages/core-module-mt/system-config-module-mt/src/services/system-config.service.mt.ts)
|
|
|
+
|
|
|
+### 配置键定义策略
|
|
|
+- **认证配置键**:
|
|
|
+ - `wx.mini.app.id` - 微信小程序AppID
|
|
|
+ - `wx.mini.app.secret` - 微信小程序AppSecret
|
|
|
+- **支付配置键**:
|
|
|
+ - `wx.payment.merchant.id` - 微信支付商户ID
|
|
|
+ - `wx.payment.v3.key` - 微信支付V3密钥
|
|
|
+ - `wx.payment.cert.serial.no` - 商户证书序列号
|
|
|
+ - `wx.payment.public.key` - 商户公钥
|
|
|
+ - `wx.payment.private.key` - 商户私钥
|
|
|
+ - `wx.payment.notify.url` - 支付回调URL
|
|
|
+
|
|
|
+### 集成方法
|
|
|
+- **依赖注入**: 在服务构造函数中注入SystemConfigServiceMt
|
|
|
+- **配置优先**: 优先从系统配置读取,如果配置不存在则回退到环境变量
|
|
|
+- **租户隔离**: 所有配置读取必须指定租户ID
|
|
|
+- **缓存利用**: 利用系统配置模块的Redis缓存提高配置读取性能
|
|
|
+
|
|
|
+### 关键参考文件路径
|
|
|
+- **认证服务**: [packages/core-module-mt/auth-module-mt/src/services/mini-auth.service.mt.ts](packages/core-module-mt/auth-module-mt/src/services/mini-auth.service.mt.ts)
|
|
|
+- **支付服务**: [packages/mini-payment-mt/src/services/payment.mt.service.ts](packages/mini-payment-mt/src/services/payment.mt.service.ts)
|
|
|
+- **系统配置服务**: [packages/core-module-mt/system-config-module-mt/src/services/system-config.service.mt.ts](packages/core-module-mt/system-config-module-mt/src/services/system-config.service.mt.ts)
|
|
|
+- **认证路由**: [packages/core-module-mt/auth-module-mt/src/routes/mini-login.route.mt.ts](packages/core-module-mt/auth-module-mt/src/routes/mini-login.route.mt.ts)
|
|
|
+- **支付路由**: [packages/mini-payment-mt/src/routes/payment/create.mt.ts](packages/mini-payment-mt/src/routes/payment/create.mt.ts)
|
|
|
+
|
|
|
+### Testing
|
|
|
+
|
|
|
+#### 测试标准 [Source: architecture/testing-strategy.md]
|
|
|
+- **测试框架**: Vitest + hono/testing
|
|
|
+- **测试位置**: 各模块的`tests/integration/`目录
|
|
|
+- **测试类型**: 集成测试
|
|
|
+- **覆盖率目标**: 集成测试 ≥ 60%
|
|
|
+
|
|
|
+#### 测试文件结构
|
|
|
+- `packages/core-module-mt/auth-module-mt/tests/integration/system-config-integration.test.ts` - 认证模块系统配置集成测试
|
|
|
+- `packages/mini-payment-mt/tests/integration/system-config-integration.test.ts` - 支付模块系统配置集成测试
|
|
|
+
|
|
|
+#### 测试场景
|
|
|
+- 系统配置读取测试(认证配置)
|
|
|
+- 系统配置读取测试(支付配置)
|
|
|
+- 租户配置隔离测试
|
|
|
+- 配置回退到环境变量测试
|
|
|
+- 现有功能回归测试
|
|
|
+
|
|
|
+#### 现有模块参考模式
|
|
|
+- **文件模块**: `packages/core-module-mt/file-module-mt/`
|
|
|
+- **用户模块**: `packages/core-module-mt/user-module-mt/`
|
|
|
+- **命名约定**: 所有文件使用 `.mt.ts` 后缀,遵循多租户包命名规范
|
|
|
+
|
|
|
+## Change Log
|
|
|
+| Date | Version | Description | Author |
|
|
|
+|------|---------|-------------|--------|
|
|
|
+| 2025-11-20 | 1.0 | 初始故事创建 | Bob (Scrum Master) |
|
|
|
+
|
|
|
+## Dev Agent Record
|
|
|
+
|
|
|
+### Agent Model Used
|
|
|
+- **Agent**:
|
|
|
+- **Environment**:
|
|
|
+- **Session Date**:
|
|
|
+
|
|
|
+### Debug Log References
|
|
|
+
|
|
|
+### Completion Notes List
|
|
|
+
|
|
|
+### File List
|
|
|
+
|
|
|
+## QA Results
|