Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
3072c963
Unverified
Commit
3072c963
authored
Apr 25, 2021
by
Tsln
Committed by
GitHub
Apr 25, 2021
Browse files
update: 更换 UserAgent 识别库 (#630)
parent
e0ea026d
Changes
2
Hide whitespace changes
Inline
Side-by-side
eladmin-common/src/main/java/me/zhengjie/utils/StringUtils.java
View file @
3072c963
...
...
@@ -18,8 +18,8 @@ package me.zhengjie.utils;
import
cn.hutool.http.HttpUtil
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
import
eu.bitwalker.useragentutils.Browser
;
import
eu.bitwalker
.useragent
utils
.UserAgent
;
import
nl.basjes.parse.useragent.UserAgent
;
import
nl.basjes.parse
.useragent.UserAgent
Analyzer
;
import
org.lionsoul.ip2region.DataBlock
;
import
org.lionsoul.ip2region.DbConfig
;
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
String
UNKNOWN
=
"unknown"
;
private
static
final
UserAgentAnalyzer
userAgentAnalyzer
=
UserAgentAnalyzer
.
newBuilder
()
.
hideMatcherLoadStats
()
.
withCache
(
10000
)
.
withField
(
UserAgent
.
AGENT_NAME_VERSION
)
.
build
();
static
{
SpringContextHolder
.
addCallBacks
(()
->
{
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
)
{
UserAgent
userAgent
=
UserAgent
.
parseUserAgentString
(
request
.
getHeader
(
"User-Agent"
));
Browser
browser
=
userAgent
.
getBrowser
();
return
browser
.
getName
();
UserAgent
.
ImmutableUserAgent
userAgent
=
userAgentAnalyzer
.
parse
(
request
.
getHeader
(
"User-Agent"
));
return
userAgent
.
get
(
UserAgent
.
AGENT_NAME_VERSION
).
getValue
();
}
/**
...
...
pom.xml
View file @
3072c963
...
...
@@ -203,9 +203,9 @@
<!-- 解析客户端操作系统、浏览器信息 -->
<dependency>
<groupId>
eu.bitwalker
</groupId>
<artifactId>
UserAgentUtils
</artifactId>
<version>
1
.2
1
</version>
<groupId>
nl.basjes.parse.useragent
</groupId>
<artifactId>
yauaa
</artifactId>
<version>
5
.2
3
</version>
</dependency>
</dependencies>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment