Compare commits

...

2 Commits

Author SHA1 Message Date
ca5e88cdf1 docs(guide): 添加PayPal配置检查和客户订单表创建说明
- 创建PAYPAL_CONFIG_CHECK.md文档,提供PayPal配置错误的解决方案
- 添加mt-pay/database/README_CUSTOMER_ORDER.md文档,说明客户订单表创建方法
- 提供详细的数据库表结构和SQL脚本执行指南
- 包含配置文件格式要求和调试方法说明
2025-12-23 16:03:24 +08:00
48dc5acddc refactor(config): 重构应用配置文件结构
- 将application.yml中的配置项按环境分离到对应配置文件
- 在application-dev.yml中添加服务器和应用配置
- 在application-prod.yml中添加生产环境支付配置
- 在application-test.yml中添加测试环境支付配置
- 删除application-paypal-example.yml示例文件
- 在主应用类中启用PingPong配置属性支持
- 更新配置文件激活方式为profiles模式
2025-12-23 16:03:10 +08:00
10 changed files with 5238 additions and 109 deletions

68
PAYPAL_CONFIG_CHECK.md Normal file
View File

@@ -0,0 +1,68 @@
# PayPal配置检查指南
## 错误信息
```
Username must not be null
```
这个错误表示PayPal的`clientId`Client ID配置为空。
## 问题原因
Spring Boot的`@ConfigurationProperties`在绑定配置时,需要确保:
1. 配置文件中的属性名格式正确
2. 配置类能够正确加载
3. 配置文件被正确读取
## 解决方案
### 1. 检查配置文件
确保 `application-dev.yml` 中有以下配置:
```yaml
paypal:
client-id: AdGYUZpvLuHR30dybOApvM-RNB1pVKtd74SVfh-6TK52xV-1JEBddHVMCWuDdyyHri4DXd4kABBi7Icb
client-secret: ENblspyRmwsOU_PWFurlhEYUF5Da6aYKl0pjK4ehm7p3R5aSqvbpaF_YsIIs8v0ty1c9WJu15XP-Fe_1
mode: sandbox
enabled: true
```
### 2. 检查Spring Boot配置
确保主应用类或配置类启用了配置属性绑定。
### 3. 重启应用
修改配置后,**必须重启应用**才能生效。
### 4. 验证配置加载
启动应用后检查日志中是否有PayPal配置相关的错误信息。
## 配置属性映射
Spring Boot会自动将以下格式进行映射
- `client-id` (kebab-case) → `clientId` (camelCase)
- `client-secret` (kebab-case) → `clientSecret` (camelCase)
## 调试方法
如果配置仍然无法加载,可以:
1. **添加启动日志**:在`PayPalProperties`类中添加`@PostConstruct`方法打印配置值
2. **检查环境变量**:确认使用的是`dev`环境(`spring.profiles.active=dev`
3. **检查配置文件位置**:确保`application-dev.yml``src/main/resources`目录下
## 临时解决方案
如果配置仍然无法加载,可以在代码中临时硬编码(仅用于测试):
```java
// 仅用于测试,生产环境必须使用配置文件
if (clientId == null) {
clientId = "AdGYUZpvLuHR30dybOApvM-RNB1pVKtd74SVfh-6TK52xV-1JEBddHVMCWuDdyyHri4DXd4kABBi7Icb";
clientSecret = "ENblspyRmwsOU_PWFurlhEYUF5Da6aYKl0pjK4ehm7p3R5aSqvbpaF_YsIIs8v0ty1c9WJu15XP-Fe_1";
}
```

File diff suppressed because it is too large Load Diff

3655
logs/mt-pay.2025-12-23.log Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,111 @@
# 客户订单表创建说明
## 问题
如果遇到错误:`Table 'mtpay.customer_order' doesn't exist`
说明数据库中没有 `customer_order`需要执行SQL脚本创建。
## 解决方案
### 方法1使用MySQL客户端执行推荐
1. 连接到数据库:
```bash
mysql -h rm-j6c3u06k2afwn8hxw6o.mysql.rds.aliyuncs.com -P 3306 -u mtkj2025 -p mtpay
```
2. 执行SQL脚本
```sql
source E:/MTKJPAY/mt-pay/database/customer_order_schema.sql
```
或者直接复制SQL内容执行
```sql
CREATE TABLE `customer_order` (
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`order_no` VARCHAR(64) NOT NULL UNIQUE COMMENT '订单号(全局唯一)',
`product_id` BIGINT NOT NULL COMMENT '商品ID',
`product_name` VARCHAR(500) NOT NULL COMMENT '商品名称',
`sku_id` BIGINT NOT NULL COMMENT 'SKU ID',
`sku_name` VARCHAR(500) NOT NULL COMMENT 'SKU名称/描述',
`quantity` INT NOT NULL COMMENT '购买数量',
`unit_price` DECIMAL(10, 2) NOT NULL COMMENT '单价',
`total_amount` DECIMAL(10, 2) NOT NULL COMMENT '订单总金额',
`currency` VARCHAR(3) NOT NULL COMMENT '货币代码',
`status` VARCHAR(20) NOT NULL DEFAULT 'PENDING' COMMENT '订单状态PENDING-待支付PAID-已支付SHIPPED-已发货COMPLETED-已完成CANCELLED-已取消',
-- 客户信息
`customer_name` VARCHAR(100) NOT NULL COMMENT '客户姓名',
`customer_phone` VARCHAR(20) NOT NULL COMMENT '客户电话',
`customer_email` VARCHAR(100) COMMENT '客户邮箱',
-- 收货地址
`shipping_name` VARCHAR(100) NOT NULL COMMENT '收货人姓名',
`shipping_phone` VARCHAR(20) NOT NULL COMMENT '收货人电话',
`shipping_country` VARCHAR(50) NOT NULL COMMENT '收货国家',
`shipping_state` VARCHAR(50) COMMENT '收货州/省',
`shipping_city` VARCHAR(50) NOT NULL COMMENT '收货城市',
`shipping_street` VARCHAR(200) NOT NULL COMMENT '收货街道地址',
`shipping_postcode` VARCHAR(20) COMMENT '收货邮编',
-- 支付信息
`payment_order_id` BIGINT COMMENT '关联的支付订单ID',
`payment_status` VARCHAR(20) DEFAULT 'UNPAID' COMMENT '支付状态UNPAID-未支付PAID-已支付FAILED-支付失败',
-- 备注
`remark` VARCHAR(500) COMMENT '订单备注',
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_order_no` (`order_no`),
KEY `idx_product_id` (`product_id`),
KEY `idx_status` (`status`),
KEY `idx_create_time` (`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='客户订单表';
```
### 方法2使用数据库管理工具
使用Navicat、DBeaver、MySQL Workbench等工具
1. 连接到数据库 `mtpay`
2. 打开SQL编辑器
3. 复制 `customer_order_schema.sql` 文件内容
4. 执行SQL脚本
### 方法3使用命令行Windows PowerShell
```powershell
# 读取SQL文件内容
$sql = Get-Content "E:\MTKJPAY\mt-pay\database\customer_order_schema.sql" -Raw
# 执行SQL需要先安装mysql客户端
mysql -h rm-j6c3u06k2afwn8hxw6o.mysql.rds.aliyuncs.com -P 3306 -u mtkj2025 -p mtpay -e $sql
```
## 验证
执行完成后,可以验证表是否创建成功:
```sql
-- 查看表是否存在
SHOW TABLES LIKE 'customer_order';
-- 查看表结构
DESC customer_order;
-- 或者
SHOW CREATE TABLE customer_order;
```
## 注意事项
1. 确保数据库连接信息正确
2. 确保有创建表的权限
3. 如果表已存在,可以先删除再创建:
```sql
DROP TABLE IF EXISTS `customer_order`;
```
然后重新执行创建脚本

View File

@@ -1,12 +1,15 @@
package com.mtkj.mtpay; package com.mtkj.mtpay;
import com.mtkj.mtpay.config.PingPongProperties;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
@Slf4j @Slf4j
@SpringBootApplication @SpringBootApplication
@EnableConfigurationProperties({PingPongProperties.class})
public class MtPayApplication { public class MtPayApplication {
public static void main(String[] args) { public static void main(String[] args) {

View File

@@ -60,10 +60,44 @@ spring:
config: config:
multi-statement-allow: true multi-statement-allow: true
# 服务器配置(所有环境通用)
server:
port: 8082
servlet:
context-path: /
# 文件上传配置
multipart:
# 单个文件最大大小10MB
max-file-size: 10MB
# 请求最大大小50MB支持多文件上传
max-request-size: 50MB
# 文件写入磁盘的阈值(超过此大小会写入临时文件)
file-size-threshold: 2MB
# 应用配置(所有环境通用)
app:
# 前端访问地址用于生成商品详情页URL等
frontend:
url: http://localhost:3000
# 阿里云OSS相关配置所有环境通用
aliyun:
oss:
accessId: LTAI5tHbwvzWfANvNxju2yN1
accessKey: sAQR2swByBgmMOofH97hSJT638aVcJ
endpoint: https://oss-cn-hangzhou.aliyuncs.com
bucketName: mtkj2025
# PingPong支付配置开发环境使用沙箱 # PingPong支付配置开发环境使用沙箱
pingpong: pingpong:
client-id: your-client-id
acc-id: your-acc-id
secret: your-secret-key
sign-type: MD5
gateway: https://sandbox-acquirer-payment.pingpongx.com gateway: https://sandbox-acquirer-payment.pingpongx.com
mode: sandbox mode: sandbox
enabled: false
# PayPal支付配置开发环境使用沙箱 # PayPal支付配置开发环境使用沙箱
paypal: paypal:
@@ -76,3 +110,4 @@ paypal:
# 是否启用PayPal支付 # 是否启用PayPal支付
enabled: true enabled: true

View File

@@ -1,13 +0,0 @@
# PayPal支付配置示例
# 请将以下配置添加到你的application.yml或application-dev.yml中
paypal:
# PayPal Client ID从PayPal开发者控制台获取
client-id: YOUR_CLIENT_ID
# PayPal Client Secret从PayPal开发者控制台获取
client-secret: YOUR_CLIENT_SECRET
# 环境模式sandbox沙箱或 production生产
mode: sandbox
# 是否启用PayPal支付
enabled: true

View File

@@ -62,6 +62,22 @@ spring:
# PingPong支付配置生产环境 # PingPong支付配置生产环境
pingpong: pingpong:
client-id: ${pingpong.client-id}
acc-id: ${pingpong.acc-id}
secret: ${pingpong.secret}
sign-type: MD5
gateway: https://acquirer-payment.pingpongx.com gateway: https://acquirer-payment.pingpongx.com
mode: build mode: build
enabled: false
# PayPal支付配置生产环境
paypal:
# PayPal Client IDAPI密钥- 从环境变量或配置中心获取
client-id: AdGYUZpvLuHR30dybOApvM-RNB1pVKtd74SVfh-6TK52xV-1JEBddHVMCWuDdyyHri4DXd4kABBi7Icb
# PayPal Client Secret密钥- 从环境变量或配置中心获取
client-secret: ENblspyRmwsOU_PWFurlhEYUF5Da6aYKl0pjK4ehm7p3R5aSqvbpaF_YsIIs8v0ty1c9WJu15XP-Fe_1
# 环境模式sandbox沙箱或 production生产
mode: sandbox
# 是否启用PayPal支付
enabled: true

View File

@@ -62,6 +62,21 @@ spring:
# PingPong支付配置测试环境 # PingPong支付配置测试环境
pingpong: pingpong:
client-id: ${pingpong.client-id}
acc-id: ${pingpong.acc-id}
secret: ${pingpong.secret}
sign-type: MD5
gateway: https://sandbox-acquirer-payment.pingpongx.com gateway: https://sandbox-acquirer-payment.pingpongx.com
mode: test mode: test
enabled: false
# PayPal支付配置测试环境
paypal:
# PayPal Client IDAPI密钥
client-id: AdGYUZpvLuHR30dybOApvM-RNB1pVKtd74SVfh-6TK52xV-1JEBddHVMCWuDdyyHri4DXd4kABBi7Icb
# PayPal Client Secret密钥
client-secret: ENblspyRmwsOU_PWFurlhEYUF5Da6aYKl0pjK4ehm7p3R5aSqvbpaF_YsIIs8v0ty1c9WJu15XP-Fe_1
# 环境模式sandbox沙箱或 production生产
mode: sandbox
# 是否启用PayPal支付
enabled: true

View File

@@ -1,99 +1,5 @@
spring: spring:
application: profiles:
name: mt-pay active: dev
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
druid:
# 从库数据源
slave:
# 从数据源开关/默认关闭
enabled: false
url:
username:
password:
# Druid监控配置
web-stat-filter:
enabled: true
stat-view-servlet:
enabled: true
# 设置白名单,不填则允许所有访问
allow:
url-pattern: /druid/*
# 控制台管理用户名和密码
login-username: ruoyi
login-password: 123456
filter:
stat:
enabled: true
# 慢SQL记录
log-slow-sql: false
slow-sql-millis: 1000
merge-sql: true
wall:
config:
multi-statement-allow: true
# MyBatis-Plus配置
mybatis-plus:
# 配置扫描mapper.xml文件路径
mapper-locations: classpath*:/mapper/**/*.xml
# 配置实体类包路径
type-aliases-package: com.mtkj.mtpay.entity
# 配置MyBatis-Plus全局配置
configuration:
# 开启驼峰命名转换
map-underscore-to-camel-case: true
# 开启二级缓存
cache-enabled: false
# 日志实现
log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
# 全局配置
global-config:
db-config:
# 主键类型AUTO-数据库自增
id-type: auto
# 逻辑删除字段
logic-delete-field: deleted
# 逻辑删除值
logic-delete-value: 1
# 逻辑未删除值
logic-not-delete-value: 0
# PingPong支付配置
pingpong:
client-id: your-client-id
acc-id: your-acc-id
secret: your-secret-key
sign-type: MD5
gateway: https://sandbox-acquirer-payment.pingpongx.com
mode: sandbox
enabled: true
# 服务器配置
server:
port: 8082
servlet:
context-path: /
# 文件上传配置
multipart:
# 单个文件最大大小10MB
max-file-size: 10MB
# 请求最大大小50MB支持多文件上传
max-request-size: 50MB
# 文件写入磁盘的阈值(超过此大小会写入临时文件)
file-size-threshold: 2MB
# 应用配置
app:
# 前端访问地址用于生成商品详情页URL等
frontend:
url: http://localhost:3000
# 阿里云OSS相关配置
aliyun:
oss:
accessId: LTAI5tHbwvzWfANvNxju2yN1
accessKey: sAQR2swByBgmMOofH97hSJT638aVcJ
endpoint: https://oss-cn-hangzhou.aliyuncs.com
bucketName: mtkj2025