Parcourir la source

[功能修复]调整Keys

liuf il y a 1 an
Parent
commit
422367991a

+ 1 - 0
src/main/java/com/tmzn/devicelinkykc/DeviceLinkYkcApplication.java

@@ -33,6 +33,7 @@ public class DeviceLinkYkcApplication {
                     redisCache.deleteObject(key);
                 });
             }
+            redisCache.deleteObject(RedisConstant.YKC_KEY_MAP);
             if (redisCache.hasKey(RedisConstant.DEVICE_INFO)){
                 redisCache.deleteObject(RedisConstant.DEVICE_INFO);
             }

+ 2 - 0
src/main/java/com/tmzn/devicelinkykc/constant/RedisConstant.java

@@ -18,6 +18,8 @@ public class RedisConstant {
     //通讯帧的密钥
     public static final String KEYS= "keysYKC";
 
+    public static final String YKC_KEY_MAP = "ykc_key_map";
+
     //全部设备的imei
     public static final String DEVICE_INFO="deviceInfoYKC";
     public static final String DEVICE_IMEI_PILE_MAP="device_imei_pile_map";

+ 4 - 2
src/main/java/com/tmzn/devicelinkykc/controller/DeviceController.java

@@ -172,12 +172,14 @@ public class DeviceController {
             }
             deviceList.stream().forEach(device -> {
                 //修改
-                if (redisCachel.hasKey(RedisConstant.KEYS+device.getPileCode())){
+                String key = redisCachel.getCacheMapValue(RedisConstant.YKC_KEY_MAP,device.getPileCode());
+                if(key!=null){
                     if (socketHandle.existDeviceConnection(device.getPileCode())){
                         socketHandle.removeDeviceConnection(device.getPileCode());
                     }
-                    redisCachel.deleteObject(RedisConstant.KEYS+device.getPileCode());
+                    redisCachel.deleteCacheMapValue(RedisConstant.YKC_KEY_MAP,device.getPileCode());
                 }
+
                 Device byId = deviceService.getById(device.getId());
                 byId.setIp(device.getIp());
                 byId.setPort(device.getPort());

+ 7 - 3
src/main/java/com/tmzn/devicelinkykc/frameMsg/frameType/BillingModelFrame.java

@@ -41,7 +41,9 @@ public class BillingModelFrame {
         byte[] params = checkModel(deviceConnectionMsg);
 
         if(deviceConnectionMsg.getIs18()){
-            String key = redisCache.getCacheObject(RedisConstant.KEYS+deviceConnectionMsg.getDeviceId());
+//            String key = redisCache.getCacheObject(RedisConstant.KEYS+deviceConnectionMsg.getDeviceId());
+            String key = redisCache.getCacheMapValue(RedisConstant.YKC_KEY_MAP,deviceConnectionMsg.getDeviceId());
+
             byte[] encrypt = new byte[0];
             try {
                 encrypt = Encrytion.aesEncrypt(params, key.getBytes());
@@ -91,7 +93,8 @@ public class BillingModelFrame {
     public  void getBillingModel(DeviceConnectionMsg deviceConnectionMsg){
         byte[] params = getModelParams(deviceConnectionMsg);
         if(deviceConnectionMsg.getIs18()){
-            String key = redisCache.getCacheObject(RedisConstant.KEYS+deviceConnectionMsg.getDeviceId());
+//            String key = redisCache.getCacheObject(RedisConstant.KEYS+deviceConnectionMsg.getDeviceId());
+            String key = redisCache.getCacheMapValue(RedisConstant.YKC_KEY_MAP,deviceConnectionMsg.getDeviceId());
             try {
                 byte[] encrypt = Encrytion.aesEncrypt(params, key.getBytes());
                 byte[] spliceing = FrameDataSplicing.spliceing(deviceConnectionMsg.getMessageCount(), DeviceSendYkc.BILLING_MODEL_REQUEST.getFrameType(), DeviceSendYkc.BILLING_MODEL_REQUEST.getEncryptFlag(), encrypt, encrypt.length, deviceConnectionMsg.getIs18());
@@ -129,7 +132,8 @@ public class BillingModelFrame {
     public void resp(DeviceConnectionMsg deviceConnectionMsg,byte res){
         byte[] params = params(deviceConnectionMsg.getDeviceId(),res);
         if(deviceConnectionMsg.getIs18()){
-            String key = redisCache.getCacheObject(RedisConstant.KEYS+deviceConnectionMsg.getDeviceId());
+//            String key = redisCache.getCacheObject(RedisConstant.KEYS+deviceConnectionMsg.getDeviceId());
+            String key = redisCache.getCacheMapValue(RedisConstant.YKC_KEY_MAP,deviceConnectionMsg.getDeviceId());
             try {
                 byte[] encrypt = Encrytion.aesEncrypt(params, key.getBytes());
                 byte[] spliceing = FrameDataSplicing.spliceing(deviceConnectionMsg.getMessageCount(), DeviceSendYkc.BILLING_MODEL_SETTING_RESPONSE.getFrameType(), DeviceSendYkc.BILLING_MODEL_SETTING_RESPONSE.getEncryptFlag(), encrypt, encrypt.length, deviceConnectionMsg.getIs18());

+ 4 - 2
src/main/java/com/tmzn/devicelinkykc/frameMsg/frameType/CharngingPushFrame.java

@@ -36,7 +36,8 @@ public class CharngingPushFrame {
         byte[] params = startParams(deviceConnectionMsg.getDeviceId(), trans, port, result, reson);
         log.info("{}startStatus>开始充电回复>>>"+DataConversion.bytesToHexString(params),deviceConnectionMsg.getDeviceId());
         if(deviceConnectionMsg.getIs18()){
-            String key = redisCache.getCacheObject(RedisConstant.KEYS+deviceConnectionMsg.getDeviceId());
+//            String key = redisCache.getCacheObject(RedisConstant.KEYS+deviceConnectionMsg.getDeviceId());
+            String key = redisCache.getCacheMapValue(RedisConstant.YKC_KEY_MAP,deviceConnectionMsg.getDeviceId());
             try {
                 byte[] encrypt = Encrytion.aesEncrypt(params, key.getBytes());
                 byte[] spliceing = FrameDataSplicing.spliceing(deviceConnectionMsg.getMessageCount(), DeviceSendYkc.START_CHARNGING_RESPONSE.getFrameType(), DeviceSendYkc.START_CHARNGING_RESPONSE.getEncryptFlag(), encrypt, encrypt.length, deviceConnectionMsg.getIs18());
@@ -100,7 +101,8 @@ public class CharngingPushFrame {
         log.info("endStatus>停止充电回复>>>"+DataConversion.bytesToHexString(params));
 
         if(deviceConnectionMsg.getIs18()){
-            String key = redisCache.getCacheObject(RedisConstant.KEYS+deviceConnectionMsg.getDeviceId());
+//            String key = redisCache.getCacheObject(RedisConstant.KEYS+deviceConnectionMsg.getDeviceId());
+            String key = redisCache.getCacheMapValue(RedisConstant.YKC_KEY_MAP,deviceConnectionMsg.getDeviceId());
             try {
                 byte[] encrypt = Encrytion.aesEncrypt(params, key.getBytes());
                 byte[] spliceing = FrameDataSplicing.spliceing(deviceConnectionMsg.getMessageCount(), DeviceSendYkc.STOP_CHARNGING_RESPONSE.getFrameType(), DeviceSendYkc.STOP_CHARNGING_RESPONSE.getEncryptFlag(), encrypt, encrypt.length, deviceConnectionMsg.getIs18());

+ 3 - 1
src/main/java/com/tmzn/devicelinkykc/frameMsg/frameType/LoginFrame.java

@@ -144,7 +144,9 @@ public class LoginFrame {
         //当前通讯的密钥缓存到redis
         //20240627:要求对接其他按云快充对接的
         GdDispostion dispostionServiceById = gdDispostionService.getById(device.getOperatorsId());
-        redisCache.setCacheObject(RedisConstant.KEYS +device.getPileCode(), str_key);
+//        redisCache.setCacheObject(RedisConstant.KEYS +device.getPileCode(), str_key);
+        redisCache.setCacheMapValue(RedisConstant.YKC_KEY_MAP,device.getPileCode(),str_key);
+
         log.info("LOGIN>>>>16weikey>>>>>>>"+str_key);
         byte[] bytes = Encrytion.rsaEncrypt(str_key.getBytes(),dispostionServiceById.getCode());
         byte[] base_encode = Base64.getEncoder().encode(bytes);

+ 2 - 1
src/main/java/com/tmzn/devicelinkykc/frameMsg/frameType/RealTimeStatusPushFrame.java

@@ -37,7 +37,8 @@ public class RealTimeStatusPushFrame {
             try {
                 byte[] send = upStatusDevice(trans, pileCode, guns, gunsStatus, gunsInsert, voltage, power, elec, money, time);
                 log.info("deviceStatusPush>设备实时状态上报>>>"+DataConversion.bytesToHexString(send));
-                String key = redisCache.getCacheObject(RedisConstant.KEYS+deviceConnectionMsg.getDeviceId());
+//                String key = redisCache.getCacheObject(RedisConstant.KEYS+deviceConnectionMsg.getDeviceId());
+                String key = redisCache.getCacheMapValue(RedisConstant.YKC_KEY_MAP,deviceConnectionMsg.getDeviceId());
                 // log.info("deviceStatusPush>设备实时状态key>>>"+key);
                 encrypt = Encrytion.aesEncrypt(send, key.getBytes());
                 log.info("deviceStatusPush>设备实时状态encrypt msg::>>>"+DataConversion.bytesToHexString(encrypt));

+ 2 - 1
src/main/java/com/tmzn/devicelinkykc/frameMsg/frameType/RemoteBalanceUpdatePushFrame.java

@@ -31,7 +31,8 @@ public class RemoteBalanceUpdatePushFrame {
             try {
                 byte[] send = params(deviceConnectionMsg.getDeviceId(), card,reason);
                 log.info("updateBalance>更新余额回复>>>"+DataConversion.bytesToHexString(send));
-                String key = redisCache.getCacheObject(RedisConstant.KEYS+deviceConnectionMsg.getDeviceId());
+//                String key = redisCache.getCacheObject(RedisConstant.KEYS+deviceConnectionMsg.getDeviceId());
+                String key = redisCache.getCacheMapValue(RedisConstant.YKC_KEY_MAP,deviceConnectionMsg.getDeviceId());
                 encrypt = Encrytion.aesEncrypt(send, key.getBytes());
             } catch (Exception e) {
                 log.info("pileCode:" + deviceConnectionMsg.getDeviceId() + " updateBalance params Exception");

+ 2 - 1
src/main/java/com/tmzn/devicelinkykc/frameMsg/frameType/TransactionFlowPushFrame.java

@@ -67,7 +67,8 @@ public class TransactionFlowPushFrame {
                 transCheck.setTime(System.currentTimeMillis());
 
                 //log.info("sendTrans>订单上送>>>"+DataConversion.bytesToHexString(params));
-                String key = redisCache.getCacheObject(RedisConstant.KEYS+deviceConnectionMsg.getDeviceId());
+//                String key = redisCache.getCacheObject(RedisConstant.KEYS+deviceConnectionMsg.getDeviceId());
+                String key = redisCache.getCacheMapValue(RedisConstant.YKC_KEY_MAP,deviceConnectionMsg.getDeviceId());
                 log.info("key>{}订单消息加密密钥>>>"+key,deviceConnectionMsg.getDeviceId());
                 encrypt = Encrytion.aesEncrypt(params, key.getBytes());
                 log.info("msg>{}订单加密消息>>>"+DataConversion.bytesToHexString(encrypt),deviceConnectionMsg.getDeviceId());

+ 2 - 1
src/main/java/com/tmzn/devicelinkykc/message/YkcMsgHandle.java

@@ -131,7 +131,8 @@ public class YkcMsgHandle {
                     logger.info("{},未加密消息,frame:{},data:{}",deviceConnectionMsg.getDeviceId(),framType, DataConversion.bytesToHexString(respone_msg));
                 } else {
                     try {
-                        String key = redisCache.getCacheObject(RedisConstant.KEYS + deviceConnectionMsg.getDeviceId());
+                        String key = redisCache.getCacheMapValue(RedisConstant.YKC_KEY_MAP,deviceConnectionMsg.getDeviceId());
+//                        String key = redisCache.getCacheObject(RedisConstant.KEYS + deviceConnectionMsg.getDeviceId());
                         respone_msg = Encrytion.decrypt(respone_msg, key.getBytes());
 
                         logger.info("{},加密消息,frame:{},data:{}",deviceConnectionMsg.getDeviceId(),framType, DataConversion.bytesToHexString(respone_msg));

+ 3 - 1
src/main/java/com/tmzn/devicelinkykc/service/impl/DeviceServiceImpl.java

@@ -91,7 +91,9 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
                 return AjaxResult.error("删除设备失败");
             }
             //通讯密钥也要删除掉
-            redisCache.deleteObject(RedisConstant.KEYS + pileCode);
+
+            redisCache.deleteCacheMapValue(RedisConstant.YKC_KEY_MAP,pileCode);
+//            redisCache.deleteObject(RedisConstant.KEYS + pileCode);
 
             if (redisCache.hasKey(RedisConstant.DEVICE_INFO)) {
                 Set<String> imeis = redisCache.getCacheObject(RedisConstant.DEVICE_INFO);

+ 2 - 1
src/main/java/com/tmzn/devicelinkykc/taskQueue/runner/DeviceOnlineRunner.java

@@ -89,7 +89,8 @@ public class DeviceOnlineRunner {
                 long nowTime = System.currentTimeMillis();
                 if ((nowTime - updateTime) > GAP_TIME) {
                     if (socketHandle.existDeviceConnection(deviceStatus.getPileCode())) {
-                        redisCache.deleteObject(RedisConstant.KEYS + deviceStatus.getPileCode());
+//                        redisCache.deleteObject(RedisConstant.KEYS + deviceStatus.getPileCode());
+                        redisCache.deleteCacheMapValue(RedisConstant.YKC_KEY_MAP,deviceStatus.getPileCode());
                         socketHandle.removeDeviceConnection(deviceStatus.getPileCode());
                     }
                     deviceStatus.setOnlineStatus(DeviceOnlineStatus.OFFLINE);