设备指纹替换为同IP段+手机型号处理
This commit is contained in:
parent
530229a5fb
commit
c376c42efe
@ -118,7 +118,7 @@ public interface LatestMobileDeviceService extends BaseService<LatestMobileDevic
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户设备指纹(增强版)
|
* 获取用户设备指纹(增强版)
|
||||||
* 包含:手机型号 + 系统版本 + IMEI + IP段 + 编译版本
|
* 包含:手机型号 + 系统版本 + IP段 + 编译版本
|
||||||
*
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @return 设备指纹MD5字符串
|
* @return 设备指纹MD5字符串
|
||||||
|
|||||||
@ -330,48 +330,41 @@ public class LatestMobileDeviceServiceImpl extends
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return requestClient + "|" + phoneModel + "|" + ip;
|
return requestClient + "|" + phoneModel + "|" + getIpPrefix(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建增强版设备指纹
|
* 构建增强版设备指纹
|
||||||
* 组成:手机型号 + 系统版本 + IMEI + IP段 + 编译版本
|
* 组成:手机型号 + 系统版本 + IP段 + 编译版本
|
||||||
*/
|
*/
|
||||||
private String buildEnhancedDeviceFingerprint(LatestMobileDevice device) {
|
private String buildEnhancedDeviceFingerprint(LatestMobileDevice device) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
sb.append(StringUtils.isBlank(device.getPhoneModel()) ? "" : device.getPhoneModel()).append("|");
|
sb.append(StringUtils.isBlank(device.getPhoneModel()) ? "" : device.getPhoneModel()).append("|");
|
||||||
sb.append(StringUtils.isBlank(device.getPhoneSysVersion()) ? "" : device.getPhoneSysVersion()).append("|");
|
sb.append(StringUtils.isBlank(device.getPhoneSysVersion()) ? "" : device.getPhoneSysVersion()).append("|");
|
||||||
sb.append(StringUtils.isBlank(device.getImei()) ? "" : device.getImei()).append("|");
|
|
||||||
sb.append(getIpPrefix(device.getIp())).append("|");
|
sb.append(getIpPrefix(device.getIp())).append("|");
|
||||||
sb.append(Objects.nonNull(device.getBuildVersion()) ? device.getBuildVersion() : 0);
|
|
||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取IP前缀段(提高稳定性)
|
* 获取IP前缀段
|
||||||
* IPv4: 取前3段(如 192.168.1.xxx -> 192.168.1)
|
* IPv4: 取前2段(如 192.168.1.100 -> 192.168)
|
||||||
* IPv6: 取前4段(如 2a0d:5600:24:449:xxx -> 2a0d:5600:24:449)
|
* IPv6: 取前2段(如 2402:ad80:130:d1a2::1 -> 2402:ad80)
|
||||||
*/
|
*/
|
||||||
private String getIpPrefix(String ip) {
|
private String getIpPrefix(String ip) {
|
||||||
if (StringUtils.isBlank(ip)) {
|
if (StringUtils.isBlank(ip)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ip.contains(":")) {
|
String separator = ip.contains(":") ? ":" : "\\.";
|
||||||
String[] parts = ip.split(":");
|
String joinChar = ip.contains(":") ? ":" : ".";
|
||||||
if (parts.length >= 4) {
|
|
||||||
return parts[0] + ":" + parts[1] + ":" + parts[2] + ":" + parts[3];
|
String[] parts = ip.split(separator);
|
||||||
}
|
if (parts.length >= 2) {
|
||||||
return ip;
|
return parts[0] + joinChar + parts[1];
|
||||||
} else {
|
|
||||||
String[] parts = ip.split("\\.");
|
|
||||||
if (parts.length >= 3) {
|
|
||||||
return parts[0] + "." + parts[1] + "." + parts[2];
|
|
||||||
}
|
|
||||||
return ip;
|
|
||||||
}
|
}
|
||||||
|
return ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -387,13 +380,13 @@ public class LatestMobileDeviceServiceImpl extends
|
|||||||
|
|
||||||
String requestClient = parts[0];
|
String requestClient = parts[0];
|
||||||
String phoneModel = parts[1];
|
String phoneModel = parts[1];
|
||||||
String ip = parts[2];
|
String ipPrefix = parts[2];
|
||||||
|
|
||||||
return Optional.ofNullable(query()
|
return Optional.ofNullable(query()
|
||||||
.select(LatestMobileDevice::getUserId)
|
.select(LatestMobileDevice::getUserId)
|
||||||
.eq(LatestMobileDevice::getRequestClient, requestClient)
|
.eq(LatestMobileDevice::getRequestClient, requestClient)
|
||||||
.eq(LatestMobileDevice::getPhoneModel, phoneModel)
|
.eq(LatestMobileDevice::getPhoneModel, phoneModel)
|
||||||
.eq(LatestMobileDevice::getIp, ip)
|
.likeRight(LatestMobileDevice::getIp, ipPrefix) // 前缀匹配
|
||||||
.eq(LatestMobileDevice::getSysOrigin, sysOrigin)
|
.eq(LatestMobileDevice::getSysOrigin, sysOrigin)
|
||||||
.last(PageConstant.formatLimit(500))
|
.last(PageConstant.formatLimit(500))
|
||||||
.list())
|
.list())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user