Commit 1fd92d46 by giaogiao

成员不存在,不能创建会话

parent c25d594a
......@@ -76,6 +76,17 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
ImClient client = imClientService.getClient();
// 成员不存在,不能创建会话
for (String id : imConversationCreate.getClientIds()) {
ImClient client2 = imClientService.getOne(new QueryWrapper<ImClient>().lambda()
.eq(ImClient::getFkAppid, client.getFkAppid())
.eq(ImClient::getClientId, id));
if (client2 == null) {
log.info(" 成员不存在,不能创建会话 client2 == null");
return ApiResult.result(ApiCode.CLIENT_NOT_FOUNT, null);
}
}
// 判断是否已经存在会话
// 两个用户如果已经创建过会话,不能重复创建会话
if (imConversationCreate.getClientIds().size() == 1) {
......
......@@ -3,11 +3,14 @@ package com.wecloud.im.tillo.netty.handler;
import com.alibaba.fastjson.JSONObject;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.wecloud.im.tillo.app_ws.WsHandler;
import com.wecloud.im.tillo.app_ws.model.WsConstants;
import com.wecloud.im.tillo.app_ws.service.MangerChannelService;
import com.wecloud.im.tillo.app_ws.utils.FullHttpRequestUtils;
import io.geekidea.springbootplus.config.constant.CommonConstant;
import io.geekidea.springbootplus.framework.common.api.ApiCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.shiro.jwt.JwtToken;
import io.geekidea.springbootplus.framework.shiro.service.ShiroLoginService;
import io.geekidea.springbootplus.framework.shiro.util.JwtUtil;
......@@ -17,7 +20,6 @@ import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpResponseStatus;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -54,8 +56,7 @@ public class NettyApiRequest {
*/
public void handle(ChannelHandlerContext ctx, Object msg, FullHttpRequest httpRequest) throws Exception {
if (!(msg instanceof FullHttpRequest)) {
// String context = JsonUtil.obj2Json(ResultModel.error(ResultStatus.REQUEST_ERROR));
String context = "JsonUtil.obj2Json(ResultModel.error(ResultStatus.REQUEST_ERROR))";
String context = new JsonMapper().writeValueAsString(ApiResult.fail());
FullHttpRequestUtils.send(ctx, context, HttpResponseStatus.OK);
return;
}
......@@ -81,7 +82,6 @@ public class NettyApiRequest {
private void initWs(ChannelHandlerContext ctx, FullHttpRequest httpRequest) throws Exception {
Map<String, String> paramMap = FullHttpRequestUtils.parameterParse(httpRequest);
String token = paramMap.get(WsConstants.TOKEN);
// String deviceId = paramMap.get(RequestHeaderConstants.DEVICE_ID);
DecodedJWT jwtInfo = JwtUtil.getJwtInfo(token);
String payload = jwtInfo.getPayload();
......@@ -92,22 +92,30 @@ public class NettyApiRequest {
String clientId = (String) jsonObject.get(CommonConstant.CLIENT_ID);
if (StringUtils.isBlank(token)) {
throw new AuthenticationException("token不能为空");
String context = new JsonMapper().writeValueAsString(ApiResult.result(ApiCode.FAIL, "token不能为空", (Object) null));
FullHttpRequestUtils.send(ctx, context, HttpResponseStatus.OK);
return;
}
if (JwtUtil.isExpired(token)) {
throw new AuthenticationException("JWT Token已过期,token:" + token);
String context = new JsonMapper().writeValueAsString(ApiResult.result(ApiCode.FAIL, "JWT Token已过期,token", (Object) null));
FullHttpRequestUtils.send(ctx, context, HttpResponseStatus.OK);
return;
}
// 验签token
JwtToken jwtToken = shiroLoginService.getTJwtTokenForRedis(token);
if (jwtToken == null) {
log.error("jwtToken == null ,token和redis不一致, clientId:" + clientId + ",token:" + token);
log.info("jwtToken == null ,token和redis不一致, clientId:" + clientId + ",token:" + token);
String context = new JsonMapper().writeValueAsString(ApiResult.result(ApiCode.FAIL, "jwtToken == null ,token和redis不一致", (Object) null));
FullHttpRequestUtils.send(ctx, context, HttpResponseStatus.OK);
return;
}
if ((!jwtToken.getClientId().equals(clientId)) || (!jwtToken.getAppKey().equals(appKey))) {
log.error("clientId appKey 不一致");
String context = new JsonMapper().writeValueAsString(ApiResult.result(ApiCode.FAIL, "clientId appKey 不一致", (Object) null));
FullHttpRequestUtils.send(ctx, context, HttpResponseStatus.OK);
log.info("clientId appKey 不一致");
return;
}
......
......@@ -75,12 +75,5 @@ api.response.code.JWTDECODE_EXCEPTION=Token解析异常
#* 默认的异常处理
#*/
api.response.code.HTTP_REQUEST_METHOD_NOT_SUPPORTED_EXCEPTION=默认的异常处理
api.response.code.user.PWD_OR_USERNAME_ERROR=账号或密码错误
api.response.code.user.SMS_CODE_ERROR=旧手机号验证码错误
api.response.code.user.SMS_CODE_REGIST_ERROR=验证码错误
api.response.code.user.USER_NOT_FOUND=用户不存在
api.response.code.user.USER_WECHAT_CODE=微信code错误
api.response.code.user.SMS_CODE_ERROR_NEW=新手机号验证码错误
api.response.code.user.UPDATA_PHONE_USE=绑定手机已经被使用
api.response.code.user.PHONE_IS_ME=手机号不能为自己
api.response.code.REPETITION_CONVERSATION=已有会话,不能重复创建会话
api.response.code.CLIENT_NOT_FOUNT=成员不存在,不能创建会话
......@@ -109,6 +109,10 @@ public enum ApiCode {
*/
REPETITION_CONVERSATION(6010, "api.response.code.REPETITION_CONVERSATION"),
/**
* 成员不存在,不能创建会话
*/
CLIENT_NOT_FOUNT(6011, "api.response.code.CLIENT_NOT_FOUNT"),
;
......
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