7.1 KiB
Requirements Document
Introduction
本文档定义了将PHP支付系统迁移到.NET 8的需求。支付系统是订单系统的核心组成部分,负责处理微信支付、余额支付、积分支付等多种支付方式,以及支付回调处理和支付状态管理。
Glossary
- Payment_Service: 支付服务,负责处理各种支付方式的统一接口
- Wechat_Pay_Service: 微信支付服务,负责与微信支付API交互
- Order_Notify_Service: 支付回调服务,负责处理微信支付回调通知
- User: 用户实体,包含余额、积分等资产信息
- Order: 订单实体,包含订单金额、支付状态等信息
- Profit_Pay: 支付记录实体,记录用户的支付流水
Requirements
Requirement 1: 微信支付统一下单
User Story: As a user, I want to pay for my order using WeChat Pay, so that I can complete my purchase conveniently.
Acceptance Criteria
- WHEN a user initiates WeChat payment, THE Wechat_Pay_Service SHALL create a unified order with correct parameters
- WHEN the unified order is created successfully, THE Wechat_Pay_Service SHALL return valid payment parameters (appId, timeStamp, nonceStr, package, signType, paySign)
- WHEN the unified order creation fails, THE Wechat_Pay_Service SHALL return an appropriate error message
- THE Wechat_Pay_Service SHALL generate correct MD5 signature for payment parameters
- THE Wechat_Pay_Service SHALL support multiple merchant configurations based on order prefix
Requirement 2: 微信支付回调处理
User Story: As a system, I want to process WeChat payment notifications, so that order status can be updated correctly after payment.
Acceptance Criteria
- WHEN a payment notification is received, THE Order_Notify_Service SHALL verify the signature before processing
- WHEN the signature verification passes and payment is successful, THE Order_Notify_Service SHALL update the order status to paid
- WHEN the order is a lottery order (一番赏/无限赏), THE Order_Notify_Service SHALL trigger the prize drawing process
- WHEN the order is a recharge order, THE Order_Notify_Service SHALL add balance to user account
- WHEN the order is a shipping fee order, THE Order_Notify_Service SHALL update the delivery record status
- THE Order_Notify_Service SHALL record payment information in profit_pay table
- THE Order_Notify_Service SHALL deduct user assets (balance, integral, money2) if used in the order
- IF the payment notification is a duplicate, THEN THE Order_Notify_Service SHALL return success without reprocessing
- THE Order_Notify_Service SHALL return correct XML response to WeChat
Requirement 3: 余额支付
User Story: As a user, I want to pay using my account balance, so that I can use my accumulated funds.
Acceptance Criteria
- WHEN a user chooses balance payment, THE Payment_Service SHALL verify sufficient balance
- IF the balance is insufficient, THEN THE Payment_Service SHALL return an error message
- WHEN balance payment is successful, THE Payment_Service SHALL deduct the amount from user balance
- THE Payment_Service SHALL record the balance deduction in profit_money table
- THE Payment_Service SHALL update order status to paid after successful balance payment
Requirement 4: 积分支付
User Story: As a user, I want to pay using my points (吧唧币), so that I can redeem my accumulated points.
Acceptance Criteria
- WHEN a user chooses integral payment, THE Payment_Service SHALL verify sufficient integral balance
- IF the integral is insufficient, THEN THE Payment_Service SHALL return an error message
- WHEN integral payment is successful, THE Payment_Service SHALL deduct the amount from user integral
- THE Payment_Service SHALL record the integral deduction in profit_integral table
- THE Payment_Service SHALL apply the correct exchange rate for integral to money conversion
Requirement 5: 哈尼券支付
User Story: As a user, I want to pay using my Honey vouchers (哈尼券), so that I can use my promotional credits.
Acceptance Criteria
- WHEN a user chooses money2 payment, THE Payment_Service SHALL verify sufficient money2 balance
- IF the money2 is insufficient, THEN THE Payment_Service SHALL return an error message
- WHEN money2 payment is successful, THE Payment_Service SHALL deduct the amount from user money2
- THE Payment_Service SHALL record the money2 deduction in profit_money2 table
Requirement 6: 混合支付
User Story: As a user, I want to combine multiple payment methods, so that I can use all my available assets.
Acceptance Criteria
- WHEN a user uses mixed payment, THE Payment_Service SHALL process each payment method in order
- THE Payment_Service SHALL first deduct balance if use_money_is is enabled
- THE Payment_Service SHALL then deduct integral if use_integral_is is enabled
- THE Payment_Service SHALL then deduct money2 if use_money2_is is enabled
- THE Payment_Service SHALL calculate remaining amount for WeChat payment
- IF the total deductions cover the order amount, THEN THE Payment_Service SHALL complete payment without WeChat
- THE Payment_Service SHALL ensure atomicity of all deductions in a transaction
Requirement 7: 支付签名验证
User Story: As a system, I want to verify payment signatures, so that payment security is ensured.
Acceptance Criteria
- THE Payment_Service SHALL generate MD5 signature using sorted parameters and secret key
- THE Payment_Service SHALL verify incoming signatures match calculated signatures
- THE Payment_Service SHALL support multiple secret keys for different merchants
- IF signature verification fails, THEN THE Payment_Service SHALL reject the request
Requirement 8: 支付记录管理
User Story: As a user, I want to view my payment history, so that I can track my spending.
Acceptance Criteria
- THE Payment_Service SHALL record all payment transactions in profit_pay table
- THE Payment_Service SHALL include order number, amount, payment type, and timestamp
- THE Payment_Service SHALL support querying payment records by user and type
Requirement 9: 订单发货通知
User Story: As a system, I want to notify WeChat about order shipment, so that users can track their orders in WeChat.
Acceptance Criteria
- WHEN an order is paid, THE Payment_Service SHALL send shipping notification to WeChat
- THE Payment_Service SHALL include correct merchant ID and order number
- IF the notification fails, THEN THE Payment_Service SHALL store the order for retry
- THE Payment_Service SHALL support retry mechanism for failed notifications
Requirement 10: API响应格式兼容
User Story: As a frontend developer, I want the payment API responses to match the PHP API format, so that no frontend changes are needed.
Acceptance Criteria
- THE Payment_Service SHALL return responses in the same format as PHP API
- THE Payment_Service SHALL use snake_case for all response field names
- THE Payment_Service SHALL return status code 1 for success and 0 for failure
- THE Payment_Service SHALL include msg field with appropriate message