3.1 KiB
3.1 KiB
携程API配置说明
配置结构
1. 配置文件位置
- 配置文件:
src/main/resources/application.yml
2. 配置项说明
spring:
# 环境配置:test(测试环境) / prod(生产环境)
profiles:
active: test
ctrip:
# AES加密配置
aes:
key: 087b36ad0dff7942 # AES密钥
iv: 750e15a31356a99d # AES IV
# API配置
api:
test-url: https://ttdopen.ctrip.com/api # 测试环境URL
prod-url: https://ttdentry.ctrip.com/ttd-connect-orderentryapi/supplier # 生产环境URL
environment: test # 当前环境:test/prod
timeout: 30000 # 请求超时时间(毫秒)
retry-times: 3 # 重试次数
# 账户配置
account:
id: c50a8f2a59c9e7 # 账户ID
secret: ce6033ae31124ec5cdab3d2bc79f2622 # 账户密钥
环境切换
1. 测试环境(默认)
# 使用默认配置(测试环境)
java -jar coupon-center.jar
2. 生产环境
# 使用生产环境配置
java -jar coupon-center.jar --spring.profiles.active=prod
或者在 application.yml 中设置:
spring:
profiles:
active: prod
URL配置说明
1. 测试环境
- 基础URL:
https://ttdopen.ctrip.com/api - 订单通知接口:
https://ttdopen.ctrip.com/api/order/notice.do
2. 生产环境
- 基础URL:
https://ttdentry.ctrip.com/ttd-connect-orderentryapi/supplier - 订单通知接口:
https://ttdentry.ctrip.com/ttd-connect-orderentryapi/supplier/order/notice.do
代码使用
1. 注入配置
@Autowired
private CtripApiConfig ctripApiConfig;
2. 获取URL
// 获取当前环境的订单通知URL
String url = ctripApiConfig.getApi().getOrderNoticeUrl();
// 获取当前环境的基础URL
String baseUrl = ctripApiConfig.getApi().getBaseUrl();
3. 获取账户信息
String accountId = ctripApiConfig.getAccount().getId();
String accountSecret = ctripApiConfig.getAccount().getSecret();
安全注意事项
- 生产环境密钥: 生产环境的AES密钥和账户密钥应该通过环境变量或配置中心管理
- 日志级别: 生产环境建议将敏感信息的日志级别设置为WARN或ERROR
- 网络访问: 确保服务器能够访问携程的API地址
- 超时配置: 根据网络情况调整timeout和retry-times参数
故障排查
1. 网络连接问题
# 测试网络连接
curl -I https://ttdentry.ctrip.com/ttd-connect-orderentryapi/supplier/order/notice.do
2. 配置验证
// 在启动时验证配置
@PostConstruct
public void validateConfig() {
log.info("当前环境: {}", ctripApiConfig.getApi().getEnvironment());
log.info("API URL: {}", ctripApiConfig.getApi().getOrderNoticeUrl());
}
3. 日志监控
logging:
level:
com.central.coupon.service.impl.CtripConsumedServiceImpl: DEBUG
com.central.coupon.util.CtripDecryptUtil: DEBUG