HaniBlindBox/.kiro/specs/payment-integration/tasks.md
2026-01-03 00:10:18 +08:00

273 lines
11 KiB
Markdown
Raw 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.

# Implementation Plan: 支付集成迁移
## Overview
本任务列表将PHP支付系统迁移到.NET 8按照接口优先级逐个迁移。每迁移一个接口前需要先查看PHP代码了解详细业务逻辑迁移完成后需要在API接口文档.md中标记迁移状态。
## Tasks
- [x] 1. 基础设施准备
- [x] 1.1 创建支付相关的DTO和Request/Response模型
- 在HoneyBox.Model/Models/Payment目录下创建相关模型
- 包括WechatPayRequest、WechatPayResult、WechatPayData等
- 包括NotifyResult、PaymentRecordDto等
- _Requirements: 1.1-10.4_
- [x] 1.2 创建服务接口定义
- 在HoneyBox.Core/Interfaces目录下创建IWechatPayService、IPaymentNotifyService接口
- _Requirements: 1.1-10.4_
- [x] 1.3 创建数据库实体模型(如果尚未存在)
- 确认OrderNotify实体存在
- 配置EF Core映射
- _Requirements: 1.1-10.4_
- [x] 1.4 注册服务到DI容器
- 在ServiceModule.cs中注册WechatPayService、PaymentNotifyService
- _Requirements: 1.1-10.4_
- [x] 2. 微信支付配置服务实现
- [x] 2.1 查看PHP代码了解微信支付配置逻辑
- 阅读server/php/app/api/controller/Pay.php中的构造函数和setMerchantByOrderNum方法
- 理解多商户配置、订单前缀匹配逻辑
- _Requirements: 1.5_
- [x] 2.2 实现WechatPayConfig配置类
- 实现微信支付配置读取
- 实现多商户配置支持
- 实现根据订单前缀获取商户配置
- _Requirements: 1.5_
- [x] 3. 微信支付签名服务实现
- [x] 3.1 查看PHP代码了解签名生成逻辑
- 阅读server/php/app/api/controller/Pay.php中的MakeSign、ToUrlParams方法
- 理解MD5签名算法
- _Requirements: 1.4, 7.1, 7.2, 7.3_
- [x] 3.2 实现签名生成和验证方法
- 实现MakeSign方法参数排序、拼接、MD5加密
- 实现VerifySign方法
- _Requirements: 1.4, 7.1, 7.2, 7.3_
- [ ]* 3.3 编写签名属性测试
- **Property 1: 支付签名正确性**
- **Validates: Requirements 1.4, 7.1, 7.2**
- [x] 4. 微信支付统一下单服务实现
- [x] 4.1 查看PHP代码了解统一下单逻辑
- 阅读server/php/app/api/controller/Pay.php中的wxCreateOrder、wxpay方法
- 理解统一下单参数构建、XML转换、API调用逻辑
- _Requirements: 1.1-1.5_
- [x] 4.2 实现WechatPayService - 统一下单
- 实现CreatePaymentAsync方法
- 实现XML构建和解析
- 实现微信API调用
- 实现支付参数返回
- _Requirements: 1.1-1.5_
- [x] 5. Checkpoint - 微信支付服务测试验证
- 确保微信支付配置、签名、统一下单服务测试通过
- 如有问题请询问用户
- [x] 6. 支付回调服务实现
- [x] 6.1 查看PHP代码了解支付回调处理逻辑
- 阅读server/php/app/api/controller/Notify.php中的order_notify方法
- 理解签名验证、订单类型判断、状态更新逻辑
- _Requirements: 2.1-2.9_
- [x] 6.2 实现PaymentNotifyService - 回调处理
- 实现HandleWechatNotifyAsync方法
- 实现XML解析和签名验证
- 实现订单类型路由(一番赏、无限赏、充值、发货等)
- _Requirements: 2.1-2.9_
- [ ]* 6.3 编写回调幂等性属性测试
- **Property 2: 支付回调幂等性**
- **Validates: Requirements 2.8**
- [x] 7. 一番赏订单支付成功处理
- [x] 7.1 查看PHP代码了解一番赏支付成功处理逻辑
- 阅读server/php/app/api/controller/Notify.php中的drawprize_notice方法
- 理解订单状态更新、资产扣减、抽奖触发逻辑
- _Requirements: 2.3, 2.6, 2.7_
- [x] 7.2 实现ProcessLotteryOrderAsync方法
- 实现订单状态更新
- 实现用户资产扣减(余额、积分、哈尼券)
- 实现优惠券状态更新
- 调用现有抽奖服务
- _Requirements: 2.3, 2.6, 2.7_
- [x] 8. 无限赏订单支付成功处理
- [x] 8.1 查看PHP代码了解无限赏支付成功处理逻辑
- 阅读server/php/app/api/controller/Notify.php中的infinite_drawprize_notice方法
- 理解无限赏特有的处理逻辑
- _Requirements: 2.3, 2.6, 2.7_
- [x] 8.2 实现ProcessInfiniteOrderAsync方法
- 实现无限赏订单状态更新
- 实现用户资产扣减
- 调用现有无限赏抽奖服务
- _Requirements: 2.3, 2.6, 2.7_
- [x] 9. 充值订单支付成功处理
- [x] 9.1 查看PHP代码了解充值支付成功处理逻辑
- 阅读server/php/app/api/controller/Notify.php中user_recharge相关处理
- 理解充值金额增加逻辑
- _Requirements: 2.4_
- [x] 9.2 实现ProcessRechargeOrderAsync方法
- 实现充值订单状态更新
- 实现用户余额增加
- 记录支付流水
- _Requirements: 2.4_
- [x] 10. 发货运费支付成功处理
- [x] 10.1 查看PHP代码了解发货运费支付成功处理逻辑
- 阅读server/php/app/api/controller/Notify.php中order_list_send相关处理
- 理解发货记录状态更新逻辑
- _Requirements: 2.5_
- [x] 10.2 实现ProcessShippingFeeOrderAsync方法
- 实现发货记录状态更新
- 记录支付流水
- _Requirements: 2.5_
- [x] 11. Checkpoint - 支付回调服务测试验证
- 确保所有支付回调处理服务测试通过
- 如有问题请询问用户
- [x] 12. 资产扣减服务实现
- [x] 12.1 查看PHP代码了解资产扣减逻辑
- 阅读server/php/app/common/model/User.php中的changeMoney、changeIntegral、changeMoney2方法
- 理解资产变更记录逻辑
- _Requirements: 3.1-5.4_
- [x] 12.2 实现PaymentService - 资产扣减
- 实现DeductBalanceAsync方法
- 实现DeductIntegralAsync方法
- 实现DeductMoney2Async方法
- 实现资产变更记录
- _Requirements: 3.1-5.4_
- [ ]* 12.3 编写资产扣减属性测试
- **Property 4: 余额扣减正确性**
- **Validates: Requirements 3.3, 3.4**
- [x] 13. 支付记录服务实现
- [x] 13.1 查看PHP代码了解支付记录逻辑
- 阅读server/php/app/api/controller/Notify.php中ProfitPay::insert相关代码
- 理解支付记录字段和类型
- _Requirements: 8.1-8.3_
- [x] 13.2 实现PaymentService - 支付记录
- 实现RecordPaymentAsync方法
- 支持不同支付类型记录
- _Requirements: 8.1-8.3_
- [ ]* 13.3 编写支付记录属性测试
- **Property 5: 支付记录完整性**
- **Validates: Requirements 8.1, 8.2**
- [x] 14. 订单发货通知服务实现
- [x] 14.1 查看PHP代码了解订单发货通知逻辑
- 阅读server/php/app/api/controller/Pay.php中的post_order方法
- 理解微信发货通知API调用逻辑
- _Requirements: 9.1-9.4_
- [x] 14.2 实现WechatPayService - 发货通知
- 实现PostOrderShippingAsync方法
- 实现失败重试机制
- _Requirements: 9.1-9.4_
- [x] 15. Checkpoint - 支付服务测试验证
- 确保所有支付服务测试通过
- 如有问题请询问用户
- [x] 16. 控制器实现 - NotifyController
- [x] 16.1 实现微信支付回调接口 POST /api/notify/order_notify
- 调用PaymentNotifyService.HandleWechatNotifyAsync
- 返回正确的XML响应
- 更新API接口文档标记迁移状态
- _Requirements: 2.1-2.9_
- [x] 17. 控制器实现 - PayController如需要独立支付接口
- [x] 17.1 实现支付接口 POST /api/pay
- 调用WechatPayService.CreatePaymentAsync
- 更新API接口文档标记迁移状态
- _Requirements: 1.1-1.5_
- [x] 18. Checkpoint - 控制器测试验证
- 确保所有控制器接口可正常访问
- 使用Postman或HTTP文件测试各接口
- 如有问题请询问用户
- [x] 19. API响应格式验证
- [x] 19.1 验证所有接口响应格式
- 确保status、msg、data结构一致
- 确保字段命名与PHP API一致snake_case
- 确保微信支付参数格式正确
- _Requirements: 10.1-10.4_
- [x] 20. 集成测试
- [x] 20.1 编写微信支付集成测试
- 测试统一下单流程模拟微信API
- 测试签名生成和验证
- _Requirements: 1.1-1.5, 7.1-7.4_
- [x] 20.2 编写支付回调集成测试
- 测试回调处理流程
- 测试幂等性
- _Requirements: 2.1-2.9_
- [x] 20.3 编写资产扣减集成测试
- 测试余额扣减
- 测试积分扣减
- 测试哈尼券扣减
- 测试混合支付
- _Requirements: 3.1-6.7_
- [ ]* 20.4 编写混合支付原子性属性测试
- **Property 3: 资产扣减原子性**
- **Validates: Requirements 6.7**
- [x] 21. 文档更新和最终验证
- [x] 21.1 更新API接口文档
- 确认所有迁移接口都已标记
- 记录新接口地址
- _Requirements: 10.1-10.4_
- [x] 21.2 创建HTTP测试文件
- 在HoneyBox.Api目录下创建payment-system.http测试文件
- 包含所有支付系统相关接口的测试请求
- [ ] 22. Final Checkpoint - 完整功能验证
- 确保所有测试通过
- 确保API文档已更新
- 确保与前端兼容性
- 如有问题请询问用户
## Notes
- Tasks marked with `*` are optional and can be skipped for faster MVP
- Each task references specific requirements for traceability
- Checkpoints ensure incremental validation
- Property tests validate universal correctness properties
- Unit tests validate specific examples and edge cases
- 每迁移完成一个接口都需要在docs/API接口文档.md中标记迁移状态和新接口地址
- 迁移前必须先查看PHP代码了解详细业务逻辑确保功能一致性
- 支付系统涉及资金安全,需要特别注意签名验证和事务处理
- 支付回调需要确保幂等性,防止重复处理
## 接口迁移清单
| 序号 | PHP接口 | 新接口地址 | 状态 |
|------|---------|-----------|------|
| 1 | POST /api/notify/order_notify | POST /api/notify/order_notify | ✅ |
| 2 | POST /api/pay | POST /api/pay | ✅ |
## 关键业务逻辑说明
### 支付回调订单类型
| attach值 | 订单类型 | 处理方法 |
|----------|---------|---------|
| user_recharge | 余额充值 | ProcessRechargeOrderAsync |
| order_yfs | 一番赏订单 | ProcessLotteryOrderAsync |
| order_lts | 擂台赏订单 | ProcessLotteryOrderAsync |
| order_zzs | 转转赏订单 | ProcessLotteryOrderAsync |
| order_flw | 福利屋订单 | ProcessLotteryOrderAsync |
| order_scs | 商城赏订单 | ProcessLotteryOrderAsync |
| order_wxs | 无限赏订单 | ProcessInfiniteOrderAsync |
| order_fbs | 翻倍赏订单 | ProcessInfiniteOrderAsync |
| order_ckj | 抽卡机订单 | ProcessCardExtractorOrderAsync |
| order_list_send | 发货运费 | ProcessShippingFeeOrderAsync |
### 支付类型枚举
| PayType | 说明 |
|---------|------|
| 1 | 微信支付 |
| 2 | 余额支付 |
| 3 | 积分支付 |
| 4 | 哈尼券支付 |