diff --git a/cloud-common-socket/pom.xml b/cloud-common-socket/pom.xml index d3fcfe9..61311be 100644 --- a/cloud-common-socket/pom.xml +++ b/cloud-common-socket/pom.xml @@ -14,13 +14,19 @@ com.cm - cloud-common + cloud-common-plugin 1.0.1-SNAPSHOT + + + com.cm + cloud-security + 1.0.1-SNAPSHOT + + io.netty netty-all - 4.1.50.Final diff --git a/cloud-common-socket/src/main/java/com/cm/socket/service/AbstractSocketService.java b/cloud-common-socket/src/main/java/com/cm/socket/service/AbstractSocketService.java index 0ed0f19..271e4e0 100644 --- a/cloud-common-socket/src/main/java/com/cm/socket/service/AbstractSocketService.java +++ b/cloud-common-socket/src/main/java/com/cm/socket/service/AbstractSocketService.java @@ -2,6 +2,7 @@ package com.cm.socket.service; import com.alibaba.fastjson.JSONObject; import com.cm.common.base.AbstractService; +import com.cm.common.utils.AesUtil; import com.cm.socket.enums.SocketCodeEnum; import com.cm.socket.enums.SocketTypeMessageEnum; import com.cm.socket.pojo.Message; @@ -22,13 +23,15 @@ import java.util.List; **/ public abstract class AbstractSocketService extends AbstractService implements ISocketService { + private static final String CONTENT_ENCODE_KEY = "Ts_Socket_Key_W_"; + /** * 读取信息业务 * * @param channelHandlerContext * @param readMessage */ - protected abstract void readMessageService(ChannelHandlerContext channelHandlerContext, Message readMessage); + protected abstract void readMessageService(ChannelHandlerContext channelHandlerContext, Message readMessage) throws Exception; /** * 输出信息 @@ -120,4 +123,26 @@ public abstract class AbstractSocketService extends AbstractService implements I return socketResult; } + /** + * 获取加密结果 + * + * @param content + * @return + * @throws Exception + */ + protected String getEncodeContent(String content) throws Exception { + return AesUtil.aesCommonEncoder(CONTENT_ENCODE_KEY, content); + } + + /** + * 获取解密结果 + * + * @param content + * @return + * @throws Exception + */ + protected String getDecodeContent(String content) throws Exception { + return AesUtil.aesCommonDecoder(CONTENT_ENCODE_KEY, content); + } + } diff --git a/cloud-common-socket/src/main/java/com/cm/socket/service/ISocketService.java b/cloud-common-socket/src/main/java/com/cm/socket/service/ISocketService.java index 05ff4b3..bba0756 100644 --- a/cloud-common-socket/src/main/java/com/cm/socket/service/ISocketService.java +++ b/cloud-common-socket/src/main/java/com/cm/socket/service/ISocketService.java @@ -21,13 +21,13 @@ public interface ISocketService { * @param channelHandlerContext * @param readMessage */ - void readMessage(ChannelHandlerContext channelHandlerContext, Message readMessage); + void readMessage(ChannelHandlerContext channelHandlerContext, Message readMessage) throws Exception; /** * 自动回复数据 * * @param channelHandlerContext */ - void autoReply(ChannelHandlerContext channelHandlerContext); + void autoReply(ChannelHandlerContext channelHandlerContext) throws Exception; }