From e5475998623944f2ffacaf0e130083aae81f3954 Mon Sep 17 00:00:00 2001 From: yqy Date: Fri, 24 Dec 2021 16:41:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=9B=9E=E8=B0=83=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/controller/RechargeController.java | 2 +- .../service/AccountRechargeService.java | 2 +- .../impl/AccountRechargeServiceImpl.java | 56 ++++++++++++------- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/controller/RechargeController.java b/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/controller/RechargeController.java index cba8bcf..9ef5bdb 100644 --- a/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/controller/RechargeController.java +++ b/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/controller/RechargeController.java @@ -40,7 +40,7 @@ public class RechargeController { @ApiOperation(value = "支付回调") @RequestMapping(value = "/pay-notify") - public CommonResult frontRcvResponse(HttpServletRequest request) throws Exception { + public CommonResult frontRcvResponse(HttpServletRequest request){ return accountRechargeService.pcNotifyResponse(request); } diff --git a/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/service/AccountRechargeService.java b/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/service/AccountRechargeService.java index 4d002ea..63b80e3 100644 --- a/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/service/AccountRechargeService.java +++ b/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/service/AccountRechargeService.java @@ -31,7 +31,7 @@ public interface AccountRechargeService { * @param request * @return */ - CommonResult pcNotifyResponse(HttpServletRequest request) throws Exception; + CommonResult pcNotifyResponse(HttpServletRequest request); /** * 同步历史数据支付创建订单 diff --git a/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/service/impl/AccountRechargeServiceImpl.java b/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/service/impl/AccountRechargeServiceImpl.java index b32ecb0..bc4d83a 100644 --- a/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/service/impl/AccountRechargeServiceImpl.java +++ b/service/trade-service-others/trade-service-others-account/src/main/java/com/hchbox/module/service/impl/AccountRechargeServiceImpl.java @@ -38,6 +38,7 @@ import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.time.LocalTime; +import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -142,13 +143,15 @@ public class AccountRechargeServiceImpl implements AccountRechargeService { */ @Override public CommonResult pcNotifyResponse(HttpServletRequest request) { + log.info("======================支付回调开始时间:======================{}", LocalTime.now()); int i = 0; PayOrder order = null; try { //获取支付宝GET过来反馈信息 - Map params = new HashMap<>(DefaultNumberConstants.TWO_NUMBER); +// Map params = new HashMap<>(DefaultNumberConstants.TWO_NUMBER); // 处理乱码问题 - checkParam(request, params); +// checkParam(request, params); + Map params = getAllRequestParam(request); Boolean flag = Factory.Payment.Common().verifyNotify(params); //商户订单号 String orderNo = new String(request.getParameter(PayConstants.OUT_TRADE_NO). @@ -206,7 +209,6 @@ public class AccountRechargeServiceImpl implements AccountRechargeService { String orderNo = String.valueOf(IdUtil.getSnowflake(workerId, datacenterId).nextId()); payTwoOrder.setAnticipateNum(NumberUtil.div(payTwoOrder.getAmount(), BigDecimal.valueOf(amount)).longValue()); Double num = payTwoOrder.getAmount() + payTwoOrder.getIdenticalAmount(); -// Double num = 0.01; // 生成返回对象 response = Factory.Payment.Page() .pay(PayConstants.PAY_TITLE + orderNo, orderNo, num.toString(), aliPay.getNotifyUrlTwo()); @@ -238,13 +240,15 @@ public class AccountRechargeServiceImpl implements AccountRechargeService { */ @Override public CommonResult pcTwoNotifyResponse(HttpServletRequest request) { + log.info("======================同步支付回调开始时间:======================{}", LocalTime.now()); int i = 0; PayTwoOrder order = null; try { //获取支付宝GET过来反馈信息 - Map params = new HashMap<>(DefaultNumberConstants.TWO_NUMBER); +// Map params = new HashMap<>(DefaultNumberConstants.TWO_NUMBER); // 处理乱码问题 - checkParam(request, params); +// checkParam(request, params); + Map params = getAllRequestParam(request); Boolean flag = Factory.Payment.Common().verifyNotify(params); //商户订单号 String orderNo = new String(request.getParameter(PayConstants.OUT_TRADE_NO). @@ -287,21 +291,33 @@ public class AccountRechargeServiceImpl implements AccountRechargeService { return CommonResult.successfulOperation(); } - private void checkParam(HttpServletRequest request, Map params) { - Map requestParams = request.getParameterMap(); - if (CollectionUtils.isNotEmpty(requestParams.keySet())) { - for (String name : requestParams.keySet()) { - String[] values = requestParams.get(name); - String valueStr = ""; - for (int i = 0; i < values.length; i++) { - valueStr = (i == values.length - 1) ? valueStr + values[i] - : valueStr + values[i] + StrUtil.COMMA; - } - //乱码解决,这段代码在出现乱码时使用 - valueStr = new String(valueStr.getBytes - (StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); - params.put(name, valueStr); - } +// private void checkParam(HttpServletRequest request, Map params) { +// Map requestParams = request.getParameterMap(); +// if (CollectionUtils.isNotEmpty(requestParams.keySet())) { +// for (String name : requestParams.keySet()) { +// String[] values = requestParams.get(name); +// String valueStr = ""; +// for (int i = 0; i < values.length; i++) { +// valueStr = (i == values.length - 1) ? valueStr + values[i] +// : valueStr + values[i] + StrUtil.COMMA; +// } +// //乱码解决,这段代码在出现乱码时使用 +// valueStr = new String(valueStr.getBytes +// (StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); +// params.put(name, valueStr); +// } +// } +// } + + //得到请求的参数 + private Map getAllRequestParam(final HttpServletRequest request) { + Map res = new HashMap<>(); + Enumeration temp = request.getParameterNames(); + while (temp.hasMoreElements()) { + String en = (String) temp.nextElement(); + String value = request.getParameter(en); + res.put(en, value); } + return res; } }