update 第三方平台解析密钥方法

This commit is contained in:
Lemon
2023-10-25 09:32:15 +08:00
parent 1377f9a488
commit f20e8a74ca
4 changed files with 58 additions and 43 deletions

View File

@@ -34,6 +34,7 @@ import com.jsowell.pile.vo.uniapp.PileConnectorDetailVO;
import com.jsowell.pile.vo.web.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -824,19 +825,23 @@ public class PileBasicInfoServiceImpl implements IPileBasicInfoService {
}
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("0");
list.add("1");
list.add("4");
list.add("3");
list.add("2");
list.add(null);
list.add("");
list = list.stream().filter(StringUtils::isNotBlank).collect(Collectors.toList());
list.sort(Comparator.comparing(Integer::new));
String s = RandomStringUtils.randomAlphanumeric(16);
System.out.println(s);
System.out.println(list);
// List<String> list = new ArrayList<>();
// list.add("0");
// list.add("1");
// list.add("4");
// list.add("3");
// list.add("2");
// list.add(null);
// list.add("");
//
// list = list.stream().filter(StringUtils::isNotBlank).collect(Collectors.toList());
// list.sort(Comparator.comparing(Integer::new));
//
// System.out.println(list);
}
/**

View File

@@ -216,10 +216,16 @@ public class LianLianServiceImpl implements LianLianService {
return result;
}
public static void main(String[] args) {
String s = RandomStringUtils.randomAlphanumeric(16).toUpperCase(Locale.ROOT);
System.out.println(s);
public static void main(String[] args) throws UnsupportedEncodingException {
String dataSecret = "vj3RWNsWIxT5MC2K";
String dataSecretIV = "jjkySnGlM3pbOUki";
String dataString = "JdVMdw0JVYvouzS4WA9APlqKyQJuTuvh43lDYGaVccrvMboNTVajQdkvtLfqq3+lxlUXkokSkGSDsmxNkUT/SQ==";
// 解密data
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes());
String dataStr = new String(plainText, StandardCharsets.UTF_8);
Map<String, String> resMap = (Map<String, String>) JSON.parse(dataStr);
String secret = resMap.get("OperatorSecret");
System.out.println(secret);
}
/**
@@ -302,12 +308,12 @@ public class LianLianServiceImpl implements LianLianService {
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(map).getBytes(),
configInfo.getOperatorSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getOperatorSecret());
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
return resultMap;
@@ -396,12 +402,12 @@ public class LianLianServiceImpl implements LianLianService {
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(map).getBytes(),
configInfo.getOperatorSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getOperatorSecret());
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
return resultMap;
@@ -492,12 +498,12 @@ public class LianLianServiceImpl implements LianLianService {
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(stationStatsInfo).getBytes(),
configInfo.getOperatorSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getOperatorSecret());
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
return resultMap;
@@ -552,12 +558,12 @@ public class LianLianServiceImpl implements LianLianService {
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(vo).getBytes(),
configInfo.getOperatorSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getOperatorSecret());
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
return resultMap;
@@ -614,12 +620,12 @@ public class LianLianServiceImpl implements LianLianService {
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(vo).getBytes(),
configInfo.getOperatorSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getOperatorSecret());
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
return resultMap;
@@ -682,12 +688,12 @@ public class LianLianServiceImpl implements LianLianService {
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(vo).getBytes(),
configInfo.getOperatorSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getOperatorSecret());
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
return resultMap;
@@ -734,7 +740,7 @@ public class LianLianServiceImpl implements LianLianService {
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getOperatorSecret());
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
return resultMap;
@@ -1071,7 +1077,7 @@ public class LianLianServiceImpl implements LianLianService {
String data = map.get("Data");
// 解密data
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(data),
operatorSecret.getBytes(), operatorSecret.getBytes());
dataSecret.getBytes(), dataSecretIv.getBytes());
String dataStr = new String(plainText, StandardCharsets.UTF_8);
// 转成对应的对象
QueryEquipChargeStatusDTO queryEquipChargeStatusDTO = JSONObject.parseObject(dataStr, QueryEquipChargeStatusDTO.class);
@@ -1241,12 +1247,12 @@ public class LianLianServiceImpl implements LianLianService {
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(map).getBytes(),
platformConfig.getOperatorSecret().getBytes(), platformConfig.getDataSecretIv().getBytes());
platformConfig.getDataSecret().getBytes(), platformConfig.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, platformConfig.getOperatorSecret());
String resultSign = GBSignUtils.sign(resultMap, platformConfig.getSignSecret());
resultMap.put("Sig", resultSign);
return resultMap;
@@ -1435,6 +1441,9 @@ public class LianLianServiceImpl implements LianLianService {
return null;
}
String operatorSecret = platformConfig.getOperatorSecret();
String dataSecret = platformConfig.getDataSecret();
String dataSecretIv = platformConfig.getDataSecretIv();
String signSecret = platformConfig.getSignSecret();
// 校验签名
Map<String, String> checkResultMap = checkoutSign(dto);
if (checkResultMap == null) {
@@ -1443,7 +1452,7 @@ public class LianLianServiceImpl implements LianLianService {
}
String dataString = checkResultMap.get("Data");
// 解密data
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), operatorSecret.getBytes(), operatorSecret.getBytes());
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIv.getBytes());
String dataStr = new String(plainText, "UTF-8");
Map<String, String> resMap = (Map<String, String>) JSON.parse(dataStr);
String secret = resMap.get("OperatorSecret");
@@ -1471,12 +1480,12 @@ public class LianLianServiceImpl implements LianLianService {
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(vo).getBytes(),
platformConfig.getDataSecret().getBytes(), platformConfig.getDataSecretIv().getBytes());
dataSecret.getBytes(), dataSecretIv.getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, operatorSecret);
String resultSign = GBSignUtils.sign(resultMap, signSecret);
resultMap.put("Sig", resultSign);
return resultMap;
@@ -1495,13 +1504,14 @@ public class LianLianServiceImpl implements LianLianService {
return null;
}
String operatorSecret = platformConfig.getOperatorSecret();
String signSecret = platformConfig.getSignSecret();
Map<String, String> map = Maps.newLinkedHashMap();
map.put("OperatorID", dto.getOperatorID());
map.put("Data", dto.getData());
map.put("TimeStamp", dto.getTimeStamp());
map.put("Seq", dto.getSeq());
String sign = GBSignUtils.sign(map, operatorSecret);
String sign = GBSignUtils.sign(map, signSecret);
System.out.println(sign);
// 验证签名 得到请求方传过来的签名sig->自己拿到请求体后再按双方约定的协议生成一个sig->对比两个sig是否一致

View File

@@ -309,12 +309,12 @@ public class NRServiceImpl implements NRService {
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(map).getBytes(),
configInfo.getOperatorSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getOperatorSecret());
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
return resultMap;
@@ -520,12 +520,12 @@ public class NRServiceImpl implements NRService {
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(map).getBytes(),
configInfo.getOperatorSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getOperatorSecret());
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
return resultMap;
@@ -600,12 +600,12 @@ public class NRServiceImpl implements NRService {
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(resultList).getBytes(),
configInfo.getOperatorSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getOperatorSecret());
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
return resultMap;

View File

@@ -209,12 +209,12 @@ public class ZDLServiceImpl implements ZDLService {
Map<String, String> resultMap = Maps.newLinkedHashMap();
// 加密数据
byte[] encryptText = Cryptos.aesEncrypt(JSONObject.toJSONString(map).getBytes(),
configInfo.getOperatorSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
String encryptData = Encodes.encodeBase64(encryptText);
resultMap.put("Data", encryptData);
// 生成sig
String resultSign = GBSignUtils.sign(resultMap, configInfo.getOperatorSecret());
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
resultMap.put("Sig", resultSign);
return resultMap;