| | |
| | | import java.util.concurrent.TimeUnit; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import com.ruoyi.common.core.exception.user.UserAppletException; |
| | | import com.ruoyi.system.api.model.LoginUserApplet; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND; |
| | | |
| | | private final static long expireTime = CacheConstants.EXPIRATION; |
| | | private final static long expireAppletTime = CacheConstants.EXPIRATION_APPLET; |
| | | |
| | | private final static String ACCESS_TOKEN = CacheConstants.LOGIN_TOKEN_KEY; |
| | | |
| | |
| | | */ |
| | | public Map<String, Object> createTokenApplet(LoginUserApplet loginUser) { |
| | | String token = IdUtils.fastUUID(); |
| | | Integer userId = loginUser.getUserid(); |
| | | Long userId = loginUser.getUserId(); |
| | | String name = loginUser.getName(); |
| | | loginUser.setToken(token); |
| | | loginUser.setIpaddr(IpUtils.getIpAddr()); |
| | |
| | | // 接口返回信息 |
| | | Map<String, Object> rspMap = new HashMap<String, Object>(); |
| | | rspMap.put("access_token", JwtUtils.createToken(claimsMap)); |
| | | rspMap.put("expires_in", expireTime); |
| | | rspMap.put("expires_in", expireAppletTime); |
| | | return rspMap; |
| | | } |
| | | public LoginUserApplet getLoginUserApplet() { |
| | | return getLoginUserAppletToken(ServletUtils.getRequest()); |
| | | LoginUserApplet loginUserAppletToken = getLoginUserAppletToken(ServletUtils.getRequest()); |
| | | if (loginUserAppletToken == null){ |
| | | throw new UserAppletException("登录失效,请重新登录!", 401); |
| | | } |
| | | return loginUserAppletToken; |
| | | } |
| | | public LoginUserApplet getLoginUserAppletToken(HttpServletRequest request) { |
| | | // 获取请求携带的令牌 |
| | |
| | | LoginUserApplet user = null; |
| | | try { |
| | | if (StringUtils.isNotEmpty(token)) { |
| | | String userkey = JwtUtils.getUserKeyApplet(token); |
| | | user = redisService.getCacheObject(getTokenKey(userkey)); |
| | | String userKey = JwtUtils.getUserKeyApplet(token); |
| | | user = redisService.getCacheObject(getTokenKey(userKey)); |
| | | return user; |
| | | } |
| | | } catch (Exception e) { |