feat 异常体系完善

This commit is contained in:
DaxPay
2024-06-19 21:37:56 +08:00
parent bd11adee36
commit 777d691d71
40 changed files with 200 additions and 95 deletions

View File

@@ -4,7 +4,6 @@
- [x] 增加转账接口功能 - [x] 增加转账接口功能
- [ ] 转账订单功能 - [ ] 转账订单功能
- [ ] DEMO增加转账演示功能 - [ ] DEMO增加转账演示功能
- [ ] 转账同步接口
- [x] 手动发起分账重试参数修正 - [x] 手动发起分账重试参数修正
- [x] 细分各种支付异常类和编码(部分+初版) - [x] 细分各种支付异常类和编码(部分+初版)
- [x] 支付宝支持JSAPI方式支付 - [x] 支付宝支持JSAPI方式支付
@@ -53,6 +52,7 @@
- [ ] 聚合支付UA在前端判断, 提高响应速度 - [ ] 聚合支付UA在前端判断, 提高响应速度
- [ ] 增加分账回调处理(支付宝) - [ ] 增加分账回调处理(支付宝)
- [ ] 请求权限改版, 使用专用配置类 - [ ] 请求权限改版, 使用专用配置类
- [ ] 转账同步接口
**任务池** **任务池**
- [ ] 增加收单收银台功能 - [ ] 增加收单收银台功能

View File

@@ -1,4 +1,4 @@
package cn.daxpay.single.core.code; package cn.daxpay.single.sdk.code;
/** /**
* 公共错误码 * 公共错误码
@@ -73,5 +73,5 @@ public interface DaxPayCommonErrorCode {
int DATA_ERROR = 20091; int DATA_ERROR = 20091;
/** 未知异常,系统无法处理 */ /** 未知异常,系统无法处理 */
int SYSTEM_UNKNOWN_ERROR = 20000; int SYSTEM_UNKNOWN_ERROR = 30000;
} }

View File

@@ -34,7 +34,7 @@ public class PayOrderSyncTest {
param.setBizOrderNo("SDK_1715341621498"); param.setBizOrderNo("SDK_1715341621498");
DaxPayResult<PaySyncModel> execute = DaxPayKit.execute(param); DaxPayResult<PaySyncModel> execute = DaxPayKit.execute(param);
System.out.println(JSONUtil.toJsonStr(execute)); System.out.println(JSONUtil.toJsonStr(execute));
} }
} }

View File

@@ -51,6 +51,6 @@ public class PayOrderTest {
DaxPayResult<PayModel> execute = DaxPayKit.execute(param); DaxPayResult<PayModel> execute = DaxPayKit.execute(param);
System.out.println(JSONUtil.toJsonStr(execute)); System.out.println(JSONUtil.toJsonStr(execute));
} }
} }

View File

@@ -36,7 +36,7 @@ public class RefundOrderSyncTest {
param.setClientIp("127.0.0.1"); param.setClientIp("127.0.0.1");
DaxPayResult<RefundSyncModel> execute = DaxPayKit.execute(param); DaxPayResult<RefundSyncModel> execute = DaxPayKit.execute(param);
System.out.println(JSONUtil.toJsonStr(execute)); System.out.println(JSONUtil.toJsonStr(execute));
} }
} }

View File

@@ -47,7 +47,7 @@ public class RefundOrderTest {
DaxPayResult<RefundModel> execute = DaxPayKit.execute(param); DaxPayResult<RefundModel> execute = DaxPayKit.execute(param);
System.out.println(JSONUtil.toJsonStr(execute)); System.out.println(JSONUtil.toJsonStr(execute));
System.out.println(PaySignUtil.verifyHmacSha256Sign(execute.getData(), "123456", execute.getData().getSign())); System.out.println(PaySignUtil.verifyHmacSha256Sign(execute.getData(), "123456", execute.getData().getSign()));
} }

View File

@@ -37,6 +37,6 @@ public class QueryPayOrderTest {
DaxPayResult<PayOrderModel> execute = DaxPayKit.execute(param); DaxPayResult<PayOrderModel> execute = DaxPayKit.execute(param);
System.out.println(JSONUtil.toJsonStr(execute)); System.out.println(JSONUtil.toJsonStr(execute));
} }
} }

