|
|
|
@ -20,8 +20,10 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author Binary Wang
|
|
|
|
@ -40,6 +42,11 @@ public class MsgHandler extends AbstractHandler {
|
|
|
|
|
@Autowired
|
|
|
|
|
private WxMpConfig wxConfig;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 存放微信登录用户的信息
|
|
|
|
|
*/
|
|
|
|
|
public static ConcurrentHashMap<String, Map<String, Object>> WE_CHAT_MAP = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
|
|
|
|
@ -55,6 +62,7 @@ public class MsgHandler extends AbstractHandler {
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
userId = userId.replace("qrscene_", "");
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
//登录
|
|
|
|
|
if (userId.contains("login")) {
|
|
|
|
|
//登录所包含userId为雪花算法ID
|
|
|
|
@ -65,11 +73,20 @@ public class MsgHandler extends AbstractHandler {
|
|
|
|
|
if (CollectionUtil.isNotEmpty(info)) {
|
|
|
|
|
Student student = studentService.getByUserId(info.get(0).getUserId());
|
|
|
|
|
String token = tokenService.getToken(student);
|
|
|
|
|
WebSocketServer.sendToUser("token="+token, userId);
|
|
|
|
|
|
|
|
|
|
map.put("type", "login");
|
|
|
|
|
map.put("status", "success");
|
|
|
|
|
map.put("token", token);
|
|
|
|
|
WE_CHAT_MAP.put(userId, map);
|
|
|
|
|
// WebSocketServer.sendToUser("token="+token, userId);
|
|
|
|
|
return WxMpXmlOutMessage.TEXT().content("登录成功").toUser(fromUser)
|
|
|
|
|
.fromUser(wxMessage.getToUser())
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
map.put("type", "login");
|
|
|
|
|
map.put("status", "error");
|
|
|
|
|
map.put("token", "登录失败,未绑定账号");
|
|
|
|
|
WE_CHAT_MAP.put(userId, map);
|
|
|
|
|
return WxMpXmlOutMessage.TEXT().content("登录失败,未绑定账号").toUser(fromUser)
|
|
|
|
|
.fromUser(wxMessage.getToUser())
|
|
|
|
|
.build();
|
|
|
|
@ -81,12 +98,20 @@ public class MsgHandler extends AbstractHandler {
|
|
|
|
|
coreUserWxQuery2.setUserId(Long.parseLong(userId));
|
|
|
|
|
CoreUserWx info2 = coreUserWxService.getInfo(coreUserWxQuery2);
|
|
|
|
|
if (info2 != null || info1 != null) {
|
|
|
|
|
return WxMpXmlOutMessage.TEXT().content("绑定失败,已经绑定其他账号").toUser(fromUser)
|
|
|
|
|
map.put("type", "bind");
|
|
|
|
|
map.put("status", "error");
|
|
|
|
|
map.put("token", "绑定失败,已经绑定");
|
|
|
|
|
WE_CHAT_MAP.put(userId, map);
|
|
|
|
|
return WxMpXmlOutMessage.TEXT().content("绑定失败,已经绑定").toUser(fromUser)
|
|
|
|
|
.fromUser(wxMessage.getToUser())
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
coreUserWxQuery2.setOpenid(fromUser);
|
|
|
|
|
coreUserWxService.add(coreUserWxQuery2);
|
|
|
|
|
map.put("type", "bind");
|
|
|
|
|
map.put("status", "success");
|
|
|
|
|
map.put("token", "绑定成功");
|
|
|
|
|
WE_CHAT_MAP.put(userId, map);
|
|
|
|
|
// String redirectURI = wxConfig.getCodeBackUrl();
|
|
|
|
|
// String s = weixinService.oauth2buildAuthorizationUrl(redirectURI, "snsapi_userinfo", "STATE");
|
|
|
|
|
return WxMpXmlOutMessage.TEXT().content("绑定成功").toUser(fromUser)
|
|
|
|
|