Commit aaff4e73 by 吴迪

【新增】区分前后端token

parent 491e730e
...@@ -124,7 +124,7 @@ public class LogLoginServiceImpl extends ServiceImpl<LogLoginDao, LogLoginEntity ...@@ -124,7 +124,7 @@ public class LogLoginServiceImpl extends ServiceImpl<LogLoginDao, LogLoginEntity
jsonObject.put("isQY",isQY); jsonObject.put("isQY",isQY);
jsonObject.put("isXT",isXT); jsonObject.put("isXT",isXT);
jsonObject.put("id",id); jsonObject.put("id",id);
R token = sysUserTokenService.createToken(id);//将token信息存入 数据库 R token = sysUserTokenService.createToken("qianduan_",id);//将token信息存入 数据库
Object token1 = token.get("token"); Object token1 = token.get("token");
jsonObject.put("token",token1); jsonObject.put("token",token1);
return jsonObject; return jsonObject;
......
...@@ -25,6 +25,10 @@ public interface SysUserTokenService extends IService<SysUserTokenEntity> { ...@@ -25,6 +25,10 @@ public interface SysUserTokenService extends IService<SysUserTokenEntity> {
*/ */
R createToken(long userId); R createToken(long userId);
R createToken(String flag,long userId);
/** /**
* 退出,修改token值 * 退出,修改token值
* @param userId 用户ID * @param userId 用户ID
......
...@@ -28,7 +28,42 @@ public class SysUserTokenServiceImpl extends ServiceImpl<SysUserTokenDao, SysUse ...@@ -28,7 +28,42 @@ public class SysUserTokenServiceImpl extends ServiceImpl<SysUserTokenDao, SysUse
@Override @Override
public R createToken(long userId) { public R createToken(long userId) {
//生成一个token //生成一个token
String token = "qianduan_"+TokenGenerator.generateValue(); String token = TokenGenerator.generateValue();
//当前时间
Date now = new Date();
//过期时间
Date expireTime = new Date(now.getTime() + EXPIRE * 1000);
//判断是否生成过token
SysUserTokenEntity tokenEntity = this.getById(userId);
if(tokenEntity == null){
tokenEntity = new SysUserTokenEntity();
tokenEntity.setUserId(userId);
tokenEntity.setToken(token);
tokenEntity.setUpdateTime(now);
tokenEntity.setExpireTime(expireTime);
//保存token
this.save(tokenEntity);
}else{
tokenEntity.setToken(token);
tokenEntity.setUpdateTime(now);
tokenEntity.setExpireTime(expireTime);
//更新token
this.updateById(tokenEntity);
}
R r = R.ok().put("token", token).put("expire", EXPIRE);
return r;
}
@Override
public R createToken(String flag, long userId) {
//生成一个token
String token = flag+TokenGenerator.generateValue();
//当前时间 //当前时间
Date now = new Date(); Date now = new Date();
......
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