feat(payment): 初始化支付模块核心代码
- 添加支付常量类PaymentConstants,定义支付状态、微信、支付宝、银联等相关常量 - 创建微信支付类型常量类WechatPayType,支持JSAPI、NATIVE、H5、APP支付方式 - 新增支付控制器PaymentController,提供创建支付、查询状态、退款等统一接口 - 实现支付回调控制器PaymentNotifyController,处理微信、支付宝、银联异步通知 - 添加支付请求数据传输对象PaymentRequest,支持多种支付方式参数校验 - 定义支付响应、状态更新请求等相关DTO类- 集成Swagger注解,完善接口文档说明- 添加参数校验和异常处理机制,确保支付流程安全可靠
This commit is contained in:
159
java/payment/enums/PaymentChannel.java
Normal file
159
java/payment/enums/PaymentChannel.java
Normal 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);
|
||||
}
|
||||
}
|
||||
141
java/payment/enums/PaymentStatus.java
Normal file
141
java/payment/enums/PaymentStatus.java
Normal file
@@ -0,0 +1,141 @@
|
||||
package com.gxwebsoft.payment.enums;
|
||||
|
||||
/**
|
||||
* 支付状态枚举
|
||||
* 定义支付过程中的各种状态
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2025-01-26
|
||||
*/
|
||||
public enum PaymentStatus {
|
||||
|
||||
/** 待支付 */
|
||||
PENDING(0, "待支付", "PENDING"),
|
||||
|
||||
/** 支付中 */
|
||||
PROCESSING(1, "支付中", "PROCESSING"),
|
||||
|
||||
/** 支付成功 */
|
||||
SUCCESS(2, "支付成功", "SUCCESS"),
|
||||
|
||||
/** 支付失败 */
|
||||
FAILED(3, "支付失败", "FAILED"),
|
||||
|
||||
/** 支付取消 */
|
||||
CANCELLED(4, "支付取消", "CANCELLED"),
|
||||
|
||||
/** 支付超时 */
|
||||
TIMEOUT(5, "支付超时", "TIMEOUT"),
|
||||
|
||||
/** 退款中 */
|
||||
REFUNDING(6, "退款中", "REFUNDING"),
|
||||
|
||||
/** 退款成功 */
|
||||
REFUNDED(7, "退款成功", "REFUNDED"),
|
||||
|
||||
/** 退款失败 */
|
||||
REFUND_FAILED(8, "退款失败", "REFUND_FAILED"),
|
||||
|
||||
/** 部分退款 */
|
||||
PARTIAL_REFUNDED(9, "部分退款", "PARTIAL_REFUNDED");
|
||||
|
||||
private final Integer code;
|
||||
private final String name;
|
||||
private final String status;
|
||||
|
||||
PaymentStatus(Integer code, String name, String status) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据代码获取支付状态
|
||||
*/
|
||||
public static PaymentStatus getByCode(Integer code) {
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
for (PaymentStatus status : values()) {
|
||||
if (status.code.equals(code)) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据状态字符串获取支付状态
|
||||
*/
|
||||
public static PaymentStatus getByStatus(String status) {
|
||||
if (status == null) {
|
||||
return null;
|
||||
}
|
||||
for (PaymentStatus paymentStatus : values()) {
|
||||
if (paymentStatus.status.equals(status)) {
|
||||
return paymentStatus;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为最终状态(不会再变化)
|
||||
*/
|
||||
public boolean isFinalStatus() {
|
||||
return this == SUCCESS || this == FAILED || this == CANCELLED ||
|
||||
this == TIMEOUT || this == REFUNDED || this == REFUND_FAILED;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为成功状态
|
||||
*/
|
||||
public boolean isSuccessStatus() {
|
||||
return this == SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为失败状态
|
||||
*/
|
||||
public boolean isFailedStatus() {
|
||||
return this == FAILED || this == CANCELLED || this == TIMEOUT || this == REFUND_FAILED;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为退款相关状态
|
||||
*/
|
||||
public boolean isRefundStatus() {
|
||||
return this == REFUNDING || this == REFUNDED || this == REFUND_FAILED || this == PARTIAL_REFUNDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否可以退款
|
||||
*/
|
||||
public boolean canRefund() {
|
||||
return this == SUCCESS || this == PARTIAL_REFUNDED;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否可以取消
|
||||
*/
|
||||
public boolean canCancel() {
|
||||
return this == PENDING || this == PROCESSING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("PaymentStatus{code=%d, name='%s', status='%s'}", code, name, status);
|
||||
}
|
||||
}
|
||||
224
java/payment/enums/PaymentType.java
Normal file
224
java/payment/enums/PaymentType.java
Normal file
@@ -0,0 +1,224 @@
|
||||
package com.gxwebsoft.payment.enums;
|
||||
|
||||
/**
|
||||
* 支付类型枚举
|
||||
* 定义系统支持的所有支付方式
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2025-01-26
|
||||
*/
|
||||
public enum PaymentType {
|
||||
|
||||
/** 余额支付 */
|
||||
BALANCE(0, "余额支付", "balance"),
|
||||
|
||||
/** 微信支付(包含JSAPI和Native) */
|
||||
WECHAT(1, "微信支付", "wechat"),
|
||||
|
||||
/** 支付宝支付 */
|
||||
ALIPAY(2, "支付宝支付", "alipay"),
|
||||
|
||||
/** 银联支付 */
|
||||
UNION_PAY(3, "银联支付", "union_pay"),
|
||||
|
||||
/** 现金支付 */
|
||||
CASH(4, "现金支付", "cash"),
|
||||
|
||||
/** POS机支付 */
|
||||
POS(5, "POS机支付", "pos"),
|
||||
|
||||
/** 免费 */
|
||||
FREE(6, "免费", "free"),
|
||||
|
||||
/** 积分支付 */
|
||||
POINTS(7, "积分支付", "points"),
|
||||
|
||||
// ========== 已废弃的支付方式(保留用于数据兼容) ==========
|
||||
|
||||
/** @deprecated 微信Native支付 - 已合并到WECHAT */
|
||||
@Deprecated
|
||||
WECHAT_NATIVE(102, "微信Native支付", "wechat_native"),
|
||||
|
||||
/** @deprecated 会员卡支付 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
MEMBER_CARD_OLD(8, "会员卡支付", "member_card"),
|
||||
|
||||
/** @deprecated VIP月卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
VIP_MONTHLY(9, "VIP月卡", "vip_monthly"),
|
||||
|
||||
/** @deprecated VIP年卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
VIP_YEARLY(10, "VIP年卡", "vip_yearly"),
|
||||
|
||||
/** @deprecated VIP次卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
VIP_COUNT(11, "VIP次卡", "vip_count"),
|
||||
|
||||
/** @deprecated 免费(旧编号) - 已迁移到新编号6 */
|
||||
@Deprecated
|
||||
FREE_OLD(12, "免费", "free"),
|
||||
|
||||
/** @deprecated VIP充值卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
VIP_RECHARGE(13, "VIP充值卡", "vip_recharge"),
|
||||
|
||||
/** @deprecated IC充值卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
IC_RECHARGE(14, "IC充值卡", "ic_recharge"),
|
||||
|
||||
/** @deprecated 积分支付(旧编号) - 已迁移到新编号7 */
|
||||
@Deprecated
|
||||
POINTS_OLD(15, "积分支付", "points"),
|
||||
|
||||
/** @deprecated VIP季卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
VIP_QUARTERLY(16, "VIP季卡", "vip_quarterly"),
|
||||
|
||||
/** @deprecated IC月卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
IC_MONTHLY(17, "IC月卡", "ic_monthly"),
|
||||
|
||||
/** @deprecated IC年卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
IC_YEARLY(18, "IC年卡", "ic_yearly"),
|
||||
|
||||
/** @deprecated IC次卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
IC_COUNT(19, "IC次卡", "ic_count"),
|
||||
|
||||
/** @deprecated IC季卡 - 建议使用余额支付 */
|
||||
@Deprecated
|
||||
IC_QUARTERLY(20, "IC季卡", "ic_quarterly"),
|
||||
|
||||
/** @deprecated 代付 - 建议通过业务逻辑实现 */
|
||||
@Deprecated
|
||||
PROXY_PAY(21, "代付", "proxy_pay"),
|
||||
|
||||
/** @deprecated 支付宝(旧编号) - 已迁移到新编号2 */
|
||||
@Deprecated
|
||||
ALIPAY_OLD(22, "支付宝支付", "alipay"),
|
||||
|
||||
/** @deprecated 银联支付(旧编号) - 已迁移到新编号3 */
|
||||
@Deprecated
|
||||
UNION_PAY_OLD(23, "银联支付", "union_pay");
|
||||
|
||||
private final Integer code;
|
||||
private final String name;
|
||||
private final String channel;
|
||||
|
||||
PaymentType(Integer code, String name, String channel) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据代码获取支付类型
|
||||
*/
|
||||
public static PaymentType getByCode(Integer code) {
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
for (PaymentType type : values()) {
|
||||
if (type.code.equals(code)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据渠道获取支付类型
|
||||
*/
|
||||
public static PaymentType getByChannel(String channel) {
|
||||
if (channel == null) {
|
||||
return null;
|
||||
}
|
||||
for (PaymentType type : values()) {
|
||||
if (type.channel.equals(channel)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为微信支付类型
|
||||
*/
|
||||
public boolean isWechatPay() {
|
||||
return this == WECHAT || this == WECHAT_NATIVE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信支付的具体类型
|
||||
* @param openid 用户openid
|
||||
* @return JSAPI 或 NATIVE
|
||||
*/
|
||||
public String getWechatPayType(String openid) {
|
||||
if (!isWechatPay()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 有openid使用JSAPI,无openid使用Native
|
||||
return (openid != null && !openid.trim().isEmpty()) ? "JSAPI" : "NATIVE";
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为第三方支付
|
||||
*/
|
||||
public boolean isThirdPartyPay() {
|
||||
return isWechatPay() || this == ALIPAY || this == UNION_PAY;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否需要在线支付
|
||||
*/
|
||||
public boolean isOnlinePay() {
|
||||
return isThirdPartyPay();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为卡类支付(已废弃的支付方式)
|
||||
* @deprecated 卡类支付已废弃,建议使用余额支付
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isCardPay() {
|
||||
return this == MEMBER_CARD_OLD ||
|
||||
this == VIP_MONTHLY || this == VIP_YEARLY || this == VIP_COUNT || this == VIP_QUARTERLY ||
|
||||
this == IC_MONTHLY || this == IC_YEARLY || this == IC_COUNT || this == IC_QUARTERLY ||
|
||||
this == VIP_RECHARGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为推荐使用的核心支付方式
|
||||
*/
|
||||
public boolean isCorePaymentType() {
|
||||
return this == BALANCE || this == WECHAT || this == ALIPAY || this == UNION_PAY ||
|
||||
this == CASH || this == POS || this == FREE || this == POINTS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为已废弃的支付方式
|
||||
*/
|
||||
public boolean isDeprecated() {
|
||||
return !isCorePaymentType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("PaymentType{code=%d, name='%s', channel='%s'}", code, name, channel);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user