diff --git a/jsowell-admin/src/main/java/com/jsowell/lianlian/LianLianController.java b/jsowell-admin/src/main/java/com/jsowell/lianlian/LianLianController.java index 6a8392a0e..122fb3ecc 100644 --- a/jsowell-admin/src/main/java/com/jsowell/lianlian/LianLianController.java +++ b/jsowell-admin/src/main/java/com/jsowell/lianlian/LianLianController.java @@ -6,6 +6,7 @@ import com.jsowell.common.core.controller.BaseController; import com.jsowell.common.enums.ykc.ReturnCodeEnum; import com.jsowell.common.exception.BusinessException; import com.jsowell.common.response.RestApiResponse; +import com.jsowell.common.util.JWTUtils; import com.jsowell.common.util.StringUtils; import com.jsowell.pile.domain.DockingPlatformConfig; import com.jsowell.pile.dto.*; @@ -22,6 +23,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletRequest; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; @@ -335,7 +337,7 @@ public class LianLianController extends BaseController { try { Map map = lianLianService.generateToken(dto); logger.info("联联平台请求令牌 result:{}", JSONObject.toJSONString(map)); - return CommonResult.success(0, "", map.get("data"), map.get("sig")); + return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig")); } catch (UnsupportedEncodingException e) { logger.error("获取token接口 异常"); return CommonResult.failed("获取token发生异常"); @@ -348,10 +350,16 @@ public class LianLianController extends BaseController { * @param dto * @return */ - @PostMapping("/query_stations_info") - public CommonResult query_stations_info(@RequestBody CommonParamsDTO dto) { + @PostMapping("/v1/query_stations_info") + public CommonResult query_stations_info(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { logger.info("联联平台查询充电站信息 params:{}", JSONObject.toJSONString(dto)); try { + // 校验令牌 + String token = request.getHeader("Authorization"); + if (!JWTUtils.checkThirdPartyToken(token)) { + // 校验失败 + return CommonResult.failed("令牌校验错误"); + } // 校验签名 Map resultMap = lianLianService.checkoutSign(dto); if (resultMap == null) { @@ -383,10 +391,16 @@ public class LianLianController extends BaseController { * @param dto * @return */ - @PostMapping("/query_station_status") - public CommonResult query_station_status(@RequestBody CommonParamsDTO dto) { + @PostMapping("/v1/query_station_status") + public CommonResult query_station_status(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { logger.info("联联平台查询充电站状态信息 params:{}", JSONObject.toJSONString(dto)); try { + // 校验令牌 + String token = request.getHeader("Authorization"); + if (!JWTUtils.checkThirdPartyToken(token)) { + // 校验失败 + return CommonResult.failed("令牌校验错误"); + } // 校验签名 Map resultMap = lianLianService.checkoutSign(dto); if (resultMap == null) { @@ -418,10 +432,16 @@ public class LianLianController extends BaseController { * @param dto * @return */ - @PostMapping("/query_station_stats") - public CommonResult query_station_stats(@RequestBody CommonParamsDTO dto) { + @PostMapping("/v1/query_station_stats") + public CommonResult query_station_stats(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { logger.info("联联平台查询统计信息 params:{}", JSONObject.toJSONString(dto)); try { + // 校验令牌 + String token = request.getHeader("Authorization"); + if (!JWTUtils.checkThirdPartyToken(token)) { + // 校验失败 + return CommonResult.failed("令牌校验错误"); + } // 校验签名 Map resultMap = lianLianService.checkoutSign(dto); if (resultMap == null) { diff --git a/jsowell-admin/src/test/java/SpringBootTestController.java b/jsowell-admin/src/test/java/SpringBootTestController.java index 3788fa9b5..93de41e1e 100644 --- a/jsowell-admin/src/test/java/SpringBootTestController.java +++ b/jsowell-admin/src/test/java/SpringBootTestController.java @@ -233,18 +233,18 @@ public class SpringBootTestController { String operatorId = "I4XLPQPV"; String operatorSecret = "3DSBTWHVIC6KVCKI"; // 请求data - // Map data = new HashMap<>(); - // data.put("OperatorID", operatorId); - // data.put("OperatorSecret", operatorSecret); - // String dataJson = JSONUtil.toJsonStr(data); + Map data = new HashMap<>(); + data.put("OperatorID", operatorId); + data.put("OperatorSecret", operatorSecret); + String dataJson = JSONUtil.toJsonStr(data); - JSONObject json = new JSONObject(); + // JSONObject json = new JSONObject(); // json.put("StationIDs", com.google.common.collect.Lists.newArrayList("1", "2")); - json.put("StationID", "2"); - json.put("StartTime", "2023-02-01"); - json.put("EndTime", "2023-06-01"); + // json.put("StationID", "2"); + // json.put("StartTime", "2023-02-01"); + // json.put("EndTime", "2023-06-01"); - String dataJson = JSONObject.toJSONString(json); + // String dataJson = JSONObject.toJSONString(json); // 加密 byte[] encryptText = Cryptos.aesEncrypt(dataJson.getBytes("UTF-8"), operatorSecret.getBytes(), operatorSecret.getBytes()); @@ -270,12 +270,13 @@ public class SpringBootTestController { // Map map = lianLianService.generateToken(dto); // String data1 = map.get("Data"); // // 解密data - // byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(data1), - // operatorSecret.getBytes(), operatorSecret.getBytes()); - // String dataStr = new String(plainText, "UTF-8"); - // Map resultMap = (Map) JSON.parse(dataStr); - // String token = resultMap.get("AccessToken"); - // System.out.println("解密后token:" + token); + String data1 = "JudlP17tnYuQc2zwOzmjJAb9hgghIymefG5v3ZzSOlOzRL6QcXMa5C5dy8acL2ZWEw5DOc0D3G2qSLsqBCZ9ft/8akGVLL0N4keLV9ipS2REJx1dvm1m4l9ONIP9czNeDTxUsS0b1aCkkxgn7OVYD+ch+yLH/3dMATb32aEjggGY31lu/S2vB+f2aO+icJ2EyAkakB8Huowb3ancZVs/sxCFbVZUmUyo6WEyLtfcn3moKwD52CWoECRgK7lUjBs3F8VKcMT/dTeSKEgZM3Z7/wrEzljKL4519XKyL2lYgJ3h/ewFDRZcnTIJAWskfiKnacZF7yZUTYj13h+sI9wrYmgT2ScqDCQVUI40gDnpewU="; + byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(data1), + operatorSecret.getBytes(), operatorSecret.getBytes()); + String dataStr = new String(plainText, "UTF-8"); + Map resultMap = (Map) JSON.parse(dataStr); + String token = resultMap.get("AccessToken"); + System.out.println("解密后token:" + token); // LianLianPushStationInfoDTO dto1 = LianLianPushStationInfoDTO.builder() @@ -315,6 +316,12 @@ public class SpringBootTestController { // 推送订单对账结果信息 // lianLianService.pushOrderReconciliationInfo("C27680791529"); + + // 测试生成、解密令牌 + // long ttlMillis = 60 * 60 * 24 * 1000; + // String token = JWTUtils.createToken(operatorId, operatorSecret, ttlMillis); + // System.out.println(JWTUtils.checkThirdPartyToken(token)); + } diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/JWTUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/JWTUtils.java index b16ee1d12..dc4ee56c0 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/util/JWTUtils.java +++ b/jsowell-common/src/main/java/com/jsowell/common/util/JWTUtils.java @@ -141,4 +141,10 @@ public class JWTUtils { } return memberToken; } + + public static void main(String[] args) { + long ttlMillis = 60 * 60 * 24 * 1000; + String token = createToken("I4XLPQPV", "3DSBTWHVIC6KVCKI", ttlMillis); + System.out.println(checkThirdPartyToken(token)); + } }