feat(payment): 初始化支付模块核心代码

- 添加支付常量类PaymentConstants,定义支付状态、微信、支付宝、银联等相关常量
- 创建微信支付类型常量类WechatPayType,支持JSAPI、NATIVE、H5、APP支付方式
- 新增支付控制器PaymentController,提供创建支付、查询状态、退款等统一接口
- 实现支付回调控制器PaymentNotifyController,处理微信、支付宝、银联异步通知
- 添加支付请求数据传输对象PaymentRequest,支持多种支付方式参数校验
- 定义支付响应、状态更新请求等相关DTO类- 集成Swagger注解,完善接口文档说明- 添加参数校验和异常处理机制,确保支付流程安全可靠
This commit is contained in:
2025-11-03 12:31:47 +08:00
parent 894b4bf7ce
commit 5749fab9e8
25 changed files with 4952 additions and 9 deletions

View File

@@ -0,0 +1,159 @@
package com.gxwebsoft.payment.enums;
/**
* 支付渠道枚举
* 定义具体的支付渠道类型
*
* @author 科技小王子
* @since 2025-01-26
*/
public enum PaymentChannel {
/** 微信JSAPI支付 */
WECHAT_JSAPI("wechat_jsapi", "微信JSAPI支付", PaymentType.WECHAT),
/** 微信Native支付 */
WECHAT_NATIVE("wechat_native", "微信Native支付", PaymentType.WECHAT_NATIVE),
/** 微信H5支付 */
WECHAT_H5("wechat_h5", "微信H5支付", PaymentType.WECHAT),
/** 微信APP支付 */
WECHAT_APP("wechat_app", "微信APP支付", PaymentType.WECHAT),
/** 微信小程序支付 */
WECHAT_MINI("wechat_mini", "微信小程序支付", PaymentType.WECHAT),
/** 支付宝网页支付 */
ALIPAY_WEB("alipay_web", "支付宝网页支付", PaymentType.ALIPAY),
/** 支付宝手机网站支付 */
ALIPAY_WAP("alipay_wap", "支付宝手机网站支付", PaymentType.ALIPAY),
/** 支付宝APP支付 */
ALIPAY_APP("alipay_app", "支付宝APP支付", PaymentType.ALIPAY),
/** 支付宝小程序支付 */
ALIPAY_MINI("alipay_mini", "支付宝小程序支付", PaymentType.ALIPAY),
/** 银联网关支付 */
UNION_WEB("union_web", "银联网关支付", PaymentType.UNION_PAY),
/** 银联手机支付 */
UNION_WAP("union_wap", "银联手机支付", PaymentType.UNION_PAY),
/** 余额支付 */
BALANCE("balance", "余额支付", PaymentType.BALANCE),
/** 现金支付 */
CASH("cash", "现金支付", PaymentType.CASH),
/** POS机支付 */
POS("pos", "POS机支付", PaymentType.POS);
private final String code;
private final String name;
private final PaymentType paymentType;
PaymentChannel(String code, String name, PaymentType paymentType) {
this.code = code;
this.name = name;
this.paymentType = paymentType;
}
public String getCode() {
return code;
}
public String getName() {
return name;
}
public PaymentType getPaymentType() {
return paymentType;
}
/**
* 根据代码获取支付渠道
*/
public static PaymentChannel getByCode(String code) {
if (code == null) {
return null;
}
for (PaymentChannel channel : values()) {
if (channel.code.equals(code)) {
return channel;
}
}
return null;
}
/**
* 根据支付类型获取默认渠道
*/
public static PaymentChannel getDefaultByPaymentType(PaymentType paymentType) {
if (paymentType == null) {
return null;
}
switch (paymentType) {
case WECHAT:
return WECHAT_JSAPI;
case WECHAT_NATIVE:
return WECHAT_NATIVE;
case ALIPAY:
return ALIPAY_WEB;
case UNION_PAY:
return UNION_WEB;
case BALANCE:
return BALANCE;
case CASH:
return CASH;
case POS:
return POS;
default:
return null;
}
}
/**
* 是否为微信支付渠道
*/
public boolean isWechatChannel() {
return paymentType.isWechatPay();
}
/**
* 是否为支付宝支付渠道
*/
public boolean isAlipayChannel() {
return paymentType == PaymentType.ALIPAY;
}
/**
* 是否为银联支付渠道
*/
public boolean isUnionPayChannel() {
return paymentType == PaymentType.UNION_PAY;
}
/**
* 是否为第三方支付渠道
*/
public boolean isThirdPartyChannel() {
return paymentType.isThirdPartyPay();
}
/**
* 是否支持退款
*/
public boolean supportRefund() {
return isThirdPartyChannel();
}
@Override
public String toString() {
return String.format("PaymentChannel{code='%s', name='%s', paymentType=%s}",
code, name, paymentType);
}
}