diff --git a/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/SuZhouPlatformController.java b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/SuZhouPlatformController.java index 283664240..35b251778 100644 --- a/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/SuZhouPlatformController.java +++ b/jsowell-admin/src/main/java/com/jsowell/api/thirdparty/SuZhouPlatformController.java @@ -43,7 +43,7 @@ public class SuZhouPlatformController extends ThirdPartyBaseController{ try { Map map = platformLogic.queryToken(dto); logger.info("{}-请求令牌, params:{}, result:{}", platformName, JSON.toJSONString(dto), JSON.toJSONString(map)); - return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig")); + return CommonResult.success(map); } catch (Exception e) { logger.error("{}-获取token接口, 异常, params:{}", platformName, JSON.toJSONString(dto), e); return CommonResult.failed("获取token发生异常"); @@ -76,7 +76,7 @@ public class SuZhouPlatformController extends ThirdPartyBaseController{ // 执行逻辑 Map map = platformLogic.queryStationsInfo(queryStationInfoDTO); - return CommonResult.success(0, "查询充电站信息成功!", map.get("Data"), map.get("Sig")); + return CommonResult.success(map); } catch (Exception e) { logger.info("{}-查询充电站信息 error:", platformName, e); } @@ -109,7 +109,7 @@ public class SuZhouPlatformController extends ThirdPartyBaseController{ // 执行逻辑 Map map = platformLogic.queryStationStatus(queryStationInfoDTO); - return CommonResult.success(0, "查询充电站状态信息成功!", map.get("Data"), map.get("Sig")); + return CommonResult.success(map); } catch (Exception e) { logger.error("{}-查询充电站状态信息 error:", platformName, e); } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/common/CommonResult.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/common/CommonResult.java index 6642f34f2..5d1b31fea 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/common/CommonResult.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lianlian/common/CommonResult.java @@ -5,6 +5,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.jsowell.common.enums.thirdparty.ThirdPartyReturnCodeEnum; import com.jsowell.thirdparty.lianlian.common.enums.ResultCode; +import java.util.LinkedHashMap; +import java.util.Map; + /** * 接口返回类 * @@ -48,6 +51,10 @@ public class CommonResult { return new CommonResult(ret, msg, data, sig); } + public static CommonResult success(Map map) { + return new CommonResult(Integer.parseInt(map.get("Ret")), map.get("Msg"), (T) map.get("Data"), map.get("Sig")); + } + /** * 失败返回结果 * diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SuZhouPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SuZhouPlatformServiceImpl.java index b97175a63..d43cea708 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SuZhouPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SuZhouPlatformServiceImpl.java @@ -96,52 +96,46 @@ public class SuZhouPlatformServiceImpl implements ThirdPartyPlatformService { */ @Override public Map queryToken(CommonParamsDTO dto) { + AccessTokenVO vo = new AccessTokenVO(); + // 0:成功;1:失败 + int succStat = 0; + // 0:无;1:无此对接平台;2:密钥错误; 3~99:自定义 + int failReason = 0; + String operatorId = dto.getOperatorID(); // 通过operatorId 查出 operatorSecret - ThirdPartySecretInfoVO suZhouSecretInfo = getSuZhouSecretInfo(); - - String operatorSecret = suZhouSecretInfo.getOurOperatorSecret(); - String dataSecret = suZhouSecretInfo.getOurDataSecret(); - String dataSecretIv = suZhouSecretInfo.getOurDataSecretIv(); - String signSecret = suZhouSecretInfo.getOurSigSecret(); - - // 解密data 获取参数中的OperatorSecret - try { + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getSuZhouSecretInfo(); + if (thirdPartySecretInfoVO == null) { + failReason = 1; + succStat = 1; + } else { + String ourOperatorSecret = thirdPartySecretInfoVO.getOurOperatorSecret(); + String dataSecret = thirdPartySecretInfoVO.getOurDataSecret(); + String dataSecretIv = thirdPartySecretInfoVO.getOurDataSecretIv(); + // 解密data 获取参数中的OperatorSecret String decrypt = Cryptos.decrypt(dto.getData(), dataSecret, dataSecretIv); String inputOperatorSecret = null; if (StringUtils.isNotBlank(decrypt)) { inputOperatorSecret = JSON.parseObject(decrypt).getString("OperatorSecret"); } - if (!StringUtils.equals(operatorSecret, inputOperatorSecret)) { - throw new RuntimeException("密钥不一致"); + // 对比密钥 + if (!StringUtils.equals(ourOperatorSecret, inputOperatorSecret)) { + failReason = 1; + succStat = 1; + } else { + // 生成token + String token = JWTUtils.createToken(operatorId, ourOperatorSecret, JWTUtils.ttlMillis); + vo.setAccessToken(token); + vo.setTokenAvailableTime((int) (JWTUtils.ttlMillis / 1000)); } - } catch (RuntimeException e) { - throw new BusinessException("2", "密钥错误"); } - - // 生成token - String token = JWTUtils.createToken(operatorId, operatorSecret, JWTUtils.ttlMillis); - // 组装返回参数 - AccessTokenVO vo = new AccessTokenVO(); - vo.setAccessToken(token); vo.setOperatorID(operatorId); - vo.setTokenAvailableTime((int) (JWTUtils.ttlMillis / 1000)); - vo.setFailReason(0); - vo.setSuccStat(0); - - Map resultMap = Maps.newLinkedHashMap(); - // 加密数据 - byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(), - dataSecret.getBytes(), dataSecretIv.getBytes()); - String encryptData = Encodes.encodeBase64(encryptText); // data - resultMap.put("Ret", "0"); - resultMap.put("Msg", "请求令牌成功!"); - resultMap.put("Data", encryptData); - // 生成sig - String resultSign = GBSignUtils.sign(resultMap, signSecret); - resultMap.put("Sig", resultSign); + vo.setFailReason(failReason); + vo.setSuccStat(succStat); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret() + , thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getOurSigSecret()); return resultMap; } @@ -214,7 +208,8 @@ public class SuZhouPlatformServiceImpl implements ThirdPartyPlatformService { map.put("PageCount", pageInfo.getPages()); map.put("ItemSize", pageInfo.getTotal()); map.put("StationInfos", resultList); - Map resultMap = ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret() + , thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getOurSigSecret()); return resultMap; } @@ -324,7 +319,8 @@ public class SuZhouPlatformServiceImpl implements ThirdPartyPlatformService { map.put("Total", total); map.put("StationStatusInfos", collect); - Map resultMap = ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret() + , thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getOurSigSecret()); return resultMap; } @@ -556,9 +552,8 @@ public class SuZhouPlatformServiceImpl implements ThirdPartyPlatformService { // 调用联联平台接口 String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_STATION_INFO.getValue(); - String jsonStr = JSON.toJSONString(info); JSONObject data = new JSONObject(); - data.put("StationInfo", jsonStr); + data.put("StationInfo", info); String jsonString = JSON.toJSONString(data); diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/GBSignUtils.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/GBSignUtils.java index 6d7deb154..859f1a33d 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/GBSignUtils.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/GBSignUtils.java @@ -8,6 +8,7 @@ import javax.crypto.Mac; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; import java.nio.charset.StandardCharsets; +import java.util.LinkedHashMap; import java.util.Map; public class GBSignUtils { @@ -32,6 +33,57 @@ public class GBSignUtils { } } + /** + * 经过测试,此版本方法与上面方法得到的结果相同 + * @param paramValues + * @param secret + * @return + */ + public static String signV2(Map paramValues, String secret) { + try { + StringBuilder sb = new StringBuilder(); + for (Object value : paramValues.values()) { + if (StringUtils.isNotBlank((String) value)) { + sb.append(value); + } + } + logger.debug("需要签名的内容:{},密钥{}", sb.toString(), secret); + byte[] md5Digest = HmacMD5Encrypt(sb.toString(), secret); + String result = Encodes.encodeHex(md5Digest).toUpperCase(); + logger.debug("HmacSHA1的签名内容:{}", result); + return result; + } catch (Exception e) { + throw new RuntimeException("数据签名出错", e); + } + } + + public static void main(String[] args) { + Map paramValues = new LinkedHashMap<>(); + paramValues.put("Ret", "0"); + paramValues.put("Msg", "123456"); + paramValues.put("Data", "123456888888"); + StringBuilder sb = new StringBuilder(); + for (String value : paramValues.values()) { + if (StringUtils.isNotBlank(value)) { + sb.append(value); + } + } + System.out.println(sb); + + System.out.println("----------------------------------------"); + Map paramValues1 = new LinkedHashMap<>(); + paramValues1.put("Ret", 0); + paramValues1.put("Msg", "123456"); + paramValues1.put("Data", "123456888888"); + StringBuilder sb1 = new StringBuilder(); + for (Object value : paramValues1.values()) { + if (StringUtils.isNotBlank(String.valueOf(value))) { + sb1.append(value); + } + } + System.out.println(sb1); + } + /** * 使用 HMAC-MD5 签名方法对对encryptText进行签名 * diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/ThirdPartyPlatformUtils.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/ThirdPartyPlatformUtils.java index a2f10fef0..8d324ad50 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/ThirdPartyPlatformUtils.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/ThirdPartyPlatformUtils.java @@ -54,6 +54,19 @@ public class ThirdPartyPlatformUtils { return resultMap; } + public static Map generateResultMapV2(Object obj, String dataSecret, String dataSecretIv, String signSecret) { + Map resultMap = Maps.newHashMap(); + // 加密数据 + String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(obj), dataSecret, dataSecretIv); + resultMap.put("Ret", "0"); + resultMap.put("Msg", "查询成功!"); + resultMap.put("Data", encryptData); + // 生成sig + String resultSign = GBSignUtils.sign(resultMap, signSecret); + resultMap.put("Sig", resultSign); + return resultMap; + } + /** * 从给定的URL字符串中提取充电桩枪口号。 * diff --git a/jsowell-ui/src/views/thirdparty/secret/detail.vue b/jsowell-ui/src/views/thirdparty/secret/detail.vue index b313084f2..bf6b63403 100644 --- a/jsowell-ui/src/views/thirdparty/secret/detail.vue +++ b/jsowell-ui/src/views/thirdparty/secret/detail.vue @@ -124,9 +124,12 @@ @click="clickNotificationStationStatus">推送 - - + + + + + @@ -144,11 +147,8 @@ @click="clickNotificationConnectorChargeStatus">推送 - - - - - + +