Commit b893160f98c4a765e6a1de796c8608983c8f2441

Authored by huanggang
1 parent 5e609a45

upgrade after testing

cashier-boss/src/main/java/com/diligrp/cashier/boss/domain/CashierOrderToken.java
... ... @@ -35,13 +35,13 @@ public class CashierOrderToken {
35 35 payload = payload + signature;
36 36 return payload;
37 37 } catch (Exception ex) {
38   - throw new BossServiceException(ErrorCode.ILLEGAL_ARGUMENT_ERROR, "Failed to generate order token");
  38 + throw new BossServiceException(ErrorCode.ILLEGAL_ARGUMENT_ERROR, "生成订单TOKEN失败");
39 39 }
40 40 }
41 41  
42 42 public static long decode(String token, SecretKeySpec secretKey) {
43 43 if (token == null || token.length() <= Constants.TOKEN_SIGN_LENGTH) {
44   - throw new BossServiceException(ErrorCode.ILLEGAL_ARGUMENT_ERROR, "Invalid order token");
  44 + throw new BossServiceException(ErrorCode.ILLEGAL_ARGUMENT_ERROR, "无效的订单TOKEN");
45 45 }
46 46  
47 47 String payload = token.substring(0, token.length() - Constants.TOKEN_SIGN_LENGTH);
... ... @@ -53,11 +53,11 @@ public class CashierOrderToken {
53 53 byte[] bytes = mac.doFinal(payload.getBytes(StandardCharsets.UTF_8));
54 54 tokenSign = HexUtils.encodeHexStr(bytes).substring(0, Constants.TOKEN_SIGN_LENGTH);
55 55 } catch (Exception ex) {
56   - throw new BossServiceException(ErrorCode.OPERATION_NOT_ALLOWED, "Invalid order token");
  56 + throw new BossServiceException(ErrorCode.OPERATION_NOT_ALLOWED, "无效的订单TOKEN");
57 57 }
58 58  
59 59 if (!Objects.equals(signature, tokenSign)) {
60   - throw new BossServiceException(ErrorCode.OPERATION_NOT_ALLOWED, "Invalid order token signature");
  60 + throw new BossServiceException(ErrorCode.OPERATION_NOT_ALLOWED, "无效的订单TOKEN");
61 61 }
62 62 return Base62Cipher.decodeLong(payload);
63 63 }
... ...
cashier-boss/src/main/java/com/diligrp/cashier/boss/domain/CashierOrderVO.java
... ... @@ -5,6 +5,8 @@ import com.diligrp.cashier.pipeline.type.ChannelType;
5 5 import java.util.List;
6 6  
7 7 public class CashierOrderVO {
  8 + // 交易号
  9 + private final String tradeId;
8 10 // 业务系统用户标识
9 11 private final String userId;
10 12 // 商品描述
... ... @@ -16,8 +18,9 @@ public class CashierOrderVO {
16 18 // 支付通道
17 19 private final List<PaymentPipeline> pipelines;
18 20  
19   - public CashierOrderVO(String userId, String goods, String amount,
  21 + public CashierOrderVO(String tradeId, String userId, String goods, String amount,
20 22 String redirectUrl, List<PaymentPipeline> pipelines) {
  23 + this.tradeId = tradeId;
21 24 this.userId = userId;
22 25 this.goods = goods;
23 26 this.amount = amount;
... ... @@ -25,6 +28,10 @@ public class CashierOrderVO {
25 28 this.pipelines = pipelines;
26 29 }
27 30  
  31 + public String getTradeId() {
  32 + return tradeId;
  33 + }
  34 +
28 35 public String getUserId() {
29 36 return userId;
30 37 }
... ...
cashier-boss/src/main/java/com/diligrp/cashier/boss/service/impl/CashierDeskServiceImpl.java
... ... @@ -76,7 +76,7 @@ public class CashierDeskServiceImpl implements ICashierDeskService {
76 76 String tokenKey = String.format(Constants.TRADE_REDIS_KEY, tradeId);
77 77 String payload = stringRedisTemplate.opsForValue().get(tokenKey);
78 78 if (ObjectUtils.isEmpty(payload)) {
79   - throw new BossServiceException(ErrorCode.ILLEGAL_ARGUMENT_ERROR, "TOKEN超时过期,不能完成支付");
  79 + throw new BossServiceException(ErrorCode.ILLEGAL_ARGUMENT_ERROR, "订单TOKEN超时过期,不能完成支付");
80 80 }
81 81  
82 82 CashierOrderToken orderToken = CashierOrderToken.decodeCashierOrder(payload);
... ... @@ -88,7 +88,8 @@ public class CashierDeskServiceImpl implements ICashierDeskService {
88 88 List<CashierOrderVO.PaymentPipeline> pipelineList = pipelines.stream().map(pipeline ->
89 89 new CashierOrderVO.PaymentPipeline(pipeline.pipelineId(), pipeline.supportedChannel())).toList();
90 90 String amount = CurrencyUtils.toNoSymbolCurrency(trade.getMaxAmount());
91   - return new CashierOrderVO(orderToken.getUserId(), trade.getGoods(), amount, orderToken.getRedirectUrl(), pipelineList);
  91 + return new CashierOrderVO(orderToken.getTradeId(), orderToken.getUserId(), trade.getGoods(), amount,
  92 + orderToken.getRedirectUrl(), pipelineList);
92 93 }
93 94  
94 95 /**
... ...
cashier-shared/src/main/java/com/diligrp/cashier/shared/exception/DefaultExceptionHandler.java
... ... @@ -22,17 +22,18 @@ import java.util.stream.Collectors;
22 22  
23 23 @RestControllerAdvice
24 24 public class DefaultExceptionHandler {
25   - private final Logger LOG = LoggerFactory.getLogger(this.getClass());
  25 +
  26 + private static final Logger LOG = LoggerFactory.getLogger(DefaultExceptionHandler.class);
26 27  
27 28 @ExceptionHandler(PlatformServiceException.class)
28 29 public Message<?> platformServiceException(PlatformServiceException ex) {
29   - LOG.warn("assistant platform service exception", ex);
  30 + LOG.warn("cashier platform service exception", ex);
30 31 return Message.failure(ex.getCode(), ex.getMessage());
31 32 }
32 33  
33 34 @ExceptionHandler(IllegalArgumentException.class)
34 35 public Message<?> illegalArgumentException(IllegalArgumentException ex) {
35   - LOG.warn("assistant platform service exception", ex);
  36 + LOG.warn("cashier platform service exception", ex);
36 37 return Message.failure(ErrorCode.ILLEGAL_ARGUMENT_ERROR, ex.getMessage());
37 38 }
38 39  
... ... @@ -40,39 +41,33 @@ public class DefaultExceptionHandler {
40 41 public Message<?> constraintViolationException(ConstraintViolationException exs) {
41 42 Set<ConstraintViolation<?>> violations = exs.getConstraintViolations();
42 43 String msg = violations.stream().map(ConstraintViolation::getMessage)
43   - .collect(Collectors.joining(","));
  44 + .collect(Collectors.joining(","));
44 45 return Message.failure(ErrorCode.ILLEGAL_ARGUMENT_ERROR, msg);
45 46 }
46 47  
47 48 @ExceptionHandler(value = {MethodArgumentNotValidException.class, BindException.class})
48   - public Message<?> methodArgumentNotValidException(Exception e) {
49   - BindingResult bindingResult;
50   - if (e instanceof MethodArgumentNotValidException) {
51   - bindingResult = ((MethodArgumentNotValidException) e).getBindingResult();
52   - } else {
53   - bindingResult = ((BindException) e).getBindingResult();
54   - }
  49 + public Message<?> methodArgumentNotValidException(BindException ex) {
  50 + BindingResult bindingResult = ex.getBindingResult();
55 51 List<ObjectError> allErrors = bindingResult.getAllErrors();
56 52 String msg = allErrors.stream().map(DefaultMessageSourceResolvable::getDefaultMessage)
57   - .collect(Collectors.joining("、"));
  53 + .collect(Collectors.joining(","));
58 54  
59 55 return Message.failure(ErrorCode.ILLEGAL_ARGUMENT_ERROR, msg);
60 56 }
61 57  
62 58 @ExceptionHandler(MissingServletRequestParameterException.class)
63 59 public Message<?> missingServletRequestParameterExceptionHandler(MissingServletRequestParameterException ex) {
64   - return Message.failure(ErrorCode.ILLEGAL_ARGUMENT_ERROR, String.format("缺少参数%s", ex.getParameterName()));
  60 + return Message.failure(ErrorCode.ILLEGAL_ARGUMENT_ERROR, String.format("缺少参数: %s", ex.getParameterName()));
65 61 }
66 62  
67 63 @ExceptionHandler({HttpRequestMethodNotSupportedException.class})
68 64 public Message<?> handleRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException ex) {
69   - return Message.failure(ErrorCode.METHOD_NOT_SUPPORTED_ERROR, "请求方式错误");
  65 + return Message.failure(ErrorCode.METHOD_NOT_SUPPORTED_ERROR, "请求方式错误!");
70 66 }
71 67  
72   -
73 68 @ExceptionHandler(Exception.class)
74 69 public Message<?> defaultExceptionHandler(Exception ex) {
75   - LOG.warn("assistant platform service exception", ex);
  70 + LOG.warn("cashier platform service exception", ex);
76 71 return Message.failure(ErrorCode.SYSTEM_UNKNOWN_ERROR, ErrorCode.MESSAGE_UNKNOWN_ERROR);
77 72 }
78 73 }
... ...
cashier-trade/src/main/java/com/diligrp/cashier/trade/service/impl/CashierPaymentServiceImpl.java
... ... @@ -345,8 +345,9 @@ public class CashierPaymentServiceImpl implements ICashierPaymentService {
345 345 .type(TradeType.REFUND).paymentId(refundId).channelId(payment.getChannelId())
346 346 .payType(payment.getPayType()).pipelineId(payment.getPipelineId()).goods(payment.getGoods() + "-退款")
347 347 .amount(request.getAmount()).objectId(payment.getPaymentId()).payerId(payment.getPayerId())
348   - .finishTime(response.getWhen()).outTradeNo(response.getOutTradeNo()).outPayType(payment.getOutPayType())
349   - .state(response.getState()).description(request.getDescription()).version(0).createdTime(now).modifiedTime(now).build();
  348 + .outTradeNo(response.getOutTradeNo()).outPayType(payment.getOutPayType()).finishTime(response.getWhen())
  349 + .state(response.getState()).notifyUrl(request.getNotifyUrl()).description(request.getDescription())
  350 + .version(0).createdTime(now).modifiedTime(now).build();
350 351 onlinePaymentDao.insertOnlinePayment(refund);
351 352  
352 353 if (response.getState() == PaymentState.SUCCESS) {
... ...