登录部分
This commit is contained in:
parent
fefb4c3a85
commit
b7ce764bdb
|
|
@ -108,6 +108,9 @@ public class LoginFilter implements Filter {
|
|||
}else if(environment.equals("wx")){
|
||||
//获取当前登录人的用户id
|
||||
String openId = TokenUtil.parseParamFromToken(token).getString("openId");
|
||||
if(StringUtils.isBlank(openId)){
|
||||
openId = TokenUtil.parseParamFromToken(token).getString("userId");
|
||||
}
|
||||
tokenKey=RedisCst.ONLINE_USER.concat(openId);
|
||||
}
|
||||
message = redisUtil.getMessage(tokenKey);
|
||||
|
|
|
|||
|
|
@ -98,7 +98,9 @@ public class LoginService {
|
|||
}
|
||||
}
|
||||
else {
|
||||
userInfo.setSearchWord(userInfo.getSearchWord() + "||微信用户");
|
||||
if(!userInfo.getSearchWord().contains("微信用户")){
|
||||
userInfo.setSearchWord(userInfo.getSearchWord() + "||微信用户");
|
||||
}
|
||||
userInfo.setMiniAppOpenId(openId);
|
||||
userInfo.setUpdatedAt(System.currentTimeMillis());
|
||||
tbUserInfoMapper.updateByPrimaryKeySelective(userInfo);
|
||||
|
|
@ -232,7 +234,7 @@ public class LoginService {
|
|||
//生成token 信息
|
||||
String token = null;
|
||||
try {
|
||||
token = TokenUtil.generateToken(userInfo.getId(), null, userInfo.getTelephone(), userInfo.getNickName());
|
||||
token = TokenUtil.generateToken(userInfo.getId(), userInfo.getMiniAppOpenId(), userInfo.getTelephone(), userInfo.getNickName());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
@ -240,7 +242,12 @@ public class LoginService {
|
|||
try {
|
||||
map.put("token", token);
|
||||
map.put("userInfo", userInfo);
|
||||
redisUtil.saveMessage(RedisCst.ONLINE_APP_USER.concat(userInfo.getId() + ""), JSON.toJSONString(map));
|
||||
if(StringUtils.isNotBlank(userInfo.getMiniAppOpenId())){
|
||||
redisUtil.saveMessage(RedisCst.ONLINE_USER.concat(userInfo.getMiniAppOpenId()), JSON.toJSONString(map),60*60*24*30L);
|
||||
}else {
|
||||
redisUtil.saveMessage(RedisCst.ONLINE_USER.concat(userInfo.getId() + ""), JSON.toJSONString(map),60*60*24*30L);
|
||||
}
|
||||
// redisUtil.saveMessage(RedisCst.ONLINE_APP_USER.concat(userInfo.getId() + ""), JSON.toJSONString(map),60*60*24*30L);
|
||||
return Result.success(CodeEnum.SUCCESS, map);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ public class AppWebSocketServer {
|
|||
String shopId = queryParams.get("shopId");
|
||||
String userId = queryParams.get("userId");
|
||||
|
||||
log.info("建立连接参数 tableId:{} shopId:{} userId:{}",tableId,shopId,userId);
|
||||
log.info("建立连接参数 tableId:{} shopId:{} userId:{} sessionId:{}",tableId,shopId,userId,session.getId());
|
||||
this.tableId = tableId;
|
||||
this.shopId = shopId;
|
||||
this.userId = userId;
|
||||
|
|
@ -162,7 +162,7 @@ public class AppWebSocketServer {
|
|||
@OnClose
|
||||
public void onClose() throws IOException {
|
||||
String key=tableId + "-" + shopId;
|
||||
log.info("触发关闭操作 key为:{} userId为:{}",key,userId);
|
||||
log.info("触发关闭操作 key为:{} userId为:{} sessionId:{}",key,userId,session.getId());
|
||||
if (webSocketMap.containsKey(key)) {
|
||||
ConcurrentHashMap<String, AppWebSocketServer> userSocketMap = webSocketMap.get(key);
|
||||
// 在放置新条目之前检查并清除同名userId的数据
|
||||
|
|
@ -176,6 +176,7 @@ public class AppWebSocketServer {
|
|||
// userMap.remove(tableId + "-" + shopId);
|
||||
// }
|
||||
}
|
||||
session.close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -185,7 +186,7 @@ public class AppWebSocketServer {
|
|||
*/
|
||||
@OnMessage
|
||||
public void onMessage(String message, Session session) {
|
||||
log.info("接收消息 tableId:{} shopId:{} userId:{} message:{}",this.tableId,this.shopId,this.userId,message);
|
||||
log.info("接收消息 tableId:{} shopId:{} userId:{} message:{} sessionId:{}",this.tableId,this.shopId,this.userId,message,session.getId());
|
||||
//可以群发消息
|
||||
//消息保存到数据库、redis
|
||||
if (StringUtils.isNotBlank(message) && !message.equals("undefined")) {
|
||||
|
|
@ -207,11 +208,17 @@ public class AppWebSocketServer {
|
|||
if (webSocketMap.containsKey(tableId+"-"+shopId)) {
|
||||
ConcurrentHashMap<String, AppWebSocketServer> userSocketMap = webSocketMap.get(tableId+"-"+shopId);
|
||||
// 在放置新条目之前检查并清除同名userId的数据
|
||||
userSocketMap.put(userId,this);
|
||||
if(userSocketMap.get(userId)!=null && userSocketMap.get(userId).session!=null){
|
||||
this.session=userSocketMap.get(userId).session;
|
||||
userSocketMap.put(userId,this);
|
||||
}
|
||||
} else {
|
||||
ConcurrentHashMap<String, AppWebSocketServer> userSocketMap=new ConcurrentHashMap<>();
|
||||
userSocketMap.put(userId,this);
|
||||
webSocketMap.put(tableId+"-"+shopId,userSocketMap);
|
||||
if(userSocketMap.get(userId)!=null && userSocketMap.get(userId).session!=null){
|
||||
this.session=userSocketMap.get(userId).session;
|
||||
userSocketMap.put(userId,this);
|
||||
webSocketMap.put(tableId+"-"+shopId,userSocketMap);
|
||||
}
|
||||
}
|
||||
//这里采用责任链模式,每一个处理器对应一个前段发过来的请,这里还可以用工厂模式来生成对象
|
||||
// ChangeHandler changeHandler = new ChangeHandler();
|
||||
|
|
@ -270,6 +277,7 @@ public class AppWebSocketServer {
|
|||
//加入线程锁
|
||||
synchronized (session) {
|
||||
try {
|
||||
log.info("发送消息 session:{}",session.getId());
|
||||
//同步发送信息
|
||||
this.session.getBasicRemote().sendObject(message);
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ public class TokenUtil {
|
|||
}catch (Exception e){
|
||||
jsonObject.put("status","-4");
|
||||
jsonObject.put("message","token解析失败了");
|
||||
log.info("token解析失败{}",e.getMessage());
|
||||
log.info("token解析失败token为:{} message:{}",token,e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return jsonObject;
|
||||
|
|
|
|||
Loading…
Reference in New Issue