Introducing new features.私聊ok 判断账号是否存在
正在显示
5 个修改的文件
包含
36 行增加
和
10 行删除
| @@ -43,7 +43,7 @@ public class MsgHandler implements MsgHandle { | @@ -43,7 +43,7 @@ public class MsgHandler implements MsgHandle { | ||
| 43 | 43 | ||
| 44 | @Override | 44 | @Override |
| 45 | public void sendMsg(String msg) { | 45 | public void sendMsg(String msg) { |
| 46 | - String[] totalMsg = msg.split("><"); | 46 | + String[] totalMsg = msg.split("^^"); |
| 47 | if (totalMsg.length > 1) { | 47 | if (totalMsg.length > 1) { |
| 48 | //私聊 | 48 | //私聊 |
| 49 | P2PReqVO p2PReqVO = new P2PReqVO(); | 49 | P2PReqVO p2PReqVO = new P2PReqVO(); |
| @@ -10,6 +10,7 @@ import com.crossoverjie.cim.client.vo.req.P2PReqVO; | @@ -10,6 +10,7 @@ import com.crossoverjie.cim.client.vo.req.P2PReqVO; | ||
| 10 | import com.crossoverjie.cim.client.vo.res.CIMServerResVO; | 10 | import com.crossoverjie.cim.client.vo.res.CIMServerResVO; |
| 11 | import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO; | 11 | import com.crossoverjie.cim.client.vo.res.OnlineUsersResVO; |
| 12 | import com.crossoverjie.cim.common.enums.StatusEnum; | 12 | import com.crossoverjie.cim.common.enums.StatusEnum; |
| 13 | +import com.crossoverjie.cim.common.res.BaseResponse; | ||
| 13 | import okhttp3.*; | 14 | import okhttp3.*; |
| 14 | import org.slf4j.Logger; | 15 | import org.slf4j.Logger; |
| 15 | import org.slf4j.LoggerFactory; | 16 | import org.slf4j.LoggerFactory; |
| @@ -90,6 +91,15 @@ public class RouteRequestImpl implements RouteRequest { | @@ -90,6 +91,15 @@ public class RouteRequestImpl implements RouteRequest { | ||
| 90 | if (!response.isSuccessful()){ | 91 | if (!response.isSuccessful()){ |
| 91 | throw new IOException("Unexpected code " + response); | 92 | throw new IOException("Unexpected code " + response); |
| 92 | } | 93 | } |
| 94 | + | ||
| 95 | + String json = response.body().toString() ; | ||
| 96 | + BaseResponse baseResponse = JSON.parseObject(json, BaseResponse.class); | ||
| 97 | + | ||
| 98 | + //选择的账号不存在 | ||
| 99 | + if (baseResponse.getCode().equals(StatusEnum.OFF_LINE.getCode())){ | ||
| 100 | + LOGGER.error(p2PReqVO.getReceiveUserId() + ":" + StatusEnum.OFF_LINE.getMessage()); | ||
| 101 | + System.exit(-1); | ||
| 102 | + } | ||
| 93 | } | 103 | } |
| 94 | 104 | ||
| 95 | @Override | 105 | @Override |
| @@ -17,6 +17,9 @@ public enum StatusEnum { | @@ -17,6 +17,9 @@ public enum StatusEnum { | ||
| 17 | /** 重复登录 */ | 17 | /** 重复登录 */ |
| 18 | REPEAT_LOGIN("5000", "账号重复登录,请退出一个账号!"), | 18 | REPEAT_LOGIN("5000", "账号重复登录,请退出一个账号!"), |
| 19 | 19 | ||
| 20 | + /** 账号不在线 */ | ||
| 21 | + OFF_LINE("7000", "你选择的账号不在线,请重新选择!"), | ||
| 22 | + | ||
| 20 | /** 请求限流 */ | 23 | /** 请求限流 */ |
| 21 | REQUEST_LIMIT("6000", "请求限流"), | 24 | REQUEST_LIMIT("6000", "请求限流"), |
| 22 | ; | 25 | ; |
| 1 | package com.crossoverjie.cim.route.controller; | 1 | package com.crossoverjie.cim.route.controller; |
| 2 | 2 | ||
| 3 | import com.crossoverjie.cim.common.enums.StatusEnum; | 3 | import com.crossoverjie.cim.common.enums.StatusEnum; |
| 4 | +import com.crossoverjie.cim.common.exception.CIMException; | ||
| 4 | import com.crossoverjie.cim.common.pojo.CIMUserInfo; | 5 | import com.crossoverjie.cim.common.pojo.CIMUserInfo; |
| 5 | import com.crossoverjie.cim.common.res.BaseResponse; | 6 | import com.crossoverjie.cim.common.res.BaseResponse; |
| 6 | import com.crossoverjie.cim.common.res.NULLBody; | 7 | import com.crossoverjie.cim.common.res.NULLBody; |
| @@ -94,18 +95,23 @@ public class RouteController { | @@ -94,18 +95,23 @@ public class RouteController { | ||
| 94 | public BaseResponse<NULLBody> p2pRoute(@RequestBody P2PReqVO p2pRequest) throws Exception { | 95 | public BaseResponse<NULLBody> p2pRoute(@RequestBody P2PReqVO p2pRequest) throws Exception { |
| 95 | BaseResponse<NULLBody> res = new BaseResponse(); | 96 | BaseResponse<NULLBody> res = new BaseResponse(); |
| 96 | 97 | ||
| 97 | - //获取接收消息用户的路由信息 | ||
| 98 | - CIMServerResVO cimServerResVO = accountService.loadRouteRelatedByUserId(p2pRequest.getReceiveUserId()); | ||
| 99 | - //推送消息 | ||
| 100 | - String url = "http://" + cimServerResVO.getIp() + ":" + cimServerResVO.getHttpPort() + "/sendMsg" ; | 98 | + try { |
| 99 | + //获取接收消息用户的路由信息 | ||
| 100 | + CIMServerResVO cimServerResVO = accountService.loadRouteRelatedByUserId(p2pRequest.getReceiveUserId()); | ||
| 101 | + //推送消息 | ||
| 102 | + String url = "http://" + cimServerResVO.getIp() + ":" + cimServerResVO.getHttpPort() + "/sendMsg" ; | ||
| 101 | 103 | ||
| 102 | - //p2pRequest.getReceiveUserId()==>消息接收者的 userID | ||
| 103 | - ChatReqVO chatVO = new ChatReqVO(p2pRequest.getReceiveUserId(),p2pRequest.getMsg()) ; | ||
| 104 | - accountService.pushMsg(url,p2pRequest.getUserId(),chatVO); | 104 | + //p2pRequest.getReceiveUserId()==>消息接收者的 userID |
| 105 | + ChatReqVO chatVO = new ChatReqVO(p2pRequest.getReceiveUserId(),p2pRequest.getMsg()) ; | ||
| 106 | + accountService.pushMsg(url,p2pRequest.getUserId(),chatVO); | ||
| 105 | 107 | ||
| 108 | + res.setCode(StatusEnum.SUCCESS.getCode()); | ||
| 109 | + res.setMessage(StatusEnum.SUCCESS.getMessage()); | ||
| 106 | 110 | ||
| 107 | - res.setCode(StatusEnum.SUCCESS.getCode()); | ||
| 108 | - res.setMessage(StatusEnum.SUCCESS.getMessage()); | 111 | + }catch (CIMException e){ |
| 112 | + res.setCode(e.getErrorCode()); | ||
| 113 | + res.setMessage(e.getErrorMessage()); | ||
| 114 | + } | ||
| 109 | return res; | 115 | return res; |
| 110 | } | 116 | } |
| 111 | 117 |
cim-forward-route/src/main/java/com/crossoverjie/cim/route/service/impl/AccountServiceRedisImpl.java
| 1 | package com.crossoverjie.cim.route.service.impl; | 1 | package com.crossoverjie.cim.route.service.impl; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | +import com.crossoverjie.cim.common.exception.CIMException; | ||
| 4 | import com.crossoverjie.cim.common.pojo.CIMUserInfo; | 5 | import com.crossoverjie.cim.common.pojo.CIMUserInfo; |
| 5 | import com.crossoverjie.cim.route.service.AccountService; | 6 | import com.crossoverjie.cim.route.service.AccountService; |
| 6 | import com.crossoverjie.cim.route.service.UserInfoCacheService; | 7 | import com.crossoverjie.cim.route.service.UserInfoCacheService; |
| @@ -23,6 +24,7 @@ import java.nio.charset.StandardCharsets; | @@ -23,6 +24,7 @@ import java.nio.charset.StandardCharsets; | ||
| 23 | import java.util.HashMap; | 24 | import java.util.HashMap; |
| 24 | import java.util.Map; | 25 | import java.util.Map; |
| 25 | 26 | ||
| 27 | +import static com.crossoverjie.cim.common.enums.StatusEnum.OFF_LINE; | ||
| 26 | import static com.crossoverjie.cim.route.constant.Constant.ACCOUNT_PREFIX; | 28 | import static com.crossoverjie.cim.route.constant.Constant.ACCOUNT_PREFIX; |
| 27 | import static com.crossoverjie.cim.route.constant.Constant.ROUTE_PREFIX; | 29 | import static com.crossoverjie.cim.route.constant.Constant.ROUTE_PREFIX; |
| 28 | 30 | ||
| @@ -120,6 +122,11 @@ public class AccountServiceRedisImpl implements AccountService { | @@ -120,6 +122,11 @@ public class AccountServiceRedisImpl implements AccountService { | ||
| 120 | @Override | 122 | @Override |
| 121 | public CIMServerResVO loadRouteRelatedByUserId(Long userId) { | 123 | public CIMServerResVO loadRouteRelatedByUserId(Long userId) { |
| 122 | String value = redisTemplate.opsForValue().get(ROUTE_PREFIX + userId); | 124 | String value = redisTemplate.opsForValue().get(ROUTE_PREFIX + userId); |
| 125 | + | ||
| 126 | + if (value == null){ | ||
| 127 | + throw new CIMException(OFF_LINE) ; | ||
| 128 | + } | ||
| 129 | + | ||
| 123 | String[] server = value.split(":"); | 130 | String[] server = value.split(":"); |
| 124 | CIMServerResVO cimServerResVO = new CIMServerResVO(server[0], Integer.parseInt(server[1]), Integer.parseInt(server[2])); | 131 | CIMServerResVO cimServerResVO = new CIMServerResVO(server[0], Integer.parseInt(server[1]), Integer.parseInt(server[2])); |
| 125 | return cimServerResVO; | 132 | return cimServerResVO; |
-
请 注册 或 登录 后发表评论