|
|
|
@ -1,5 +1,11 @@
|
|
|
|
|
package mashibing.online.text.intercept;
|
|
|
|
|
|
|
|
|
|
import com.mashibing.dto.PassengerRequestDto;
|
|
|
|
|
import com.mashibing.dto.TokenResult;
|
|
|
|
|
import com.mashibing.util.JwtUtils;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import mashibing.online.text.consonant.PassengerConsonant;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
import org.springframework.web.servlet.HandlerInterceptor;
|
|
|
|
|
|
|
|
|
@ -7,6 +13,7 @@ import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class JwtIntercept implements HandlerInterceptor {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@ -15,7 +22,28 @@ public class JwtIntercept implements HandlerInterceptor {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
|
|
|
String token = request.getHeader("Authorization");
|
|
|
|
|
boolean result =true;
|
|
|
|
|
TokenResult tokenResult =null;
|
|
|
|
|
try{
|
|
|
|
|
tokenResult = JwtUtils.parseToken(token);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
log.error("解析token异常 e",e.getCause());
|
|
|
|
|
}
|
|
|
|
|
if(!result){
|
|
|
|
|
|
|
|
|
|
return HandlerInterceptor.super.preHandle(request, response, handler);
|
|
|
|
|
}else {
|
|
|
|
|
String phone=tokenResult.getPhoneNum();
|
|
|
|
|
String idendity=tokenResult.getIdendity();
|
|
|
|
|
//根据手机号 和身份类型 查询
|
|
|
|
|
String s = stringRedisTemplate.opsForValue().get(PassengerConsonant.phoneNumberTokenPreKey + phone + idendity);
|
|
|
|
|
if(StringUtils.isNotBlank(s)){
|
|
|
|
|
//token 有效
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|