Commit dd8c1191 authored by 赵啸非's avatar 赵啸非

修改udp 加密解密

parent 5113c16d
...@@ -22,6 +22,7 @@ import com.mortals.xhx.common.model.DefaultTbQueueMsgHeaders; ...@@ -22,6 +22,7 @@ import com.mortals.xhx.common.model.DefaultTbQueueMsgHeaders;
import com.mortals.xhx.common.model.MessageHeader; import com.mortals.xhx.common.model.MessageHeader;
import com.mortals.xhx.common.utils.BeanUtil; import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.common.utils.DownMsgTask; import com.mortals.xhx.common.utils.DownMsgTask;
import com.mortals.xhx.common.utils.EncryptUtil;
import com.mortals.xhx.common.utils.SendTaskThreadPool; import com.mortals.xhx.common.utils.SendTaskThreadPool;
import com.mortals.xhx.module.device.model.DeviceEntity; import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.service.DeviceService; import com.mortals.xhx.module.device.service.DeviceService;
...@@ -46,6 +47,9 @@ import java.util.Date; ...@@ -46,6 +47,9 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.mortals.xhx.common.key.Constant.DES_STR;
import static com.mortals.xhx.common.key.Constant.ENCRYPT_STR;
/** /**
* 设备 * 设备
* *
...@@ -124,7 +128,12 @@ public class DeviceApiController { ...@@ -124,7 +128,12 @@ public class DeviceApiController {
authInfo.setUploadTopicFilter(Constant.UPLOAD_TOPIC + deviceEntity.getDeviceCode()); authInfo.setUploadTopicFilter(Constant.UPLOAD_TOPIC + deviceEntity.getDeviceCode());
authInfo.setDownTopicFilter(Constant.DOWN_TOPIC + deviceEntity.getDeviceCode()); authInfo.setDownTopicFilter(Constant.DOWN_TOPIC + deviceEntity.getDeviceCode());
authInfo.setHomeUrl(platformEntity.getHomeUrl()); authInfo.setHomeUrl(platformEntity.getHomeUrl());
String content = AESUtil.encryptForApp(JSON.toJSONString(authInfo), secret);
// String content = AESUtil.encryptForApp(JSON.toJSONString(authInfo), secret);
String content = EncryptUtil.myEnscrt(JSON.toJSONString(authInfo), 9, DES_STR, ENCRYPT_STR);
deviceResp.setContent(content); deviceResp.setContent(content);
deviceEntity.setOnlineTime(new Date()); deviceEntity.setOnlineTime(new Date());
deviceEntity.setDeviceOnlineStatus(DeviceOnlineStatusEnum.在线.getValue()); deviceEntity.setDeviceOnlineStatus(DeviceOnlineStatusEnum.在线.getValue());
...@@ -461,6 +470,9 @@ public class DeviceApiController { ...@@ -461,6 +470,9 @@ public class DeviceApiController {
} }
private DeviceEntity checkDeviceExist(DeviceReq req) { private DeviceEntity checkDeviceExist(DeviceReq req) {
if (ObjectUtils.isEmpty(req.getDeviceCode())) {
throw new AppException("当前设备编码不存在!");
}
DeviceEntity deviceEntity = deviceService.getExtCache(req.getDeviceCode()); DeviceEntity deviceEntity = deviceService.getExtCache(req.getDeviceCode());
if (ObjectUtils.isEmpty(deviceEntity)) { if (ObjectUtils.isEmpty(deviceEntity)) {
throw new AppException("当前设备不存在!"); throw new AppException("当前设备不存在!");
......
...@@ -42,6 +42,7 @@ public final class Constant { ...@@ -42,6 +42,7 @@ public final class Constant {
*/ */
public static final String TOKEN = "token"; public static final String TOKEN = "token";
public static final String ENCRYPT_STR = "w4*KbUamPdZDnDpG"; public static final String ENCRYPT_STR = "w4*KbUamPdZDnDpG";
public static final String DES_STR = "FZV1D&tr";
public static final Integer SERVER_PORT = 8074; public static final Integer SERVER_PORT = 8074;
public static final Integer CLIENT_PORT = 8073; public static final Integer CLIENT_PORT = 8073;
......
...@@ -47,7 +47,7 @@ public class NettyUDPServerHandler extends SimpleChannelInboundHandler<DatagramP ...@@ -47,7 +47,7 @@ public class NettyUDPServerHandler extends SimpleChannelInboundHandler<DatagramP
resp.setCode(YesNoEnum.YES.getValue()); resp.setCode(YesNoEnum.YES.getValue());
log.info("receive->UDP entbefore:{}", packet.sender().toString() + "," + content); log.info("receive->UDP entbefore:{}", packet.sender().toString() + "," + content);
try { try {
content = EncryptUtil.myReEnscrt(content, 9, "FZV1D&tr", ENCRYPT_STR); content = EncryptUtil.myReEnscrt(content, 9, DES_STR, ENCRYPT_STR);
//EncryptUtil.decrypt(content, ENCRYPT_STR); //EncryptUtil.decrypt(content, ENCRYPT_STR);
log.info("receive->UDPafter:{}", packet.sender().toString() + "," + content); log.info("receive->UDPafter:{}", packet.sender().toString() + "," + content);
JSONObject jsonObject = JSON.parseObject(content); JSONObject jsonObject = JSON.parseObject(content);
...@@ -56,7 +56,7 @@ public class NettyUDPServerHandler extends SimpleChannelInboundHandler<DatagramP ...@@ -56,7 +56,7 @@ public class NettyUDPServerHandler extends SimpleChannelInboundHandler<DatagramP
resp.setMsg("获取服务端地址成功!"); resp.setMsg("获取服务端地址成功!");
if (!ObjectUtils.isEmpty(action) && "findserver".equals(action)) { if (!ObjectUtils.isEmpty(action) && "findserver".equals(action)) {
String URL = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.0.98:11021"); String URL = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.0.98:11071/m/api/register");
resp.setData(URL); resp.setData(URL);
} else { } else {
resp.setCode(YesNoEnum.NO.getValue()); resp.setCode(YesNoEnum.NO.getValue());
...@@ -64,7 +64,7 @@ public class NettyUDPServerHandler extends SimpleChannelInboundHandler<DatagramP ...@@ -64,7 +64,7 @@ public class NettyUDPServerHandler extends SimpleChannelInboundHandler<DatagramP
} }
InetSocketAddress remoteAddress = new InetSocketAddress(packet.sender().getHostName(), CLIENT_PORT); InetSocketAddress remoteAddress = new InetSocketAddress(packet.sender().getHostName(), CLIENT_PORT);
String sa = EncryptUtil.myEnscrt(JSON.toJSONString(resp), 9, "FZV1D&tr", ENCRYPT_STR); String sa = EncryptUtil.myEnscrt(JSON.toJSONString(resp), 9, DES_STR, ENCRYPT_STR);
DatagramPacket sendpacket = new DatagramPacket(Unpooled.copiedBuffer(sa, CharsetUtil.UTF_8), remoteAddress); DatagramPacket sendpacket = new DatagramPacket(Unpooled.copiedBuffer(sa, CharsetUtil.UTF_8), remoteAddress);
//ctx.writeAndFlush(new DatagramPacket(Unpooled.copiedBuffer(JSON.toJSONString(resp), CharsetUtil.UTF_8), packet.sender())); //ctx.writeAndFlush(new DatagramPacket(Unpooled.copiedBuffer(JSON.toJSONString(resp), CharsetUtil.UTF_8), packet.sender()));
......
...@@ -18,7 +18,9 @@ arrays|数组类型|[{"name":"zhang3"},{"name":"zhang2"}] ...@@ -18,7 +18,9 @@ arrays|数组类型|[{"name":"zhang3"},{"name":"zhang2"}]
### 服务端地址获取 ### 服务端地址获取
**广播端口:** 54321 **广播服务端口:** 8074
**广播客户端口:** 8073
**请求方式:** UDP **请求方式:** UDP
...@@ -55,7 +57,7 @@ data|String|数据对象|- ...@@ -55,7 +57,7 @@ data|String|数据对象|-
{ {
"msg":"获取服务端地址成功", "msg":"获取服务端地址成功",
"code":1, "code":1,
"data":"http://192.168.0.98:11021" "data":"http://192.168.0.98:11071/m/api/register"
} }
``` ```
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment