update 联联平台接口校验令牌

This commit is contained in:
Lemon
2023-05-29 14:40:46 +08:00
parent d4682926fd
commit ff52e01f98
3 changed files with 55 additions and 22 deletions

View File

@@ -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<String, String> 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<String, String> 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<String, String> 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<String, String> resultMap = lianLianService.checkoutSign(dto);
if (resultMap == null) {

View File

@@ -233,18 +233,18 @@ public class SpringBootTestController {
String operatorId = "I4XLPQPV";
String operatorSecret = "3DSBTWHVIC6KVCKI";
// 请求data
// Map<String, String> data = new HashMap<>();
// data.put("OperatorID", operatorId);
// data.put("OperatorSecret", operatorSecret);
// String dataJson = JSONUtil.toJsonStr(data);
Map<String, String> 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<String, String> 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<String, String> resultMap = (Map<String, String>) 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<String, String> resultMap = (Map<String, String>) 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));
}