From 9204b7cfb931b390ed78d211937365476fd1db9b Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Mon, 10 Aug 2020 18:51:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=A0=E8=A7=A3=E5=AF=86?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cloud-common-socket/pom.xml | 10 +++++-- .../socket/service/AbstractSocketService.java | 27 ++++++++++++++++++- .../com/cm/socket/service/ISocketService.java | 4 +-- 3 files changed, 36 insertions(+), 5 deletions(-) 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; }