From 05bd28159e35aa6b101287f49ed5ab071d6894e0 Mon Sep 17 00:00:00 2001 From: yuyang <2265829957@qq.com> Date: Tue, 28 Sep 2021 14:26:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=81=9C=E6=AD=A2=E5=85=85=E7=94=B5=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=AE=A2=E5=8D=95=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/XhpcChargeOrderServiceImpl.java | 7 ++- .../controller/AlipayPaymentController.java | 60 +++++++++++++------ .../src/main/resources/bootstrap.yml | 2 +- 3 files changed, 50 insertions(+), 19 deletions(-) diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java index dbdc89ac..7b31c737 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java @@ -190,6 +190,8 @@ public class XhpcChargeOrderServiceImpl implements IXhpcChargeOrderService { if(number !=0){ startChargingData.setSoc(number); } + logger.info("<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>:"+number); + logger.info("<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>:"+startChargingData.getSoc()); R r1 = powerPileService.startCharging(startChargingData); logger.info("<<<<<<<<<<<<<<<<<<<<<<<<充电返回>>>>>>>>>>>>>>>>>"); @@ -247,8 +249,11 @@ public class XhpcChargeOrderServiceImpl implements IXhpcChargeOrderService { if(xhpcChargingPileById.get("communicationProtocolVersion")!=null && !"".equals(xhpcChargingPileById.get("communicationProtocolVersion").toString())){ version=xhpcChargingPileById.get("communicationProtocolVersion").toString(); } + //获取充电订单号 + XhpcChargeOrder order = xhpcChargeOrderMapper.getChargingOrderId(chargingOrderId); - R oa = powerPileService.stopCharging(xhpcTerminal.getPileSerialNumber(), xhpcTerminal.getSerialNumber().substring(14), version); + + R oa = powerPileService.stopCharging(order.getSerialNumber(),xhpcTerminal.getPileSerialNumber(), xhpcTerminal.getSerialNumber().substring(14), version); logger.info("<<<<<<<<<<<<<<<<<<<<<<<<停止充电返回>>>>>>>>>>>>>>>>>"); logger.info("<<<<<<<<<<<<<<<<<<<<<<<<"+oa.getCode()+">>>>>>>>>>>>>>>>>"); logger.info("<<<<<<<<<<<<<<<<<<<<<<<<"+oa.getMsg()+">>>>>>>>>>>>>>>>>"); diff --git a/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/controller/AlipayPaymentController.java b/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/controller/AlipayPaymentController.java index 5e4a58bb..54902644 100644 --- a/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/controller/AlipayPaymentController.java +++ b/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/controller/AlipayPaymentController.java @@ -1,36 +1,35 @@ package com.xhpc.payment.controller; -import cn.hutool.core.map.MapUtil; -import com.alibaba.fastjson.JSONObject; import com.alipay.api.AlipayApiException; import com.alipay.api.AlipayClient; import com.alipay.api.DefaultAlipayClient; -import com.alipay.api.domain.AlipayTradeAppPayModel; import com.alipay.api.internal.util.AlipaySignature; import com.alipay.api.request.AlipayTradeCreateRequest; -import com.alipay.api.response.AlipayTradeAppPayResponse; import com.alipay.api.response.AlipayTradeCreateResponse; import com.xhpc.common.core.constant.HttpStatus; import com.xhpc.common.core.constant.StatusConstants; import com.xhpc.common.core.utils.StringUtils; import com.xhpc.common.core.web.domain.AjaxResult; import com.xhpc.payment.domain.XhpcRechargeOrder; -import com.xhpc.payment.mapper.XhpcUserAccountStatementMapper; import com.xhpc.payment.service.IXhpcRechargeOrderService; import com.xhpc.payment.service.IXhpcRefundOrderService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.net.URLEncoder; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.HashMap; import java.util.Map; +import java.util.Set; @RestController @@ -44,7 +43,7 @@ public class AlipayPaymentController { private IXhpcRechargeOrderService iXhpcRechargeOrderService; //@Autowired //private XhpcUserAccountStatementMapper xhpcUserAccountStatementMapper; - + private static final Logger logger = LoggerFactory.getLogger(AlipayPaymentController.class); @Autowired private IXhpcRefundOrderService iXhpcRefundOrderService; @@ -60,9 +59,9 @@ public class AlipayPaymentController { if (StringUtils.isEmpty(amount)) { return AjaxResult.error(HttpStatus.NOT_NULL, "充值金额不能为空"); }else{ - if(new BigDecimal(5).compareTo(new BigDecimal(amount))==1){ - return AjaxResult.error(HttpStatus.NOT_NULL, "充值金额不能少于5元"); - } +// if(new BigDecimal(5).compareTo(new BigDecimal(amount))==1){ +// return AjaxResult.error(HttpStatus.NOT_NULL, "充值金额不能少于5元"); +// } } //用户信息id String userId = StringUtils.valueOf(map.get("userId")); @@ -78,18 +77,17 @@ public class AlipayPaymentController { //生成充值订单 XhpcRechargeOrder xhpcRechargeOrder = iXhpcRechargeOrderService.addRechargeOrder(userId, BigDecimal.valueOf(Double.parseDouble(amount)), "2", orderNumber); String attach = attachYu(StringUtils.valueOf(xhpcRechargeOrder.getRechargeOrderId()), StringUtils.valueOf(amount), null, orderNumber); - AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", environment.getProperty("ALIPAYAPPID"), environment.getProperty("ALIPAYPRIVATEKEY"), "json", "utf-8", environment.getProperty("ALIPAYPUBLICKEY"), "RSA2"); AlipayTradeCreateRequest request = new AlipayTradeCreateRequest(); - - request.setBizContent("{" + - "\"out_trade_no\":\""+orderNumber+"\"," + + String encode = URLEncoder.encode(attach); + System.out.println("encode :"+encode); + request.setBizContent("{" + "\"out_trade_no\":\""+orderNumber+"\"," + "\"total_amount\":"+amount+"," + "\"subject\":\"小华充电\"," + "\"timeout_express\":\"30m\"," + + "\"passback_params\":\""+encode+"\"," + "\"buyer_id\":\""+openid+"\"" + "}"); - //"\"passback_params\":\""+attach+"\"," + request.setNotifyUrl(environment.getProperty("ALIPAYPSERVERDOMAIN")); try { //这里和普通的接口调用不同,使用的是sdkExecute @@ -132,12 +130,15 @@ public class AlipayPaymentController { valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8"); params.put(name, valueStr); } + logger.info("支付宝回调接口1111>>>>>:"+params.toString()); //调用SDK验证签名 boolean signVerified = AlipaySignature.rsaCheckV1(params, environment.getProperty("ALIPAYPUBLICKEY"), "utf-8", "RSA2"); //boolean类型signVerified为true时 则验证成功 if (signVerified) { //获取到支付的状态 TRADE_SUCCESS则支付成功 String trade_status = request.getParameter("trade_status"); + Map yu = convertRequestParamsToMap(request); + logger.info("支付宝回调接口>>>>>:"+yu.toString()); if (trade_status.equals("TRADE_SUCCESS")) { System.out.println("支付成功"); } else { @@ -146,6 +147,7 @@ public class AlipayPaymentController { } //签名验证失败 else { + logger.info("签名验证失败>>>>>:"+params.toString()); System.out.println(AlipaySignature.getSignCheckContentV1(params)); } } @@ -161,4 +163,28 @@ public class AlipayPaymentController { String attach = attachSB.substring(1); return attach; } + + + // 将request中的参数转换成Map + private Map convertRequestParamsToMap(HttpServletRequest request) { + Map retMap = new HashMap(); + Set> entrySet = request.getParameterMap().entrySet(); + for (Map.Entry entry : entrySet) { + String name = entry.getKey(); + String[] values = entry.getValue(); + int valLen = values.length; + if (valLen == 1) { + retMap.put(name, values[0]); + } else if (valLen > 1) { + StringBuilder sb = new StringBuilder(); + for (String val : values) { + sb.append(",").append(val); + } + retMap.put(name, sb.toString().substring(1)); + } else { + retMap.put(name, ""); + } + } + return retMap; + } } diff --git a/xhpc-modules/xhpc-payment/src/main/resources/bootstrap.yml b/xhpc-modules/xhpc-payment/src/main/resources/bootstrap.yml index 243c4671..269b4a83 100644 --- a/xhpc-modules/xhpc-payment/src/main/resources/bootstrap.yml +++ b/xhpc-modules/xhpc-payment/src/main/resources/bootstrap.yml @@ -43,7 +43,7 @@ SERVERDOMAIN: "http://xhpc.scxhua.com/prod-api/xhpc-payment/wx/paymentCallback" WXTRANSFERS: "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers" #支付宝支付回调地址 -ALIPAYPSERVERDOMAIN: "https://xhpc.scxhua.com/prod-api/alipay/notifyUrl" +ALIPAYPSERVERDOMAIN: "https://xhpc.scxhua.com/prod-api/xhpc-payment/alipay/notifyUrl" #支付宝公钥 ALIPAYPUBLICKEY: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjHDksTgZTpf0wh7oeTVRp0h3SqzTM2smjEJnx9jF1+q3WSXLRB4OzSzq7VsJ/szcyK10ZGO5PxeQ4u9GAG/U+7xhs7ei1cJB/Er55Sg9SbjfkTpwlDv181UJCRJJ/IAcqyqezwTpB8e2trYmHKovUdt0KR9/tVkGa7hsNd5GfxTOUaAFc3zADqRVM+wGimtG0NYfOF2f8tkmBEAiMMLKq5pbAnHU723a1cm/nfVp7gvXfsnO0k2GvRuHzb8mxIhWLiAnwdK9gEu5za/jWxo/xIvf2sdJPYdWj+yfyzA2e1fJkx4uRUzX31CXxZvP2/tfEcnTdI0gxN+OH2eAMiPVswIDAQAB" #应用私钥