| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.xcong.excoin.common.contants.AppContants; |
| | | import com.xcong.excoin.configurations.properties.SecurityProperties; |
| | | import com.xcong.excoin.modules.member.entity.MemberEntity; |
| | | import com.xcong.excoin.netty.bean.ChatRequest; |
| | | import com.xcong.excoin.netty.bean.RequestBean; |
| | | import com.xcong.excoin.netty.bean.ResponseBean; |
| | |
| | | // |
| | | // Long memberId = Long.parseLong(tokens[0]); |
| | | |
| | | String token = requestBean.getData().toString(); |
| | | String redisKey = AppContants.APP_LOGIN_PREFIX + token; |
| | | String loginStr = redisUtils.getString(redisKey); |
| | | if (StrUtil.isBlank(loginStr)) { |
| | | ResponseBean res = ResponseBean.fail(); |
| | | res.setType(requestBean.getType()); |
| | | channel.writeAndFlush(NettyTools.webSocketBytes(JSONObject.toJSONString(res))); |
| | | return; |
| | | } |
| | | |
| | | Long memberId = Long.parseLong(requestBean.getData().toString()); |
| | | MemberEntity loginUser = JSONObject.parseObject(loginStr, MemberEntity.class); |
| | | Long memberId = loginUser.getId(); |
| | | |
| | | channel.writeAndFlush(NettyTools.webSocketBytes(JSONObject.toJSONString(responseBean))); |
| | | ChannelManager.addWsChannel(channel, memberId); |
| | |
| | | String chatStr = requestBean.getData().toString(); |
| | | ChatRequest chat = JSONObject.parseObject(chatStr, ChatRequest.class); |
| | | |
| | | Channel channel = ChannelManager.findWebSocketChannel(requestBean.getChannelId()); |
| | | channel.writeAndFlush(NettyTools.webSocketJson(ResponseBean.ok(chat))); |
| | | // 判断是否在线 |
| | | Channel targetChannel = ChannelManager.findWsChannel(Long.parseLong(chat.getTo())); |
| | | if (targetChannel != null) { |