fix(filter): 修复App-Version参数缺失导致的接口访问问题
- 添加白名单配置,排除部分遗漏App-Version参数的前端接口 - 对getTicket、uploadSingleFile、getInfoById接口跳过版本校验 - 解决iOS打包重新审核期间的接口兼容性问题 - 保留原有版本校验逻辑,仅对白名单接口进行特殊处理
This commit is contained in:
parent
7db9d6ef8e
commit
7cf1dfcf9f
|
|
@ -18,6 +18,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Set;
|
||||
|
||||
@Slf4j
|
||||
@Order(0)
|
||||
|
|
@ -26,28 +27,35 @@ public class AppVersionFilter extends OncePerRequestFilter {
|
|||
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* 因前端部分接口遗漏App-Version参数,ios打包重新审核需要很久,所以需要排除掉,否则会导致接口无法访问
|
||||
*/
|
||||
private static final Set<String> WHITE_LIST = Set.of("getTicket", "uploadSingleFile", "getInfoById");
|
||||
|
||||
private static final String MIN_SUPPER_VERSION = "1.0.9";
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException {
|
||||
String appPlatform = request.getHeader("App-Platform");
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
if (StrUtil.isBlank(appPlatform)) {
|
||||
log.error("请求头中未找到App-Platform");
|
||||
response.setStatus(HttpStatus.UNAUTHORIZED.value());
|
||||
out(response, ApiResult.error(STATE.ServiceConnectRefused, "请更新版本!"));
|
||||
} else {
|
||||
if (appPlatform.startsWith("pc")) {
|
||||
filterChain.doFilter(request, response);
|
||||
if (WHITE_LIST.stream().noneMatch(path -> request.getRequestURI().endsWith(path))) {
|
||||
String appPlatform = request.getHeader("App-Platform");
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
if (StrUtil.isBlank(appPlatform)) {
|
||||
log.error("请求头中未找到App-Platform");
|
||||
response.setStatus(HttpStatus.UNAUTHORIZED.value());
|
||||
out(response, ApiResult.error(STATE.ServiceConnectRefused, "请更新版本!"));
|
||||
} else {
|
||||
String appVersion = request.getHeader("App-Version");
|
||||
if (StrUtil.isBlank(appVersion)) {
|
||||
log.error("请求头中未找到App-Version");
|
||||
out(response, ApiResult.error(STATE.ServiceConnectRefused, "请更新版本!"));
|
||||
} else if (VersionComparator.INSTANCE.compare(appVersion, MIN_SUPPER_VERSION) < 0) {
|
||||
out(response, ApiResult.error(STATE.ServiceConnectRefused, "版本太低,请更新版本!"));
|
||||
} else {
|
||||
if (appPlatform.startsWith("pc")) {
|
||||
filterChain.doFilter(request, response);
|
||||
} else {
|
||||
String appVersion = request.getHeader("App-Version");
|
||||
if (StrUtil.isBlank(appVersion)) {
|
||||
log.error("请求头中未找到App-Version");
|
||||
out(response, ApiResult.error(STATE.ServiceConnectRefused, "请更新版本!"));
|
||||
} else if (VersionComparator.INSTANCE.compare(appVersion, MIN_SUPPER_VERSION) < 0) {
|
||||
out(response, ApiResult.error(STATE.ServiceConnectRefused, "版本太低,请更新版本!"));
|
||||
} else {
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue