- 添加支付常量类PaymentConstants,定义支付状态、微信、支付宝、银联等相关常量 - 创建微信支付类型常量类WechatPayType,支持JSAPI、NATIVE、H5、APP支付方式 - 新增支付控制器PaymentController,提供创建支付、查询状态、退款等统一接口 - 实现支付回调控制器PaymentNotifyController,处理微信、支付宝、银联异步通知 - 添加支付请求数据传输对象PaymentRequest,支持多种支付方式参数校验 - 定义支付响应、状态更新请求等相关DTO类- 集成Swagger注解,完善接口文档说明- 添加参数校验和异常处理机制,确保支付流程安全可靠
245 lines
8.8 KiB
Java
245 lines
8.8 KiB
Java
package com.gxwebsoft.payment.constants;
|
|
|
|
/**
|
|
* 支付模块常量类
|
|
* 统一管理支付相关的常量配置
|
|
*
|
|
* @author 科技小王子
|
|
* @since 2025-01-26
|
|
*/
|
|
public class PaymentConstants {
|
|
|
|
/**
|
|
* 支付状态常量
|
|
*/
|
|
public static class Status {
|
|
/** 待支付 */
|
|
public static final String PENDING = "PENDING";
|
|
/** 支付成功 */
|
|
public static final String SUCCESS = "SUCCESS";
|
|
/** 支付失败 */
|
|
public static final String FAILED = "FAILED";
|
|
/** 支付取消 */
|
|
public static final String CANCELLED = "CANCELLED";
|
|
/** 支付超时 */
|
|
public static final String TIMEOUT = "TIMEOUT";
|
|
/** 退款成功 */
|
|
public static final String REFUNDED = "REFUNDED";
|
|
}
|
|
|
|
/**
|
|
* 微信支付相关常量
|
|
*/
|
|
public static class Wechat {
|
|
/** 货币类型 */
|
|
public static final String CURRENCY = "CNY";
|
|
/** 金额转换倍数(元转分) */
|
|
public static final int AMOUNT_MULTIPLIER = 100;
|
|
|
|
/** 支付状态 */
|
|
public static final String PAY_SUCCESS = "SUCCESS";
|
|
public static final String PAY_REFUND = "REFUND";
|
|
public static final String PAY_NOTPAY = "NOTPAY";
|
|
public static final String PAY_CLOSED = "CLOSED";
|
|
public static final String PAY_REVOKED = "REVOKED";
|
|
public static final String PAY_USERPAYING = "USERPAYING";
|
|
public static final String PAY_PAYERROR = "PAYERROR";
|
|
|
|
/** 回调响应 */
|
|
public static final String NOTIFY_SUCCESS = "SUCCESS";
|
|
public static final String NOTIFY_FAIL = "FAIL";
|
|
|
|
/** 通知类型 */
|
|
public static final String EVENT_PAYMENT = "TRANSACTION.SUCCESS";
|
|
public static final String EVENT_REFUND = "REFUND.SUCCESS";
|
|
|
|
/** HTTP头部 */
|
|
public static final String HEADER_SIGNATURE = "Wechatpay-Signature";
|
|
public static final String HEADER_TIMESTAMP = "Wechatpay-Timestamp";
|
|
public static final String HEADER_NONCE = "Wechatpay-Nonce";
|
|
public static final String HEADER_SERIAL = "Wechatpay-Serial";
|
|
public static final String HEADER_REQUEST_ID = "Request-ID";
|
|
}
|
|
|
|
/**
|
|
* 支付宝相关常量
|
|
*/
|
|
public static class Alipay {
|
|
/** 货币类型 */
|
|
public static final String CURRENCY = "CNY";
|
|
|
|
/** 支付状态 */
|
|
public static final String PAY_SUCCESS = "TRADE_SUCCESS";
|
|
public static final String PAY_FINISHED = "TRADE_FINISHED";
|
|
public static final String PAY_CLOSED = "TRADE_CLOSED";
|
|
|
|
/** 回调响应 */
|
|
public static final String NOTIFY_SUCCESS = "success";
|
|
public static final String NOTIFY_FAIL = "failure";
|
|
|
|
/** 产品码 */
|
|
public static final String PRODUCT_CODE_WEB = "FAST_INSTANT_TRADE_PAY";
|
|
public static final String PRODUCT_CODE_WAP = "QUICK_WAP_WAY";
|
|
public static final String PRODUCT_CODE_APP = "QUICK_MSECURITY_PAY";
|
|
}
|
|
|
|
/**
|
|
* 银联支付相关常量
|
|
*/
|
|
public static class UnionPay {
|
|
/** 货币类型 */
|
|
public static final String CURRENCY = "156"; // 人民币代码
|
|
|
|
/** 支付状态 */
|
|
public static final String PAY_SUCCESS = "00";
|
|
public static final String PAY_FAILED = "01";
|
|
|
|
/** 交易类型 */
|
|
public static final String TXN_TYPE_CONSUME = "01"; // 消费
|
|
public static final String TXN_TYPE_REFUND = "04"; // 退货
|
|
}
|
|
|
|
/**
|
|
* 缓存键常量
|
|
*/
|
|
public static class CacheKey {
|
|
/** 支付配置缓存前缀 */
|
|
public static final String PAYMENT_CONFIG = "payment:config:";
|
|
/** 支付订单缓存前缀 */
|
|
public static final String PAYMENT_ORDER = "payment:order:";
|
|
/** 支付锁前缀 */
|
|
public static final String PAYMENT_LOCK = "payment:lock:";
|
|
/** 回调处理锁前缀 */
|
|
public static final String NOTIFY_LOCK = "payment:notify:lock:";
|
|
}
|
|
|
|
/**
|
|
* 配置相关常量
|
|
*/
|
|
public static class Config {
|
|
/** 订单超时时间(分钟) */
|
|
public static final int ORDER_TIMEOUT_MINUTES = 30;
|
|
/** 订单描述最大长度 */
|
|
public static final int DESCRIPTION_MAX_LENGTH = 127;
|
|
/** 最大重试次数 */
|
|
public static final int MAX_RETRY_COUNT = 3;
|
|
/** 重试间隔(毫秒) */
|
|
public static final long RETRY_INTERVAL_MS = 1000;
|
|
/** 签名有效期(秒) */
|
|
public static final long SIGNATURE_VALID_SECONDS = 300;
|
|
}
|
|
|
|
/**
|
|
* 错误信息常量
|
|
*/
|
|
public static class ErrorMessage {
|
|
/** 参数错误 */
|
|
public static final String PARAM_ERROR = "参数错误";
|
|
/** 配置未找到 */
|
|
public static final String CONFIG_NOT_FOUND = "支付配置未找到";
|
|
/** 支付方式不支持 */
|
|
public static final String PAYMENT_TYPE_NOT_SUPPORTED = "支付方式不支持";
|
|
/** 金额错误 */
|
|
public static final String AMOUNT_ERROR = "金额错误";
|
|
/** 订单不存在 */
|
|
public static final String ORDER_NOT_FOUND = "订单不存在";
|
|
/** 订单状态错误 */
|
|
public static final String ORDER_STATUS_ERROR = "订单状态错误";
|
|
/** 签名验证失败 */
|
|
public static final String SIGNATURE_ERROR = "签名验证失败";
|
|
/** 网络请求失败 */
|
|
public static final String NETWORK_ERROR = "网络请求失败";
|
|
/** 系统内部错误 */
|
|
public static final String SYSTEM_ERROR = "系统内部错误";
|
|
/** 余额不足 */
|
|
public static final String INSUFFICIENT_BALANCE = "余额不足";
|
|
/** 支付超时 */
|
|
public static final String PAYMENT_TIMEOUT = "支付超时";
|
|
/** 重复支付 */
|
|
public static final String DUPLICATE_PAYMENT = "重复支付";
|
|
}
|
|
|
|
/**
|
|
* 日志消息常量
|
|
*/
|
|
public static class LogMessage {
|
|
/** 支付请求开始 */
|
|
public static final String PAYMENT_START = "开始处理支付请求";
|
|
/** 支付请求成功 */
|
|
public static final String PAYMENT_SUCCESS = "支付请求处理成功";
|
|
/** 支付请求失败 */
|
|
public static final String PAYMENT_FAILED = "支付请求处理失败";
|
|
|
|
/** 回调处理开始 */
|
|
public static final String NOTIFY_START = "开始处理支付回调";
|
|
/** 回调处理成功 */
|
|
public static final String NOTIFY_SUCCESS = "支付回调处理成功";
|
|
/** 回调处理失败 */
|
|
public static final String NOTIFY_FAILED = "支付回调处理失败";
|
|
|
|
/** 退款请求开始 */
|
|
public static final String REFUND_START = "开始处理退款请求";
|
|
/** 退款请求成功 */
|
|
public static final String REFUND_SUCCESS = "退款请求处理成功";
|
|
/** 退款请求失败 */
|
|
public static final String REFUND_FAILED = "退款请求处理失败";
|
|
}
|
|
|
|
/**
|
|
* 正则表达式常量
|
|
*/
|
|
public static class Regex {
|
|
/** 订单号格式 */
|
|
public static final String ORDER_NO = "^[a-zA-Z0-9_-]{1,32}$";
|
|
/** 金额格式(分) */
|
|
public static final String AMOUNT = "^[1-9]\\d*$";
|
|
/** 手机号格式 */
|
|
public static final String MOBILE = "^1[3-9]\\d{9}$";
|
|
/** 邮箱格式 */
|
|
public static final String EMAIL = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
|
|
}
|
|
|
|
/**
|
|
* 时间相关常量
|
|
*/
|
|
public static class Time {
|
|
/** 配置缓存有效期(秒) */
|
|
public static final long CONFIG_CACHE_SECONDS = 3600;
|
|
/** 订单缓存有效期(秒) */
|
|
public static final long ORDER_CACHE_SECONDS = 1800;
|
|
/** 支付锁有效期(秒) */
|
|
public static final long PAYMENT_LOCK_SECONDS = 60;
|
|
/** 回调锁有效期(秒) */
|
|
public static final long NOTIFY_LOCK_SECONDS = 30;
|
|
}
|
|
|
|
/**
|
|
* 文件相关常量
|
|
*/
|
|
public static class File {
|
|
/** 证书文件扩展名 */
|
|
public static final String CERT_EXTENSION = ".pem";
|
|
/** 私钥文件后缀 */
|
|
public static final String PRIVATE_KEY_SUFFIX = "_key.pem";
|
|
/** 公钥文件后缀 */
|
|
public static final String PUBLIC_KEY_SUFFIX = "_cert.pem";
|
|
}
|
|
|
|
/**
|
|
* 环境相关常量
|
|
*/
|
|
public static class Environment {
|
|
/** 开发环境 */
|
|
public static final String DEV = "dev";
|
|
/** 测试环境 */
|
|
public static final String TEST = "test";
|
|
/** 生产环境 */
|
|
public static final String PROD = "prod";
|
|
}
|
|
|
|
// 私有构造函数,防止实例化
|
|
private PaymentConstants() {
|
|
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
|
}
|
|
}
|