mirror of https://github.com/elunez/eladmin
update: 更换 UserAgent 识别库 (#630)
parent
e0ea026d43
commit
3072c9633a
|
@ -18,8 +18,8 @@ package me.zhengjie.utils;
|
||||||
import cn.hutool.http.HttpUtil;
|
import cn.hutool.http.HttpUtil;
|
||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import eu.bitwalker.useragentutils.Browser;
|
import nl.basjes.parse.useragent.UserAgent;
|
||||||
import eu.bitwalker.useragentutils.UserAgent;
|
import nl.basjes.parse.useragent.UserAgentAnalyzer;
|
||||||
import org.lionsoul.ip2region.DataBlock;
|
import org.lionsoul.ip2region.DataBlock;
|
||||||
import org.lionsoul.ip2region.DbConfig;
|
import org.lionsoul.ip2region.DbConfig;
|
||||||
import org.lionsoul.ip2region.DbSearcher;
|
import org.lionsoul.ip2region.DbSearcher;
|
||||||
|
@ -50,6 +50,14 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||||
private static final char SEPARATOR = '_';
|
private static final char SEPARATOR = '_';
|
||||||
private static final String UNKNOWN = "unknown";
|
private static final String UNKNOWN = "unknown";
|
||||||
|
|
||||||
|
private static final UserAgentAnalyzer userAgentAnalyzer = UserAgentAnalyzer
|
||||||
|
.newBuilder()
|
||||||
|
.hideMatcherLoadStats()
|
||||||
|
.withCache(10000)
|
||||||
|
.withField(UserAgent.AGENT_NAME_VERSION)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
SpringContextHolder.addCallBacks(() -> {
|
SpringContextHolder.addCallBacks(() -> {
|
||||||
StringUtils.ipLocal = SpringContextHolder.getProperties("ip.local-parsing", false, Boolean.class);
|
StringUtils.ipLocal = SpringContextHolder.getProperties("ip.local-parsing", false, Boolean.class);
|
||||||
|
@ -225,9 +233,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getBrowser(HttpServletRequest request) {
|
public static String getBrowser(HttpServletRequest request) {
|
||||||
UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
|
UserAgent.ImmutableUserAgent userAgent = userAgentAnalyzer.parse(request.getHeader("User-Agent"));
|
||||||
Browser browser = userAgent.getBrowser();
|
return userAgent.get(UserAgent.AGENT_NAME_VERSION).getValue();
|
||||||
return browser.getName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
6
pom.xml
6
pom.xml
|
@ -203,9 +203,9 @@
|
||||||
|
|
||||||
<!-- 解析客户端操作系统、浏览器信息 -->
|
<!-- 解析客户端操作系统、浏览器信息 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>eu.bitwalker</groupId>
|
<groupId>nl.basjes.parse.useragent</groupId>
|
||||||
<artifactId>UserAgentUtils</artifactId>
|
<artifactId>yauaa</artifactId>
|
||||||
<version>1.21</version>
|
<version>5.23</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue