com.gccloud.starter.common.utils.TokenUtils Maven / Gradle / Ivy
package com.gccloud.starter.common.utils;
import org.apache.commons.lang3.StringUtils;
import javax.servlet.http.HttpServletRequest;
/**
* @author liuchengbiao
* @date 2020-07-16 16:51
*/
public class TokenUtils {
/**
* 获取token
*
* @param request
* @return
*/
public static String getToken(HttpServletRequest request, String tokenKey) {
// 从header中获取token
String token = request.getHeader(tokenKey);
if (StringUtils.isBlank(token)) {
token = CookieUtils.getValue(request, tokenKey);
}
if (StringUtils.isBlank(token)) {
// 如果header中不存在token,则从参数中获取token
token = request.getParameter(tokenKey);
}
return token;
}
}