View File

@@ -37,6 +37,6 @@ public class QueryRefundOrderTest {
DaxPayResult<RefundOrderModel> execute = DaxPayKit.execute(param); DaxPayResult<RefundOrderModel> execute = DaxPayKit.execute(param);
System.out.println(JSONUtil.toJsonStr(execute)); System.out.println(JSONUtil.toJsonStr(execute));
} }
} }

View File

@@ -9,6 +9,7 @@ import cn.daxpay.single.core.param.payment.transfer.TransferParam;
import cn.daxpay.single.service.annotation.InitPaymentContext; import cn.daxpay.single.service.annotation.InitPaymentContext;
import cn.daxpay.single.service.core.order.transfer.service.TransferOrderQueryService; import cn.daxpay.single.service.core.order.transfer.service.TransferOrderQueryService;
import cn.daxpay.single.service.core.order.transfer.service.TransferOrderService; import cn.daxpay.single.service.core.order.transfer.service.TransferOrderService;
import cn.daxpay.single.service.core.payment.transfer.service.TransferService;
import cn.daxpay.single.service.dto.order.transfer.TransferOrderDto; import cn.daxpay.single.service.dto.order.transfer.TransferOrderDto;
import cn.daxpay.single.service.param.order.TransferOrderQuery; import cn.daxpay.single.service.param.order.TransferOrderQuery;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@@ -28,6 +29,7 @@ import org.springframework.web.bind.annotation.*;
public class TransferOrderController { public class TransferOrderController {
private final TransferOrderQueryService queryService; private final TransferOrderQueryService queryService;
private final TransferOrderService transferOrderService; private final TransferOrderService transferOrderService;
private final TransferService transferService;
@Operation(summary = "分页查询") @Operation(summary = "分页查询")
@@ -53,6 +55,7 @@ public class TransferOrderController {
@Operation(summary = "手动发起转账") @Operation(summary = "手动发起转账")
@PostMapping("/transfer") @PostMapping("/transfer")
public ResResult<Void> transfer(@RequestBody TransferParam param){ public ResResult<Void> transfer(@RequestBody TransferParam param){
transferService.transfer(param);
return Res.ok(); return Res.ok();
} }

View File

@@ -0,0 +1,77 @@
package cn.daxpay.single.core.code;
/**
* 公共错误码
* @author xxm
* @since 2024/6/17
*/
public interface DaxPayErrorCode {
/** 未归类的错误 */
int UNCLASSIFIED_ERROR = 20000;
/** 不存在的支付通道 */
int CHANNEL_NOT_EXIST = 20011;
/** 不存在的支付方式 */
int METHOD_NOT_EXIST = 20012;
/** 不存在的状态 */
int STATUS_NOT_EXIST = 20013;
/** 支付通道未启用 */
int CHANNEL_NOT_ENABLE = 20021;
/** 支付方式未启用 */
int METHOD_NOT_ENABLE = 20022;
/** 配置未启用 */
int CONFIG_NOT_ENABLE = 20023;
/** 配置错误 */
int CONFIG_ERROR = 20024;
/** 不支持该能力 */
int UNSUPPORTED_ABILITY = 20030;
/** 交易不存在 */
int TRADE_NOT_EXIST = 20041;
/** 交易已关闭 */
int TRADE_CLOSED = 20042;
/** 交易处理中, 请勿重复操作 */
int TRADE_PROCESSING = 20043;
/** 交易状态错误 */
int TRADE_STATUS_ERROR = 20044;
/** 交易失败 */
int TRADE_FAILE = 20045;
/** 参数校验未通过 */
int PARAM_VALIDATION_FAIL = 20051;
/** 验签失败 */
int VERIFY_SIGN_FAILED = 20052;
/** 金额超过限额 */
int AMOUNT_EXCEED_LIMIT = 20060;
/** 对账失败 */
int RECONCILE_FAIL = 20071;
/** 操作失败 */
int OPERATION_FAIL = 20080;
/** 操作处理中, 请勿重复操作 */
int OPERATION_PROCESSING = 20081;
/** 不支持的操作 */
int OPERATION_UNSUPPORTED = 20082;
/** 数据错误 */
int DATA_ERROR = 20091;
/** 未知异常,系统无法处理 */
int SYSTEM_UNKNOWN_ERROR = 30000;
}

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 金额超过限额 * 金额超过限额
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class AmountExceedLimitException extends PayFailureException{ public class AmountExceedLimitException extends PayFailureException{
public AmountExceedLimitException(String message) { public AmountExceedLimitException(String message) {
super(DaxPayCommonErrorCode.AMOUNT_EXCEED_LIMIT,message); super(DaxPayErrorCode.AMOUNT_EXCEED_LIMIT,message);
} }
public AmountExceedLimitException() { public AmountExceedLimitException() {
super(DaxPayCommonErrorCode.AMOUNT_EXCEED_LIMIT,"金额超过限额"); super(DaxPayErrorCode.AMOUNT_EXCEED_LIMIT,"金额超过限额");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 支付通道未启用 * 支付通道未启用
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class ChannelNotEnableException extends PayFailureException{ public class ChannelNotEnableException extends PayFailureException{
public ChannelNotEnableException(String message) { public ChannelNotEnableException(String message) {
super(DaxPayCommonErrorCode.CHANNEL_NOT_ENABLE,message); super(DaxPayErrorCode.CHANNEL_NOT_ENABLE,message);
} }
public ChannelNotEnableException() { public ChannelNotEnableException() {
super(DaxPayCommonErrorCode.CHANNEL_NOT_ENABLE,"支付通道未启用"); super(DaxPayErrorCode.CHANNEL_NOT_ENABLE,"支付通道未启用");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 不存在的支付通道 * 不存在的支付通道
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class ChannelNotExistException extends PayFailureException{ public class ChannelNotExistException extends PayFailureException{
public ChannelNotExistException(String message) { public ChannelNotExistException(String message) {
super(DaxPayCommonErrorCode.CHANNEL_NOT_EXIST,message); super(DaxPayErrorCode.CHANNEL_NOT_EXIST,message);
} }
public ChannelNotExistException() { public ChannelNotExistException() {
super(DaxPayCommonErrorCode.CHANNEL_NOT_EXIST,"不存在的支付通道"); super(DaxPayErrorCode.CHANNEL_NOT_EXIST,"不存在的支付通道");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 配置错误 * 配置错误
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class ConfigErrorException extends PayFailureException{ public class ConfigErrorException extends PayFailureException{
public ConfigErrorException(String message) { public ConfigErrorException(String message) {
super(DaxPayCommonErrorCode.CONFIG_ERROR,message); super(DaxPayErrorCode.CONFIG_ERROR,message);
} }
public ConfigErrorException() { public ConfigErrorException() {
super(DaxPayCommonErrorCode.CONFIG_ERROR,"配置错误"); super(DaxPayErrorCode.CONFIG_ERROR,"配置错误");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 配置未启用 * 配置未启用
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class ConfigNotEnableException extends PayFailureException{ public class ConfigNotEnableException extends PayFailureException{
public ConfigNotEnableException(String message) { public ConfigNotEnableException(String message) {
super(DaxPayCommonErrorCode.CONFIG_NOT_ENABLE,message); super(DaxPayErrorCode.CONFIG_NOT_ENABLE,message);
} }
public ConfigNotEnableException() { public ConfigNotEnableException() {
super(DaxPayCommonErrorCode.CONFIG_NOT_ENABLE,"配置未启用"); super(DaxPayErrorCode.CONFIG_NOT_ENABLE,"配置未启用");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 数据错误 * 数据错误
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class DataErrorException extends PayFailureException{ public class DataErrorException extends PayFailureException{
public DataErrorException(String message) { public DataErrorException(String message) {
super(DaxPayCommonErrorCode.DATA_ERROR,message); super(DaxPayErrorCode.DATA_ERROR,message);
} }
public DataErrorException() { public DataErrorException() {
super(DaxPayCommonErrorCode.DATA_ERROR,"数据错误"); super(DaxPayErrorCode.DATA_ERROR,"数据错误");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 支付方式未启用 * 支付方式未启用
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class MethodNotEnableException extends PayFailureException{ public class MethodNotEnableException extends PayFailureException{
public MethodNotEnableException(String message) { public MethodNotEnableException(String message) {
super(DaxPayCommonErrorCode.METHOD_NOT_ENABLE,message); super(DaxPayErrorCode.METHOD_NOT_ENABLE,message);
} }
public MethodNotEnableException() { public MethodNotEnableException() {
super(DaxPayCommonErrorCode.METHOD_NOT_ENABLE,"支付方式未启用"); super(DaxPayErrorCode.METHOD_NOT_ENABLE,"支付方式未启用");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 不存在的支付方式 * 不存在的支付方式
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class MethodNotExistException extends PayFailureException{ public class MethodNotExistException extends PayFailureException{
public MethodNotExistException(String message) { public MethodNotExistException(String message) {
super(DaxPayCommonErrorCode.METHOD_NOT_EXIST,message); super(DaxPayErrorCode.METHOD_NOT_EXIST,message);
} }
public MethodNotExistException() { public MethodNotExistException() {
super(DaxPayCommonErrorCode.METHOD_NOT_EXIST,"不存在的支付方式"); super(DaxPayErrorCode.METHOD_NOT_EXIST,"不存在的支付方式");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 操作失败 * 操作失败
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class OperationFailException extends PayFailureException{ public class OperationFailException extends PayFailureException{
public OperationFailException(String message) { public OperationFailException(String message) {
super(DaxPayCommonErrorCode.OPERATION_FAIL,message); super(DaxPayErrorCode.OPERATION_FAIL,message);
} }
public OperationFailException() { public OperationFailException() {
super(DaxPayCommonErrorCode.OPERATION_FAIL,"操作失败"); super(DaxPayErrorCode.OPERATION_FAIL,"操作失败");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 操作处理中, 请勿重复操作 * 操作处理中, 请勿重复操作
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class OperationProcessingException extends PayFailureException{ public class OperationProcessingException extends PayFailureException{
public OperationProcessingException(String message) { public OperationProcessingException(String message) {
super(DaxPayCommonErrorCode.OPERATION_PROCESSING,message); super(DaxPayErrorCode.OPERATION_PROCESSING,message);
} }
public OperationProcessingException() { public OperationProcessingException() {
super(DaxPayCommonErrorCode.OPERATION_PROCESSING,"操作处理中, 请勿重复操作"); super(DaxPayErrorCode.OPERATION_PROCESSING,"操作处理中, 请勿重复操作");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 不支持的操作 * 不支持的操作
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class OperationUnsupportedException extends PayFailureException{ public class OperationUnsupportedException extends PayFailureException{
public OperationUnsupportedException(String message) { public OperationUnsupportedException(String message) {
super(DaxPayCommonErrorCode.OPERATION_UNSUPPORTED,message); super(DaxPayErrorCode.OPERATION_UNSUPPORTED,message);
} }
public OperationUnsupportedException() { public OperationUnsupportedException() {
super(DaxPayCommonErrorCode.OPERATION_UNSUPPORTED,"不支持的操作"); super(DaxPayErrorCode.OPERATION_UNSUPPORTED,"不支持的操作");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 参数校验未通过 * 参数校验未通过
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class ParamValidationFailException extends PayFailureException{ public class ParamValidationFailException extends PayFailureException{
public ParamValidationFailException(String message) { public ParamValidationFailException(String message) {
super(DaxPayCommonErrorCode.PARAM_VALIDATION_FAIL,message); super(DaxPayErrorCode.PARAM_VALIDATION_FAIL,message);
} }
public ParamValidationFailException() { public ParamValidationFailException() {
super(DaxPayCommonErrorCode.PARAM_VALIDATION_FAIL,"参数校验未通过"); super(DaxPayErrorCode.PARAM_VALIDATION_FAIL,"参数校验未通过");
} }
} }

View File

@@ -1,7 +1,7 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.bootx.platform.common.core.exception.BizException; import cn.bootx.platform.common.core.exception.BizException;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 支付错误 * 支付错误
@@ -17,11 +17,11 @@ public class PayFailureException extends BizException {
} }
public PayFailureException(String message) { public PayFailureException(String message) {
super(DaxPayCommonErrorCode.UNCLASSIFIED_ERROR, message); super(DaxPayErrorCode.UNCLASSIFIED_ERROR, message);
} }
public PayFailureException() { public PayFailureException() {
super(DaxPayCommonErrorCode.UNCLASSIFIED_ERROR, "支付失败"); super(DaxPayErrorCode.UNCLASSIFIED_ERROR, "支付失败");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 对账失败 * 对账失败
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class ReconciliationFailException extends PayFailureException{ public class ReconciliationFailException extends PayFailureException{
public ReconciliationFailException(String message) { public ReconciliationFailException(String message) {
super(DaxPayCommonErrorCode.RECONCILE_FAIL,message); super(DaxPayErrorCode.RECONCILE_FAIL,message);
} }
public ReconciliationFailException() { public ReconciliationFailException() {
super(DaxPayCommonErrorCode.RECONCILE_FAIL,"对账失败"); super(DaxPayErrorCode.RECONCILE_FAIL,"对账失败");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 不存在的状态 * 不存在的状态
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class StatusNotExistException extends PayFailureException{ public class StatusNotExistException extends PayFailureException{
public StatusNotExistException(String message) { public StatusNotExistException(String message) {
super(DaxPayCommonErrorCode.STATUS_NOT_EXIST,message); super(DaxPayErrorCode.STATUS_NOT_EXIST,message);
} }
public StatusNotExistException() { public StatusNotExistException() {
super(DaxPayCommonErrorCode.STATUS_NOT_EXIST,"不存在的状态"); super(DaxPayErrorCode.STATUS_NOT_EXIST,"不存在的状态");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 未知异常,系统无法处理 * 未知异常,系统无法处理
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class SystemUnknownErrorException extends PayFailureException{ public class SystemUnknownErrorException extends PayFailureException{
public SystemUnknownErrorException(String message) { public SystemUnknownErrorException(String message) {
super(DaxPayCommonErrorCode.SYSTEM_UNKNOWN_ERROR,message); super(DaxPayErrorCode.SYSTEM_UNKNOWN_ERROR,message);
} }
public SystemUnknownErrorException() { public SystemUnknownErrorException() {
super(DaxPayCommonErrorCode.SYSTEM_UNKNOWN_ERROR,"未知异常,系统无法处理"); super(DaxPayErrorCode.SYSTEM_UNKNOWN_ERROR,"未知异常,系统无法处理");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 交易已关闭 * 交易已关闭
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class TradeClosedException extends PayFailureException{ public class TradeClosedException extends PayFailureException{
public TradeClosedException(String message) { public TradeClosedException(String message) {
super(DaxPayCommonErrorCode.TRADE_CLOSED,message); super(DaxPayErrorCode.TRADE_CLOSED,message);
} }
public TradeClosedException() { public TradeClosedException() {
super(DaxPayCommonErrorCode.TRADE_CLOSED,"交易已关闭"); super(DaxPayErrorCode.TRADE_CLOSED,"交易已关闭");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 交易失败 * 交易失败
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class TradeFaileException extends PayFailureException{ public class TradeFaileException extends PayFailureException{
public TradeFaileException(String message) { public TradeFaileException(String message) {
super(DaxPayCommonErrorCode.TRADE_FAILE,message); super(DaxPayErrorCode.TRADE_FAILE,message);
} }
public TradeFaileException() { public TradeFaileException() {
super(DaxPayCommonErrorCode.TRADE_FAILE,"交易失败"); super(DaxPayErrorCode.TRADE_FAILE,"交易失败");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 交易不存在 * 交易不存在
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class TradeNotExistException extends PayFailureException{ public class TradeNotExistException extends PayFailureException{
public TradeNotExistException(String message) { public TradeNotExistException(String message) {
super(DaxPayCommonErrorCode.TRADE_NOT_EXIST,message); super(DaxPayErrorCode.TRADE_NOT_EXIST,message);
} }
public TradeNotExistException() { public TradeNotExistException() {
super(DaxPayCommonErrorCode.TRADE_NOT_EXIST,"交易不存在"); super(DaxPayErrorCode.TRADE_NOT_EXIST,"交易不存在");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 交易处理中, 请勿重复操作 * 交易处理中, 请勿重复操作
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class TradeProcessingException extends PayFailureException{ public class TradeProcessingException extends PayFailureException{
public TradeProcessingException(String message) { public TradeProcessingException(String message) {
super(DaxPayCommonErrorCode.TRADE_PROCESSING,message); super(DaxPayErrorCode.TRADE_PROCESSING,message);
} }
public TradeProcessingException() { public TradeProcessingException() {
super(DaxPayCommonErrorCode.TRADE_PROCESSING,"交易处理中,请勿重复操作"); super(DaxPayErrorCode.TRADE_PROCESSING,"交易处理中,请勿重复操作");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 交易状态错误 * 交易状态错误
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class TradeStatusErrorException extends PayFailureException{ public class TradeStatusErrorException extends PayFailureException{
public TradeStatusErrorException(String message) { public TradeStatusErrorException(String message) {
super(DaxPayCommonErrorCode.TRADE_STATUS_ERROR,message); super(DaxPayErrorCode.TRADE_STATUS_ERROR,message);
} }
public TradeStatusErrorException() { public TradeStatusErrorException() {
super(DaxPayCommonErrorCode.TRADE_STATUS_ERROR,"交易状态错误"); super(DaxPayErrorCode.TRADE_STATUS_ERROR,"交易状态错误");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 不支持该能力 * 不支持该能力
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class UnsupportedAbilityException extends PayFailureException{ public class UnsupportedAbilityException extends PayFailureException{
public UnsupportedAbilityException(String message) { public UnsupportedAbilityException(String message) {
super(DaxPayCommonErrorCode.UNSUPPORTED_ABILITY,message); super(DaxPayErrorCode.UNSUPPORTED_ABILITY,message);
} }
public UnsupportedAbilityException() { public UnsupportedAbilityException() {
super(DaxPayCommonErrorCode.UNSUPPORTED_ABILITY,"不支持该能力"); super(DaxPayErrorCode.UNSUPPORTED_ABILITY,"不支持该能力");
} }
} }

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.core.exception; package cn.daxpay.single.core.exception;
import cn.daxpay.single.core.code.DaxPayCommonErrorCode; import cn.daxpay.single.core.code.DaxPayErrorCode;
/** /**
* 验签失败 * 验签失败
@@ -10,10 +10,10 @@ import cn.daxpay.single.core.code.DaxPayCommonErrorCode;
public class VerifySignFailedException extends PayFailureException{ public class VerifySignFailedException extends PayFailureException{
public VerifySignFailedException(String message) { public VerifySignFailedException(String message) {
super(DaxPayCommonErrorCode.VERIFY_SIGN_FAILED,message); super(DaxPayErrorCode.VERIFY_SIGN_FAILED,message);
} }
public VerifySignFailedException() { public VerifySignFailedException() {
super(DaxPayCommonErrorCode.VERIFY_SIGN_FAILED,"验签失败"); super(DaxPayErrorCode.VERIFY_SIGN_FAILED,"验签失败");
} }
} }

View File

@@ -1,5 +1,7 @@
package cn.daxpay.single.service.common.context; package cn.daxpay.single.service.common.context;
import cn.bootx.platform.common.core.exception.BizException;
import cn.daxpay.single.core.code.DaxPayErrorCode;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
@@ -13,8 +15,30 @@ import lombok.experimental.Accessors;
public class ErrorInfoLocal { public class ErrorInfoLocal {
/** 错误码 */ /** 错误码 */
private String errorCode; private int errorCode;
/** 错误内容 */ /** 错误内容 */
private String errorMsg; private String errorMsg;
/**
* 自动根据传入的异常对象对象进行处理
*/
public void setException(Exception e) {
// 如果业务异常, 获取错误码和错误信息
if (e instanceof BizException) {
BizException be = (BizException) e;
this.errorCode = be.getCode();
this.errorMsg = be.getMessage();
}
// 如果是空指针, 专门记录
else if (e instanceof NullPointerException) {
this.errorCode = DaxPayErrorCode.UNCLASSIFIED_ERROR;
this.errorMsg = "空指针异常";
}
// 如果是其他异常, 归类到为止异常中
else {
this.errorCode = DaxPayErrorCode.SYSTEM_UNKNOWN_ERROR;
this.errorMsg = "未归类异常,请联系管理人员进行排查";
}
}
} }

View File

@@ -1,5 +1,6 @@
package cn.daxpay.single.service.core.channel.alipay.service; package cn.daxpay.single.service.core.channel.alipay.service;
import cn.daxpay.single.core.code.DaxPayErrorCode;
import cn.daxpay.single.core.code.RefundStatusEnum; import cn.daxpay.single.core.code.RefundStatusEnum;
import cn.daxpay.single.core.exception.OperationFailException; import cn.daxpay.single.core.exception.OperationFailException;
import cn.daxpay.single.core.util.PayUtil; import cn.daxpay.single.core.util.PayUtil;
@@ -53,10 +54,10 @@ public class AliPayRefundService {
try { try {
AlipayTradeRefundResponse response = alipayClient.execute(request); AlipayTradeRefundResponse response = alipayClient.execute(request);
if (!Objects.equals(AliPayCode.SUCCESS, response.getCode())) { if (!Objects.equals(AliPayCode.SUCCESS, response.getCode())) {
errorInfo.setErrorMsg(response.getSubMsg()); OperationFailException operationFailException = new OperationFailException(response.getSubMsg());
errorInfo.setErrorCode(response.getCode()); errorInfo.setException(operationFailException);
log.error("网关返回退款失败: {}", response.getSubMsg()); log.error("网关返回退款失败: {}", response.getSubMsg());
throw new OperationFailException(response.getSubMsg()); throw operationFailException;
} }
// 默认为退款中状态 // 默认为退款中状态
refundInfo.setStatus(RefundStatusEnum.PROGRESS) refundInfo.setStatus(RefundStatusEnum.PROGRESS)
@@ -71,8 +72,8 @@ public class AliPayRefundService {
catch (AlipayApiException e) { catch (AlipayApiException e) {
log.error("订单退款失败:", e); log.error("订单退款失败:", e);
errorInfo.setErrorMsg(e.getErrMsg()); errorInfo.setErrorMsg(e.getErrMsg());
errorInfo.setErrorCode(e.getErrCode()); errorInfo.setErrorCode(DaxPayErrorCode.OPERATION_FAIL);
throw new OperationFailException("订单退款失败"); throw new OperationFailException(e.getErrMsg());
} }
} }
} }

View File

@@ -20,7 +20,6 @@ import org.springframework.stereotype.Service;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import static cn.daxpay.single.service.code.WeChatPayCode.*; import static cn.daxpay.single.service.code.WeChatPayCode.*;
@@ -58,9 +57,9 @@ public class WeChatPayRefundService {
// 获取证书文件 // 获取证书文件
if (StrUtil.isBlank(weChatPayConfig.getP12())){ if (StrUtil.isBlank(weChatPayConfig.getP12())){
String errorMsg = "微信p.12证书未配置,无法进行退款"; String errorMsg = "微信p.12证书未配置,无法进行退款";
errorInfo.setErrorMsg(errorMsg); ConfigErrorException configErrorException = new ConfigErrorException(errorMsg);
errorInfo.setErrorCode(RefundStatusEnum.FAIL.getCode()); errorInfo.setException(configErrorException);
throw new ConfigErrorException(errorMsg); throw configErrorException;
} }
byte[] fileBytes = Base64.decode(weChatPayConfig.getP12()); byte[] fileBytes = Base64.decode(weChatPayConfig.getP12());
ByteArrayInputStream inputStream = new ByteArrayInputStream(fileBytes); ByteArrayInputStream inputStream = new ByteArrayInputStream(fileBytes);
@@ -85,10 +84,10 @@ public class WeChatPayRefundService {
errorMsg = result.get(RETURN_MSG); errorMsg = result.get(RETURN_MSG);
} }
log.error("订单退款失败 {}", errorMsg); log.error("订单退款失败 {}", errorMsg);
TradeFaileException tradeFaileException = new TradeFaileException(errorMsg);
ErrorInfoLocal errorInfo = PaymentContextLocal.get().getErrorInfo(); ErrorInfoLocal errorInfo = PaymentContextLocal.get().getErrorInfo();
errorInfo.setErrorMsg(errorMsg); errorInfo.setException(tradeFaileException);
errorInfo.setErrorCode(Optional.ofNullable(resultCode).orElse(returnCode)); throw tradeFaileException;
throw new TradeFaileException(errorMsg);
} }
} }

View File

@@ -1,5 +1,6 @@
package cn.daxpay.single.service.core.order.transfer.service; package cn.daxpay.single.service.core.order.transfer.service;
import cn.daxpay.single.core.param.payment.transfer.TransferParam;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -17,7 +18,7 @@ public class TransferOrderService {
/** /**
* 手动转账 * 手动转账
*/ */
public void transfer(){ public void transfer(TransferParam param){
} }

View File

@@ -120,7 +120,7 @@ public class RefundAssistService {
public void updateOrderByError(RefundOrder refundOrder){ public void updateOrderByError(RefundOrder refundOrder){
RefundLocal refundInfo = PaymentContextLocal.get().getRefundInfo(); RefundLocal refundInfo = PaymentContextLocal.get().getRefundInfo();
ErrorInfoLocal errorInfo = PaymentContextLocal.get().getErrorInfo(); ErrorInfoLocal errorInfo = PaymentContextLocal.get().getErrorInfo();
refundOrder.setErrorCode(errorInfo.getErrorCode()); refundOrder.setErrorCode(String.valueOf(errorInfo.getErrorCode()));
refundOrder.setErrorMsg(errorInfo.getErrorMsg()); refundOrder.setErrorMsg(errorInfo.getErrorMsg());
refundOrder.setStatus(refundInfo.getStatus().getCode()); refundOrder.setStatus(refundInfo.getStatus().getCode());
refundOrderManager.updateById(refundOrder); refundOrderManager.updateById(refundOrder);

View File

@@ -56,7 +56,7 @@ public class TransferAssistService {
ErrorInfoLocal errorInfo = PaymentContextLocal.get().getErrorInfo(); ErrorInfoLocal errorInfo = PaymentContextLocal.get().getErrorInfo();
order.setStatus(TransferStatusEnum.FAIL.getCode()) order.setStatus(TransferStatusEnum.FAIL.getCode())
.setErrorMsg(errorInfo.getErrorMsg()) .setErrorMsg(errorInfo.getErrorMsg())
.setErrorCode(errorInfo.getErrorCode()); .setErrorCode(String.valueOf(errorInfo.getErrorCode()));
transferOrderManager.updateById(order); transferOrderManager.updateById(order);
} }

View File

@@ -33,7 +33,6 @@ public class TransferService {
* 转账 * 转账
*/ */
public TransferResult transfer(TransferParam transferParam){ public TransferResult transfer(TransferParam transferParam){
// 获取策略 // 获取策略
AbsTransferStrategy transferStrategy = PayStrategyFactory.create(transferParam.getChannel(),AbsTransferStrategy.class); AbsTransferStrategy transferStrategy = PayStrategyFactory.create(transferParam.getChannel(),AbsTransferStrategy.class);
// 检查转账参数 // 检查转账参数
@@ -50,6 +49,7 @@ public class TransferService {
log.error("转账出现错误", e); log.error("转账出现错误", e);
// 记录处理失败状态 // 记录处理失败状态
PaymentContextLocal.get().getRefundInfo().setStatus(RefundStatusEnum.FAIL); PaymentContextLocal.get().getRefundInfo().setStatus(RefundStatusEnum.FAIL);
PaymentContextLocal.get().getErrorInfo().setException(e);
// 更新退款失败的记录 // 更新退款失败的记录
transferAssistService.updateOrderByError(order); transferAssistService.updateOrderByError(order);
return transferAssistService.buildResult(order); return transferAssistService.buildResult(order);