新增加解密方法

This commit is contained in:
wenc000 2020-08-10 18:51:59 +08:00
parent 21627cd878
commit 9204b7cfb9
3 changed files with 36 additions and 5 deletions

View File

@ -14,13 +14,19 @@
<dependencies>
<dependency>
<groupId>com.cm</groupId>
<artifactId>cloud-common</artifactId>
<artifactId>cloud-common-plugin</artifactId>
<version>1.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.cm</groupId>
<artifactId>cloud-security</artifactId>
<version>1.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.50.Final</version>
</dependency>
</dependencies>

View File

@ -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);
}
}

View File

@ -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;
}