Pre Merge pull request !412 from guxin0123/master
This commit is contained in:
@ -115,8 +115,8 @@
|
||||
|
||||
<!-- 解析客户端操作系统、浏览器等 -->
|
||||
<dependency>
|
||||
<groupId>eu.bitwalker</groupId>
|
||||
<artifactId>UserAgentUtils</artifactId>
|
||||
<groupId>com.blueconic</groupId>
|
||||
<artifactId>browscap-java</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- servlet包 -->
|
||||
|
@ -0,0 +1,42 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import com.blueconic.browscap.Capabilities;
|
||||
import com.blueconic.browscap.ParseException;
|
||||
import com.blueconic.browscap.UserAgentParser;
|
||||
import com.blueconic.browscap.UserAgentService;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 浏览器UserAgent工具类
|
||||
*
|
||||
* @author Gux
|
||||
*/
|
||||
public class UserAgentUtils {
|
||||
|
||||
UserAgentParser parser;
|
||||
String browser = "";
|
||||
String platform = "";
|
||||
|
||||
public static UserAgentUtils parseUserAgentString(String userAgentString) {
|
||||
UserAgentUtils userAgentUtils = new UserAgentUtils();
|
||||
try {
|
||||
userAgentUtils.parser = new UserAgentService().loadParser();
|
||||
final Capabilities capabilities = userAgentUtils.parser.parse(userAgentString);
|
||||
userAgentUtils.browser = capabilities.getBrowser() + " " + capabilities.getBrowserMajorVersion();
|
||||
userAgentUtils.platform = capabilities.getPlatform();
|
||||
} catch (IOException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return userAgentUtils;
|
||||
}
|
||||
|
||||
public String getBrowser() {
|
||||
return browser;
|
||||
}
|
||||
|
||||
public String getOperatingSystem() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user