app登录失效修改

master
heminjian502 2 years ago
parent 8b6e5d6414
commit 97624a399a

@ -90,6 +90,8 @@ token:
secret: abcdefghijklmnopqrstuvwxyz
# 令牌有效期默认30分钟
expireTime: 30
# app令牌有效期默认30day
appExpireTime: 43200
# MyBatis配置
mybatis:

@ -195,7 +195,7 @@ public class SysLoginService
sysUser.setHospitalId(tDoctor.getHospitalId());
loginUser.setUserId(sysUser.getUserId());
loginUser.setUser(sysUser);
String token = userTokenService.createToken(loginUser);
String token = userTokenService.createTokenForApp(loginUser);
AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
AjaxResult ajaxResult = AjaxResult.success();
ajaxResult.put(Constants.TOKEN, token);
@ -211,7 +211,7 @@ public class SysLoginService
LoginUser loginUser = new LoginUser();
loginUser.setUserId(sysUser.getUserId());
loginUser.setUser(sysUser);
String token = userTokenService.createToken(loginUser);
String token = userTokenService.createTokenForApp(loginUser);
AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
return token;
}

@ -41,6 +41,9 @@ public class UserTokenService
@Value("${token.expireTime}")
private int expireTime;
@Value("${token.appExpireTime}")
private int appExpireTime;
protected static final long MILLIS_SECOND = 1000;
protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND;
@ -118,6 +121,18 @@ public class UserTokenService
return createToken(claims);
}
public String createTokenForApp(LoginUser loginUser)
{
String token = IdUtils.fastUUID();
loginUser.setToken(token);
setUserAgent(loginUser);
refreshTokenForApp(loginUser);
Map<String, Object> claims = new HashMap<>();
claims.put(Constants.LOGIN_USER_KEY, token);
return createToken(claims);
}
/**
* 20
*
@ -148,6 +163,15 @@ public class UserTokenService
redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES);
}
public void refreshTokenForApp(LoginUser loginUser)
{
loginUser.setLoginTime(System.currentTimeMillis());
loginUser.setExpireTime(loginUser.getLoginTime() + appExpireTime * MILLIS_MINUTE);
// 根据uuid将loginUser缓存
String userKey = getTokenKey(loginUser.getToken());
redisCache.setCacheObject(userKey, loginUser, appExpireTime, TimeUnit.MINUTES);
}
/**
*
*

@ -244,7 +244,7 @@ public class WechatServiceImpl implements IWechatService {
user.setSex(tPatient.getSex());
user.setPhonenumber(tPatient.getPhone());
loginUser.setUser(user);
String token = userTokenService.createToken(loginUser);
String token = userTokenService.createTokenForApp(loginUser);
return token;
}
@ -263,7 +263,7 @@ public class WechatServiceImpl implements IWechatService {
user.setDoctorId(tDoctor.getId());
user.setHospitalId(tDoctor.getHospitalId());
loginUser.setUser(user);
String token = userTokenService.createToken(loginUser);
String token = userTokenService.createTokenForApp(loginUser);
return token;
}
}

Loading…
Cancel
Save