From 694f4b43cbb799ec032545ccc1e9d01716f08943 Mon Sep 17 00:00:00 2001 From: dzc <2388224167@qq.com> Date: Thu, 6 Mar 2025 19:42:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=AD=A3=E5=85=83=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=AF=B9=E6=8E=A5=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/hard/HardThirdSelfZyServiceImpl.java | 3 - .../thirdparty/vo/zy/self/ZySelfPayVo.java | 4 +- .../impl/zy/ThirdZySelfServiceImpl.java | 92 +++++++++++-------- .../thirdparty/utils/zy/api/ZyApiTool.java | 12 ++- .../java/com/bsd/pjcloud/admin/ZyTest.java | 23 +++-- 5 files changed, 80 insertions(+), 54 deletions(-) diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/hard/HardThirdSelfZyServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/hard/HardThirdSelfZyServiceImpl.java index 63709cd1..4488fb55 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/hard/HardThirdSelfZyServiceImpl.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/hard/HardThirdSelfZyServiceImpl.java @@ -119,9 +119,6 @@ public class HardThirdSelfZyServiceImpl implements HardThirdSelfZyService { try { // 校验订单是否可以退款 HardOrderVo order = hardAfterSaleService.validateOrderCanRefund(dto.getOrderId()); - if (!ObjectUtil.equals(dto.getSerialNum(), order.getOrderNo())) { - throw new RuntimeException("正元订单号不匹配"); - } // 用户 UserInfo user = remoteUserService.getByUserId(order.getUserId()).getData(); if (ObjectUtil.isEmpty(user)) throw new RuntimeException("用户不存在"); diff --git a/pjcloud-thirdparty/pjcloud-thirdparty-api/src/main/java/com/bsd/pjcloud/thirdparty/vo/zy/self/ZySelfPayVo.java b/pjcloud-thirdparty/pjcloud-thirdparty-api/src/main/java/com/bsd/pjcloud/thirdparty/vo/zy/self/ZySelfPayVo.java index 456d496a..be2f0fea 100644 --- a/pjcloud-thirdparty/pjcloud-thirdparty-api/src/main/java/com/bsd/pjcloud/thirdparty/vo/zy/self/ZySelfPayVo.java +++ b/pjcloud-thirdparty/pjcloud-thirdparty-api/src/main/java/com/bsd/pjcloud/thirdparty/vo/zy/self/ZySelfPayVo.java @@ -13,7 +13,7 @@ import lombok.NoArgsConstructor; @Builder @AllArgsConstructor @NoArgsConstructor -public class ZySelfPayVo extends ZyBaseVo { +public class ZySelfPayVo { /** * 帐号 @@ -31,7 +31,7 @@ public class ZySelfPayVo extends ZyBaseVo { private String perCode; /** - * 订单流水号,全局唯一,第三方流水号 + * 订单流水号,全局唯一,第三方流水号 */ private String platformSerialNum; diff --git a/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/impl/zy/ThirdZySelfServiceImpl.java b/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/impl/zy/ThirdZySelfServiceImpl.java index bc44d210..98161371 100644 --- a/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/impl/zy/ThirdZySelfServiceImpl.java +++ b/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/impl/zy/ThirdZySelfServiceImpl.java @@ -103,8 +103,9 @@ public class ThirdZySelfServiceImpl implements ThirdZySelfService { ThirdZyLogEntity entity = new ThirdZyLogEntity(); entity.setBizType(bizType.getType()); entity.setApiUrl(ZyApi.Self.CORRECT); + entity.setEncipherReq(JSONUtil.toJsonStr(params)); long startTime = System.currentTimeMillis(); - ZySelfCorrectVo result = new ZySelfCorrectVo(); + ZyBaseVo result = new ZyBaseVo(); try { result.setCode(ZyBaseVo.errorCode); boolean isToken = checkIsToken(accessToken); @@ -126,7 +127,7 @@ public class ThirdZySelfServiceImpl implements ThirdZySelfService { result.setCode(ZyBaseVo.errorCode); result.setMsg(ZyBaseVo.defaultErrorMsg); ZySelfCorrectDto dto = JSONUtil.toBean(jsonRes, ZySelfCorrectDto.class); - entity.setEncipherReq(JSONUtil.toJsonStr(dto)); + entity.setOrgReq(JSONUtil.toJsonStr(dto)); // 获取参数 String correctSerialNum = dto.getCorrectSerialNum(); Long orderId = Long.parseLong(correctSerialNum); @@ -140,18 +141,25 @@ public class ThirdZySelfServiceImpl implements ThirdZySelfService { case SUCCESS -> { ThirdZyIdDictEntity userIdDict = thirdZyIdDictMapper.getBySelfId(ThirdZyBizEnumType.SYNC_ACCOUNT_INFO, String.valueOf(refundRes.getUserId())); String userZyId = userIdDict.getZyId(); - result.setAccNum(userZyId); - result.setAccName(refundRes.getUsername()); - result.setPerCode(userZyId); - result.setPlatformSerialNum(String.valueOf(refundRes.getRefundId())); - result.setSerialNum(refundRes.getOrderNo()); - result.setRecDate(LocalDateTimeUtil.format(refundRes.getRefundTime(), DatePattern.NORM_DATETIME_PATTERN)); - result.setAmount(dto.getAmount()); + ZySelfPayVo success = new ZySelfPayVo(); + success.setAccNum(userZyId); + success.setAccName(refundRes.getUsername()); + success.setPerCode(userZyId); + success.setPlatformSerialNum(String.valueOf(refundRes.getRefundId())); + success.setSerialNum(refundRes.getOrderNo()); + success.setRecDate(LocalDateTimeUtil.format(refundRes.getRefundTime(), DatePattern.NORM_DATETIME_PATTERN)); + success.setAmount(dto.getAmount()); result.setMsg(ZyBaseVo.selfSuccessMsg); - entity.setOrgReq(JSONUtil.toJsonStr(result)); - Map encryptionRes = zyApiTool.getSelfEncryptionMap(BeanUtil.beanToMap(result)); - entity.setEncipherReq(JSONUtil.toJsonStr(encryptionRes)); - return encryptionRes; + Map resMap = BeanUtil.beanToMap(result); + Map dataMap = BeanUtil.beanToMap(success); + dataMap.put("sign", zyApiTool.generateSign(dataMap, false)); + resMap.put("data", Base64.encode(JSONUtil.toJsonStr(dataMap))); + entity.setOrgRes(JSONUtil.toJsonStr(success)); + entity.setEncipherRes(JSONUtil.toJsonStr(resMap)); + long elapsedTime = System.currentTimeMillis() - startTime; + entity.setTimeConsuming(Long.toString(elapsedTime)); + thirdZyLogService.save(entity); + return resMap; } default -> throw new RuntimeException(); } @@ -159,11 +167,10 @@ public class ThirdZySelfServiceImpl implements ThirdZySelfService { String error = String.format("|%s||correct|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace())); log.error(error); entity.setError(error); - return result.getErrorMap(); - } finally { long elapsedTime = System.currentTimeMillis() - startTime; entity.setTimeConsuming(Long.toString(elapsedTime)); thirdZyLogService.save(entity); + return result.getErrorMap(); } } @@ -178,7 +185,7 @@ public class ThirdZySelfServiceImpl implements ThirdZySelfService { entity.setBizType(bizType.getType()); entity.setEncipherReq(JSONUtil.toJsonStr(params)); long startTime = System.currentTimeMillis(); - ZySelfPayVo result = new ZySelfPayVo(); + ZyBaseVo result = new ZyBaseVo(); try { result.setCode(ZyBaseVo.errorCode); // 判断token @@ -200,7 +207,7 @@ public class ThirdZySelfServiceImpl implements ThirdZySelfService { result.setCode(ZyBaseVo.errorCode); result.setMsg(ZyBaseVo.defaultErrorMsg); ZySelfPayDto dto = JSONUtil.toBean(jsonRes, ZySelfPayDto.class); - entity.setEncipherReq(JSONUtil.toJsonStr(dto)); + entity.setOrgReq(JSONUtil.toJsonStr(dto)); // 获取参数 String accNum = dto.getAccNum(); ThirdZyIdDictEntity userIdDict = thirdZyIdDictMapper.getByZyIds(ThirdZyBizEnumType.SYNC_ACCOUNT_INFO, accNum); @@ -224,18 +231,25 @@ public class ThirdZySelfServiceImpl implements ThirdZySelfService { result.setCode(payRes.getCode().getType()); switch (payRes.getCode()) { case SUCCESS -> { - result.setAccNum(payRes.getUserId().toString()); - result.setAccName(payRes.getUsername()); - result.setPerCode(payRes.getUserId().toString()); - result.setPlatformSerialNum(dto.getSerialNum()); - result.setSerialNum(dto.getSerialNum()); - result.setAmount(amount); - result.setRecDate(LocalDateTimeUtil.format(payRes.getPayTime(), DatePattern.NORM_DATETIME_PATTERN)); + ZySelfPayVo success = new ZySelfPayVo(); + success.setAccNum(payRes.getUserId().toString()); + success.setAccName(payRes.getUsername()); + success.setPerCode(payRes.getUserId().toString()); + success.setPlatformSerialNum(payRes.getOrderId().toString()); + success.setSerialNum(dto.getSerialNum()); + success.setAmount(amount); + success.setRecDate(LocalDateTimeUtil.format(payRes.getPayTime(), DatePattern.NORM_DATETIME_PATTERN)); result.setMsg(ZyBaseVo.selfSuccessMsg); - entity.setOrgReq(JSONUtil.toJsonStr(result)); - Map encryptionRes = zyApiTool.getSelfEncryptionMap(BeanUtil.beanToMap(result)); - entity.setEncipherReq(JSONUtil.toJsonStr(encryptionRes)); - return encryptionRes; + Map resMap = BeanUtil.beanToMap(result); + Map dataMap = BeanUtil.beanToMap(success); + dataMap.put("sign", zyApiTool.generateSign(dataMap, false)); + resMap.put("data", Base64.encode(JSONUtil.toJsonStr(dataMap))); + entity.setOrgRes(JSONUtil.toJsonStr(success)); + entity.setEncipherRes(JSONUtil.toJsonStr(resMap)); + long elapsedTime = System.currentTimeMillis() - startTime; + entity.setTimeConsuming(Long.toString(elapsedTime)); + thirdZyLogService.save(entity); + return resMap; } default -> throw new RuntimeException(); } @@ -243,11 +257,10 @@ public class ThirdZySelfServiceImpl implements ThirdZySelfService { String error = String.format("|%s||pay|意外的错误error|%s|stack|%s|", TAG, e.getMessage(), Arrays.toString(e.getStackTrace())); log.error(error); entity.setError(error); - return result.getErrorMap(); - } finally { long elapsedTime = System.currentTimeMillis() - startTime; entity.setTimeConsuming(Long.toString(elapsedTime)); thirdZyLogService.save(entity); + return result.getErrorMap(); } } @@ -274,11 +287,11 @@ public class ThirdZySelfServiceImpl implements ThirdZySelfService { result.setMsg(msg); throw new RuntimeException(msg); } - String redisKey = CacheConstants.THIRDPARTY_ZY_SELF_TOKEN + "*"; - Set keys = redisTemplate.keys(redisKey); - if (ObjectUtil.isNotEmpty(keys)) { - redisTemplate.delete(keys); - } + // String redisKey = CacheConstants.THIRDPARTY_ZY_SELF_TOKEN + "*"; + // Set keys = redisTemplate.keys(redisKey); + // if (ObjectUtil.isNotEmpty(keys)) { + // redisTemplate.delete(keys); + // } try { // 生成token String token = generateToken(params); @@ -345,14 +358,17 @@ public class ThirdZySelfServiceImpl implements ThirdZySelfService { } for (Map.Entry entry : paramsMap.entrySet()) { Object value = entry.getValue(); + if (ObjectUtil.isEmpty(value)) continue; if (value instanceof String) { - entry.setValue(Base64.decodeStr((String) value)); + String str = Base64.decodeStr((String) value); + entry.setValue(URLUtil.decode(str)); } else { - entry.setValue(Base64.decodeStr(value.toString())); + String str = Base64.decodeStr((String) value); + entry.setValue(URLUtil.decode(str)); } } String string = zyApiTool.generateSign(paramsMap, false); - if (ObjectUtil.equals(sign, string)) { + if (ObjectUtil.equals(sign.toLowerCase(), string)) { for (Map.Entry entry : paramsMap.entrySet()) { Object value = entry.getValue(); if (value instanceof String) { diff --git a/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/utils/zy/api/ZyApiTool.java b/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/utils/zy/api/ZyApiTool.java index f79351e5..0d13a2cc 100644 --- a/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/utils/zy/api/ZyApiTool.java +++ b/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/utils/zy/api/ZyApiTool.java @@ -174,7 +174,7 @@ public class ZyApiTool { return body; } - private void prePost(Map params, boolean isZy) { + public void prePost(Map params, boolean isZy) { for (Map.Entry entry : params.entrySet()) { Object value = entry.getValue(); if (value instanceof String) { @@ -187,10 +187,12 @@ public class ZyApiTool { String sign = generateSign(params, isZy); for (Map.Entry entry : params.entrySet()) { Object value = entry.getValue(); - if (value instanceof String) { - entry.setValue(Base64.encode((String) value)); - } else { - entry.setValue(Base64.encode(value.toString())); + if (ObjectUtil.isNotEmpty(value)) { + if (value instanceof String) { + entry.setValue(Base64.encode((String) value)); + } else { + entry.setValue(Base64.encode(value.toString())); + } } } params.put("sign", sign); diff --git a/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/test/java/com/bsd/pjcloud/admin/ZyTest.java b/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/test/java/com/bsd/pjcloud/admin/ZyTest.java index 0fe520c1..c281b532 100644 --- a/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/test/java/com/bsd/pjcloud/admin/ZyTest.java +++ b/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/test/java/com/bsd/pjcloud/admin/ZyTest.java @@ -80,15 +80,26 @@ public class ZyTest { ZySelfGetTokenVo token = zySelfService.getToken(tokenParams); String accessToken = token.getAccess_token(); +// ZySelfPayDto params = ZySelfPayDto +// .builder() +// .accNum(dzcUserDict.getZyId()) +// .cardAccNum(dzcWalletId) +// .amount("10") +// .serialNum("01234567890123456789") +// .dealTime(date) +// .opId("0123456789") +// .build(); + ZySelfPayDto params = ZySelfPayDto .builder() - .accNum(dzcUserDict.getZyId()) - .cardAccNum(dzcWalletId) - .amount("10") - .serialNum("01234567890123456789") - .dealTime(date) - .opId("0123456789") + .accNum("1741232987425846") + .cardAccNum("1877309001545244673") + .amount("0.01") + .serialNum("763") + .dealTime("2025-03-06 17:34:11") + .opId("") .build(); + String testJson = "{\"accNum\":\"MTc0MTIzMjk4NzQyNTg0Ng==\",\"amount\":\"MC4wMQ==\",\"cardAccNum\":\"MTg3NzMwOTAwMTU0NTI0NDY3Mw==\",\"dealTime\":\"MjAyNS0wMy0wNiAxNjo0NTowMA==\",\"opId\":\"\",\"serialNum\":\"NzYx\",\"sign\":\"3EFD38EA76BDC32165841852F0EEFD5E\"}"; Map paramsMap = BeanUtil.beanToMap(params); Map body = zyApiTool.getSelfEncryptionMap(paramsMap, "accNum", "cardAccNum", "amount", "serialNum", "dealTime", "opId"); ZySelfPayDto bodyObj = JSONUtil.toBean(JSONUtil.toJsonStr(body), ZySelfPayDto.class);