Commit c6910d8c authored by zhouqian's avatar zhouqian

登录增加系统key

parent 6fc20b5a
...@@ -2,6 +2,7 @@ package cn.quantgroup.xyqb.controller.external.user; ...@@ -2,6 +2,7 @@ package cn.quantgroup.xyqb.controller.external.user;
import cn.quantgroup.xyqb.Constants; import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.controller.IBaseController; import cn.quantgroup.xyqb.controller.IBaseController;
import cn.quantgroup.xyqb.entity.Merchant;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserDetail; import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.exception.NullUserException; import cn.quantgroup.xyqb.exception.NullUserException;
...@@ -10,6 +11,7 @@ import cn.quantgroup.xyqb.model.session.SessionStruct; ...@@ -10,6 +11,7 @@ import cn.quantgroup.xyqb.model.session.SessionStruct;
import cn.quantgroup.xyqb.repository.IUserDetailRepository; import cn.quantgroup.xyqb.repository.IUserDetailRepository;
import cn.quantgroup.xyqb.repository.IUserRepository; import cn.quantgroup.xyqb.repository.IUserRepository;
import cn.quantgroup.xyqb.service.auth.IIdCardService; import cn.quantgroup.xyqb.service.auth.IIdCardService;
import cn.quantgroup.xyqb.service.merchant.IMerchantService;
import cn.quantgroup.xyqb.service.session.ISessionService; import cn.quantgroup.xyqb.service.session.ISessionService;
import cn.quantgroup.xyqb.service.sms.ISmsService; import cn.quantgroup.xyqb.service.sms.ISmsService;
import cn.quantgroup.xyqb.service.user.ILkbUserService; import cn.quantgroup.xyqb.service.user.ILkbUserService;
...@@ -60,6 +62,8 @@ public class AppController implements IBaseController { ...@@ -60,6 +62,8 @@ public class AppController implements IBaseController {
private IUserDetailRepository userDetailRepository;*/ private IUserDetailRepository userDetailRepository;*/
@Autowired @Autowired
private IIdCardService idCardService; private IIdCardService idCardService;
@Autowired
private IMerchantService merchantService;
private final static Random random = new Random(); private final static Random random = new Random();
...@@ -71,11 +75,12 @@ public class AppController implements IBaseController { ...@@ -71,11 +75,12 @@ public class AppController implements IBaseController {
public JsonResult login( public JsonResult login(
String phoneNo, String phoneNo,
@RequestParam(required = false, defaultValue = "0") Long registerFrom, @RequestParam(required = false, defaultValue = "0") Long registerFrom,
String idNo, String name, HttpServletRequest request String idNo, String name, String key, HttpServletRequest request
) { ) {
if (!ValidationUtil.validatePhoneNo(phoneNo)) { if (!ValidationUtil.validatePhoneNo(phoneNo)) {
return JsonResult.buildErrorStateResult("该用户名不存在,<br/>请重新输入或注册新账号。", null); return JsonResult.buildErrorStateResult("该用户名不存在,<br/>请重新输入或注册新账号。", null);
} }
String requestIp = IPUtil.getRemoteIP(request); String requestIp = IPUtil.getRemoteIP(request);
LOGGER.info("第三方用户登录, loginFrom:{}, requestIp:{}", registerFrom, requestIp); LOGGER.info("第三方用户登录, loginFrom:{}, requestIp:{}", registerFrom, requestIp);
User user = userService.findByPhoneInDb(phoneNo); User user = userService.findByPhoneInDb(phoneNo);
...@@ -85,10 +90,14 @@ public class AppController implements IBaseController { ...@@ -85,10 +90,14 @@ public class AppController implements IBaseController {
if (user == null) { if (user == null) {
return JsonResult.buildErrorStateResult("该用户名不存在,<br/>请重新输入或注册新账号。", null); return JsonResult.buildErrorStateResult("该用户名不存在,<br/>请重新输入或注册新账号。", null);
} }
Merchant merchant = merchantService.findMerchantByName(key);
if (merchant == null) {
return JsonResult.buildErrorStateResult("无效的商户", null);
}
SessionStruct sessionStruct = sessionService.createSessionAndPersist(user, session -> { SessionStruct sessionStruct = sessionService.createSessionAndPersist(user, session -> {
session.setAttribute("channelId", "1"); session.setAttribute("channelId", "1");
session.setAttribute("createdFrom", String.valueOf(registerFrom)); session.setAttribute("createdFrom", String.valueOf(registerFrom));
}); }, merchant);
AuthBean bean = new AuthBean(); AuthBean bean = new AuthBean();
......
...@@ -184,7 +184,7 @@ public class Jr58Controller implements ApplicationEventPublisherAware { ...@@ -184,7 +184,7 @@ public class Jr58Controller implements ApplicationEventPublisherAware {
User userInXyqb = xyqbUserService.findByUuidWithCache(uuid); User userInXyqb = xyqbUserService.findByUuidWithCache(uuid);
if (userInXyqb != null) { if (userInXyqb != null) {
String token = authApiService.login(userInXyqb.getPhoneNo(), Constants.Channel.JR58); String token = authApiService.login(userInXyqb.getPhoneNo(), Constants.Channel.JR58, "xyqb");
return new Tuple<>(String.format(ENTRY_POINT_URL_TEMPLATE, xyqbUrl, token), userInXyqb); return new Tuple<>(String.format(ENTRY_POINT_URL_TEMPLATE, xyqbUrl, token), userInXyqb);
} }
...@@ -198,12 +198,12 @@ public class Jr58Controller implements ApplicationEventPublisherAware { ...@@ -198,12 +198,12 @@ public class Jr58Controller implements ApplicationEventPublisherAware {
// 手机号在新系统中存在,说明之前已经注册过 // 手机号在新系统中存在,说明之前已经注册过
userInXyqb = xyqbUserService.findByPhoneWithCache(phoneNo); userInXyqb = xyqbUserService.findByPhoneWithCache(phoneNo);
if (userInXyqb != null) { if (userInXyqb != null) {
String token = authApiService.login(phoneNo, Constants.Channel.JR58); String token = authApiService.login(phoneNo, Constants.Channel.JR58, "xyqb");
return new Tuple<>(String.format(ENTRY_POINT_URL_TEMPLATE, xyqbUrl, token), userInXyqb); return new Tuple<>(String.format(ENTRY_POINT_URL_TEMPLATE, xyqbUrl, token), userInXyqb);
} else { } else {
// 注册过 // 注册过
userInXyqb = xyqbUserService.registerAndReturn(phoneNo, "abc1234$", Constants.Channel.JR58); userInXyqb = xyqbUserService.registerAndReturn(phoneNo, "abc1234$", Constants.Channel.JR58);
String token = authApiService.login(phoneNo, Constants.Channel.JR58); String token = authApiService.login(phoneNo, Constants.Channel.JR58, "xyqb");
return new Tuple<>(String.format(ENTRY_POINT_URL_TEMPLATE, xyqbUrl, token), userInXyqb); return new Tuple<>(String.format(ENTRY_POINT_URL_TEMPLATE, xyqbUrl, token), userInXyqb);
} }
} }
......
...@@ -2,6 +2,7 @@ package cn.quantgroup.xyqb.controller.internal.user; ...@@ -2,6 +2,7 @@ package cn.quantgroup.xyqb.controller.internal.user;
import cn.quantgroup.xyqb.Constants; import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.controller.IBaseController; import cn.quantgroup.xyqb.controller.IBaseController;
import cn.quantgroup.xyqb.entity.Merchant;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserDetail; import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.exception.UserNotExistException; import cn.quantgroup.xyqb.exception.UserNotExistException;
...@@ -9,6 +10,7 @@ import cn.quantgroup.xyqb.model.AuthBean; ...@@ -9,6 +10,7 @@ import cn.quantgroup.xyqb.model.AuthBean;
import cn.quantgroup.xyqb.model.JsonResult; import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.model.UserModel; import cn.quantgroup.xyqb.model.UserModel;
import cn.quantgroup.xyqb.model.session.SessionStruct; import cn.quantgroup.xyqb.model.session.SessionStruct;
import cn.quantgroup.xyqb.service.merchant.IMerchantService;
import cn.quantgroup.xyqb.service.session.ISessionService; import cn.quantgroup.xyqb.service.session.ISessionService;
import cn.quantgroup.xyqb.service.sms.ISmsService; import cn.quantgroup.xyqb.service.sms.ISmsService;
import cn.quantgroup.xyqb.service.user.IUserDetailService; import cn.quantgroup.xyqb.service.user.IUserDetailService;
...@@ -59,6 +61,8 @@ public class UserController implements IBaseController { ...@@ -59,6 +61,8 @@ public class UserController implements IBaseController {
@Autowired @Autowired
private IUserDetailService userDetailService; private IUserDetailService userDetailService;
@Autowired
private IMerchantService merchantService;
private static final char[] PWD_BASE = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', private static final char[] PWD_BASE = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
...@@ -68,11 +72,15 @@ public class UserController implements IBaseController { ...@@ -68,11 +72,15 @@ public class UserController implements IBaseController {
public JsonResult login( public JsonResult login(
@RequestParam(required = false, defaultValue = "1") Long channelId, String appChannel, @RequestParam(required = false, defaultValue = "1") Long channelId, String appChannel,
@RequestParam(required = false, defaultValue = "1") Long createdFrom, @RequestParam(required = false, defaultValue = "1") Long createdFrom,
@RequestParam(required = false, defaultValue = "") String userId, HttpServletRequest request) { @RequestParam(required = false, defaultValue = "") String userId, String key, HttpServletRequest request) {
Merchant merchant = merchantService.findMerchantByName(key);
if (merchant == null) {
return JsonResult.buildErrorStateResult("未知的连接", null);
}
if(!StringUtils.isEmpty(userId) && userId.length() > 10) { if(!StringUtils.isEmpty(userId) && userId.length() > 10) {
return loginWithUserId(channelId, appChannel, createdFrom, userId); return loginWithUserId(channelId, appChannel, createdFrom, userId, merchant);
} else { } else {
return loginWithHttpBasic(channelId, appChannel, createdFrom, request); return loginWithHttpBasic(channelId, appChannel, createdFrom, merchant, request);
} }
} }
...@@ -85,21 +93,25 @@ public class UserController implements IBaseController { ...@@ -85,21 +93,25 @@ public class UserController implements IBaseController {
@RequestMapping("/login/fast") @RequestMapping("/login/fast")
public JsonResult loginFast( public JsonResult loginFast(
@RequestParam(required = false, defaultValue = "1") Long channelId, String appChannel, @RequestParam(required = false, defaultValue = "1") Long channelId, String appChannel,
@RequestParam(required = false, defaultValue = "1") Long createdFrom, HttpServletRequest request){ @RequestParam(required = false, defaultValue = "1") Long createdFrom, String key, HttpServletRequest request){
Map<String, JsonResult> validMap = getHeaderParam(request); Map<String, JsonResult> validMap = getHeaderParam(request);
if(null != validMap.get("fail")){ if(null != validMap.get("fail")){
return validMap.get("fail"); return validMap.get("fail");
} }
Merchant merchant = merchantService.findMerchantByName(key);
if (merchant == null) {
return JsonResult.buildErrorStateResult("未知的连接", null);
}
JsonResult successResult = validMap.get("success"); JsonResult successResult = validMap.get("success");
String phoneNo = successResult.getData().toString(); String phoneNo = successResult.getData().toString();
User user = userService.findByPhoneWithCache(phoneNo); User user = userService.findByPhoneWithCache(phoneNo);
if(user == null){ if(user == null) {
user = registerFastWhenLogin(phoneNo, channelId, createdFrom, appChannel); user = registerFastWhenLogin(phoneNo, channelId, createdFrom, appChannel);
if (user == null) { if (user == null) {
throw new UserNotExistException("用户未找到"); throw new UserNotExistException("用户未找到");
} }
} }
return createSession(channelId, createdFrom, appChannel, user); return createSession(channelId, createdFrom, appChannel, user, merchant);
// return createSession(channelId, createdFrom, appChannel, user); // return createSession(channelId, createdFrom, appChannel, user);
} }
...@@ -361,19 +373,19 @@ public class UserController implements IBaseController { ...@@ -361,19 +373,19 @@ public class UserController implements IBaseController {
} }
private JsonResult loginWithHttpBasic( Long channelId, String appChannel, Long createdFrom, HttpServletRequest request) { private JsonResult loginWithHttpBasic( Long channelId, String appChannel, Long createdFrom, Merchant merchant, HttpServletRequest request) {
User user = verificateUserNameAndPassword(request); User user = verificateUserNameAndPassword(request);
if (user == null) { if (user == null) {
return JsonResult.buildErrorStateResult("用户名或密码不正确", null); return JsonResult.buildErrorStateResult("用户名或密码不正确", null);
} else { } else {
return createSession(channelId, createdFrom, appChannel, user); return createSession(channelId, createdFrom, appChannel, user, merchant);
} }
} }
private JsonResult createSession(Long channelId, Long createdFrom, String appChannel, User user) { private JsonResult createSession(Long channelId, Long createdFrom, String appChannel, User user, Merchant merchant) {
AuthBean authBean = new AuthBean(); AuthBean authBean = new AuthBean();
//找到用户 //找到用户
String sessionId = sessionService.findSessionIdByUserId(user.getId()); String sessionId = sessionService.findSessionIdByUserIdAndMerchant(user.getId(), merchant);
if(StringUtils.isNotEmpty(sessionId)) { if(StringUtils.isNotEmpty(sessionId)) {
SessionStruct sessionStruct = sessionService.findSessionBySessionId(sessionId); SessionStruct sessionStruct = sessionService.findSessionBySessionId(sessionId);
sessionStruct.setAttribute("channelId", String.valueOf(channelId)); sessionStruct.setAttribute("channelId", String.valueOf(channelId));
...@@ -389,7 +401,7 @@ public class UserController implements IBaseController { ...@@ -389,7 +401,7 @@ public class UserController implements IBaseController {
session.setAttribute("channelId", String.valueOf(channelId)); session.setAttribute("channelId", String.valueOf(channelId));
session.setAttribute("createdFrom", String.valueOf(createdFrom)); session.setAttribute("createdFrom", String.valueOf(createdFrom));
session.setAttribute("appChannel", String.valueOf(appChannel)); session.setAttribute("appChannel", String.valueOf(appChannel));
}); }, merchant);
authBean.setPhoneNo(user.getPhoneNo()); authBean.setPhoneNo(user.getPhoneNo());
authBean.setToken(sessionStruct.getSid()); authBean.setToken(sessionStruct.getSid());
LOGGER.info("用户登录成功, loginFrom:{}, phoneNo:{},appChannel:{}", createdFrom, user.getPhoneNo(), appChannel); LOGGER.info("用户登录成功, loginFrom:{}, phoneNo:{},appChannel:{}", createdFrom, user.getPhoneNo(), appChannel);
...@@ -430,12 +442,12 @@ public class UserController implements IBaseController { ...@@ -430,12 +442,12 @@ public class UserController implements IBaseController {
return StringUtils.defaultString(targetPassword, "").equals(PasswordUtil.MD5(paramPass.toLowerCase() + pwdSalt)); return StringUtils.defaultString(targetPassword, "").equals(PasswordUtil.MD5(paramPass.toLowerCase() + pwdSalt));
} }
private JsonResult loginWithUserId(Long channelId, String appChannel, Long createdFrom, String userId) { private JsonResult loginWithUserId(Long channelId, String appChannel, Long createdFrom, String userId, Merchant merchant) {
//查询用户,存在则保存用户session信息,userId为uuid //查询用户,存在则保存用户session信息,userId为uuid
User user = userService.findByUuidInDb(userId); User user = userService.findByUuidInDb(userId);
//用户信息存在,更新session中的最后访问时间,重新写入缓存. //用户信息存在,更新session中的最后访问时间,重新写入缓存.
if(null != user) { if(null != user) {
return createSession(channelId, createdFrom, appChannel, user); return createSession(channelId, createdFrom, appChannel, user, merchant);
} else { } else {
return JsonResult.buildErrorStateResult("登录失败", null); return JsonResult.buildErrorStateResult("登录失败", null);
} }
......
...@@ -22,5 +22,6 @@ public class SessionValue{ ...@@ -22,5 +22,6 @@ public class SessionValue{
private Timestamp createdAt; private Timestamp createdAt;
@JSONField(serializeUsing = Timestamp2LongConverter.class) @JSONField(serializeUsing = Timestamp2LongConverter.class)
private Timestamp lastAccessTime; private Timestamp lastAccessTime;
private String merchantName;
} }
...@@ -6,9 +6,9 @@ package cn.quantgroup.xyqb.service.auth; ...@@ -6,9 +6,9 @@ package cn.quantgroup.xyqb.service.auth;
*/ */
public interface IAuthApiService { public interface IAuthApiService {
String login(String phone, Long loginFrom); String login(String phone, Long loginFrom, String key);
String login(String phone, Long loginFrom, Long channelId); String login(String phone, Long loginFrom, Long channelId, String key);
String login(String phone, Long loginFrom, Long channelId, Long createdFrom); String login(String phone, Long loginFrom, Long channelId, Long createdFrom, String key);
} }
...@@ -30,18 +30,18 @@ public class AuthApiServiceImpl implements IAuthApiService { ...@@ -30,18 +30,18 @@ public class AuthApiServiceImpl implements IAuthApiService {
private String xyqbAuthUrl; private String xyqbAuthUrl;
@Override @Override
public String login(String phone, Long loginFrom) { public String login(String phone, Long loginFrom, String key) {
return this.getToken(phone, loginFrom, 1L, loginFrom); return this.getToken(phone, loginFrom, 1L, loginFrom, key);
} }
@Override @Override
public String login(String phone, Long loginFrom, Long channelId) { public String login(String phone, Long loginFrom, Long channelId, String key) {
return this.getToken(phone, loginFrom, channelId, loginFrom); return this.getToken(phone, loginFrom, channelId, loginFrom, key);
} }
@Override @Override
public String login(String phone, Long loginFrom, Long channelId, Long createdFrom) { public String login(String phone, Long loginFrom, Long channelId, Long createdFrom, String key) {
return this.getToken(phone, loginFrom, channelId, createdFrom); return this.getToken(phone, loginFrom, channelId, createdFrom, key);
} }
/** /**
...@@ -50,12 +50,13 @@ public class AuthApiServiceImpl implements IAuthApiService { ...@@ -50,12 +50,13 @@ public class AuthApiServiceImpl implements IAuthApiService {
* @param phone * @param phone
* @return * @return
*/ */
private String getToken(String phone, Long loginFrom, Long channelId, Long createdFrom) { private String getToken(String phone, Long loginFrom, Long channelId, Long createdFrom, String key) {
Map<String, String> parameters = ImmutableMap.<String, String>builder() Map<String, String> parameters = ImmutableMap.<String, String>builder()
.put("phoneNo", phone) .put("phoneNo", phone)
.put("registerFrom", loginFrom + "") .put("registerFrom", loginFrom + "")
.put("channelId", channelId + "") .put("channelId", channelId + "")
.put("createdFrom", createdFrom + "") .put("createdFrom", createdFrom + "")
.put("key", key)
.build(); .build();
String response = httpService.post(xyqbAuthUrl + "/app/login", parameters); String response = httpService.post(xyqbAuthUrl + "/app/login", parameters);
......
package cn.quantgroup.xyqb.service.session; package cn.quantgroup.xyqb.service.session;
import cn.quantgroup.xyqb.entity.Merchant;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.function.OneArgFunction; import cn.quantgroup.xyqb.function.OneArgFunction;
import cn.quantgroup.xyqb.model.session.SessionStruct; import cn.quantgroup.xyqb.model.session.SessionStruct;
...@@ -9,11 +10,12 @@ import cn.quantgroup.xyqb.model.session.SessionValue; ...@@ -9,11 +10,12 @@ import cn.quantgroup.xyqb.model.session.SessionValue;
* Created by 11 on 2016/12/28. * Created by 11 on 2016/12/28.
*/ */
public interface ISessionService { public interface ISessionService {
SessionStruct createSessionAndPersistInCache(User user); SessionStruct createSessionAndPersistInCache(User user, Merchant merchant);
SessionStruct createSessionAndPersist(User user, OneArgFunction<SessionStruct> function);
String findSessionIdByUserId(Long userId); SessionStruct createSessionAndPersist(User user, OneArgFunction<SessionStruct> beforPersist, Merchant merchant);
String findSessionIdByUserIdAndMerchant(Long userId, Merchant merchant);
String findSessionValueBySessionId(String sessionId); String findSessionValueBySessionId(String sessionId);
SessionStruct newSession(User user); SessionStruct newSession(User user);
void persistSession(String token, SessionValue sessionValue); void persistSession(String token, SessionValue sessionValue);
......
package cn.quantgroup.xyqb.service.session.impl; package cn.quantgroup.xyqb.service.session.impl;
import cn.quantgroup.xyqb.Constants; import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.entity.Merchant;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.function.OneArgFunction; import cn.quantgroup.xyqb.function.OneArgFunction;
import cn.quantgroup.xyqb.model.session.SessionStruct; import cn.quantgroup.xyqb.model.session.SessionStruct;
import cn.quantgroup.xyqb.model.session.SessionValue; import cn.quantgroup.xyqb.model.session.SessionValue;
import cn.quantgroup.xyqb.service.session.ISessionService; import cn.quantgroup.xyqb.service.session.ISessionService;
import cn.quantgroup.xyqb.session.XyqbSessionContextHolder;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -32,15 +32,15 @@ public class SessionServiceImpl implements ISessionService{ ...@@ -32,15 +32,15 @@ public class SessionServiceImpl implements ISessionService{
private RedisTemplate<String, String> stringRedisTemplate; private RedisTemplate<String, String> stringRedisTemplate;
@Override @Override
public SessionStruct createSessionAndPersistInCache(User user) { public SessionStruct createSessionAndPersistInCache(User user, Merchant merchant) {
return createSessionAndPersist(user, null); return createSessionAndPersist(user, null, merchant);
} }
@Override @Override
public SessionStruct createSessionAndPersist(User user, OneArgFunction<SessionStruct> beforPersist) { public SessionStruct createSessionAndPersist(User user, OneArgFunction<SessionStruct> beforPersist, Merchant merchant) {
SessionStruct sessionStruct; SessionStruct sessionStruct;
//获取sessionid //获取sessionid
String sessionId = findSessionIdByUserId(user.getId()); String sessionId = findSessionIdByUserIdAndMerchant(user.getId(), merchant);
if(StringUtils.length(sessionId) == 36){ if(StringUtils.length(sessionId) == 36){
sessionStruct = new SessionStruct(); sessionStruct = new SessionStruct();
String sessionValue = findSessionValueBySessionId(sessionId); String sessionValue = findSessionValueBySessionId(sessionId);
...@@ -63,8 +63,8 @@ public class SessionServiceImpl implements ISessionService{ ...@@ -63,8 +63,8 @@ public class SessionServiceImpl implements ISessionService{
} }
@Override @Override
public String findSessionIdByUserId(Long userId) { public String findSessionIdByUserIdAndMerchant(Long userId, Merchant merchant) {
return stringRedisTemplate.opsForValue().get(Constants.Session.USER_SESSION_ID_CACHE + userId.toString()); return stringRedisTemplate.opsForValue().get(Constants.Session.USER_SESSION_ID_CACHE + ":" + merchant.getName() + ":" + userId.toString());
} }
@Override @Override
...@@ -89,13 +89,13 @@ public class SessionServiceImpl implements ISessionService{ ...@@ -89,13 +89,13 @@ public class SessionServiceImpl implements ISessionService{
} }
@Override @Override
public void persistSession(String token, SessionValue sessionValue){ public void persistSession(String token, SessionValue sessionValue) {
Timestamp current = new Timestamp(System.currentTimeMillis()); Timestamp current = new Timestamp(System.currentTimeMillis());
sessionValue.setLastAccessTime(current); sessionValue.setLastAccessTime(current);
String json = JSON.toJSONString(sessionValue); String json = JSON.toJSONString(sessionValue);
stringRedisTemplate.opsForValue().set(Constants.Session.USER_SESSION_CACHE + token, json, stringRedisTemplate.opsForValue().set(Constants.Session.USER_SESSION_CACHE + token, json,
Constants.Session.ONE_DAY, TimeUnit.SECONDS); Constants.Session.ONE_DAY, TimeUnit.SECONDS);
stringRedisTemplate.opsForValue().set(Constants.Session.USER_SESSION_ID_CACHE + stringRedisTemplate.opsForValue().set(Constants.Session.USER_SESSION_ID_CACHE + ":" + sessionValue.getMerchantName() + ":" +
sessionValue.getUser().getId().toString(), token, Constants.Session.ONE_DAY, TimeUnit.SECONDS); sessionValue.getUser().getId().toString(), token, Constants.Session.ONE_DAY, TimeUnit.SECONDS);
} }
......
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