|
@@ -2,7 +2,7 @@ package com.platform.util;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.platform.entity.Result;
|
|
|
-import com.platform.entity.TokenEntity;
|
|
|
+import com.platform.exception.CommonBaseException;
|
|
|
import com.platform.interceptor.AuthorizationInterceptor;
|
|
|
import com.platform.service.TokenService;
|
|
|
import com.platform.utils.JwtUtil;
|
|
@@ -25,8 +25,6 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -151,8 +149,12 @@ public class ApiBaseAction {
|
|
|
*/
|
|
|
public Long getUserId() {
|
|
|
String token = request.getHeader(AuthorizationInterceptor.LOGIN_TOKEN_KEY);
|
|
|
-
|
|
|
- Claims claims = JwtUtil.parseJWT(token);
|
|
|
+ Claims claims = null;
|
|
|
+ try{
|
|
|
+ claims = JwtUtil.parseJWT(token);
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new CommonBaseException(401,"请先登录");
|
|
|
+ }
|
|
|
return Long.valueOf(claims.get("id", String.class));
|
|
|
}
|
|
|
|
|
@@ -164,14 +166,23 @@ public class ApiBaseAction {
|
|
|
public String getUserName() {
|
|
|
String token = request.getHeader(AuthorizationInterceptor.LOGIN_TOKEN_KEY);
|
|
|
|
|
|
- Claims claims = JwtUtil.parseJWT(token);
|
|
|
+ Claims claims;
|
|
|
+ try{
|
|
|
+ claims = JwtUtil.parseJWT(token);
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new CommonBaseException(401,"请先登录");
|
|
|
+ }
|
|
|
return claims.get("username", String.class);
|
|
|
}
|
|
|
|
|
|
public String getWeixinOpenid() {
|
|
|
String token = request.getHeader(AuthorizationInterceptor.LOGIN_TOKEN_KEY);
|
|
|
-
|
|
|
- Claims claims = JwtUtil.parseJWT(token);
|
|
|
+ Claims claims;
|
|
|
+ try{
|
|
|
+ claims = JwtUtil.parseJWT(token);
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new CommonBaseException(401,"请先登录");
|
|
|
+ }
|
|
|
return claims.get("weixin_openid", String.class);
|
|
|
}
|
|
|
}
|