|
@@ -39,14 +39,17 @@ public class LoginController
|
|
|
|
|
|
String terminal = request.getHeader("terminal");
|
|
|
String merchant = request.getHeader("merchant");
|
|
|
+ String userAgent = request.getHeader("User-Agent");
|
|
|
+
|
|
|
|
|
|
String ip = HttpUtil.getClientIp(request);
|
|
|
loginInfoDTO.setIp(ip);
|
|
|
loginInfoDTO.setTerminal(terminal);
|
|
|
loginInfoDTO.setMerchant(merchant);
|
|
|
|
|
|
- log.info("login request header : ip={},terminal={},merchant={},user-agent={}", ip, terminal, merchant);
|
|
|
-
|
|
|
+ log.info("login request header : ip={},terminal={},merchant={},user-agent={}", ip, terminal, merchant,userAgent);
|
|
|
+ //填充设备信息
|
|
|
+ fillDeviceInfo(userAgent, loginInfoDTO);
|
|
|
|
|
|
return userService.login(loginInfoDTO);
|
|
|
}
|
|
@@ -126,4 +129,58 @@ public class LoginController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Fill device info
|
|
|
+ * @param userAgentStr the string of user agent
|
|
|
+ * @param loginInfoDTO the login info
|
|
|
+ */
|
|
|
+ private void fillDeviceInfo(String userAgentStr, LoginInfoDTO loginInfoDTO)
|
|
|
+ {
|
|
|
+ if (userAgentStr == "" || userAgentStr == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (loginInfoDTO == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ UserAgent userAgent = UserAgent.parseUserAgentString(userAgentStr);
|
|
|
+
|
|
|
+ //获取浏览器对象
|
|
|
+ Browser browser = userAgent.getBrowser();
|
|
|
+
|
|
|
+ //获取操作系统对象
|
|
|
+ OperatingSystem operatingSystem = userAgent.getOperatingSystem();
|
|
|
+
|
|
|
+ //操作系统名称
|
|
|
+ String osName = operatingSystem.getName();
|
|
|
+ loginInfoDTO.setDeviceName(osName);
|
|
|
+
|
|
|
+ //获取厂商
|
|
|
+ String osMfrs = operatingSystem.getManufacturer().toString();
|
|
|
+ loginInfoDTO.setDeviceMfrs(osMfrs);
|
|
|
+
|
|
|
+ //获取设备类型
|
|
|
+ String deviceType = operatingSystem.getDeviceType().toString();
|
|
|
+ loginInfoDTO.setDeviceType(deviceType);
|
|
|
+
|
|
|
+ //获取设备型号
|
|
|
+ if ("MOBILE".equals(deviceType))
|
|
|
+ {
|
|
|
+ Pattern pattern = Pattern.compile(";\\s?(\\S*?\\s?\\S*?)\\s?(Build)?/");
|
|
|
+ Matcher matcher = pattern.matcher(userAgentStr);
|
|
|
+ String model = null;
|
|
|
+ if (matcher.find())
|
|
|
+ {
|
|
|
+ model = matcher.group(1).trim();
|
|
|
+ loginInfoDTO.setDeviceModel(model);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ loginInfoDTO.setDeviceModel(osName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|