新增新版指纹ip限制。
This commit is contained in:
parent
e9db47df91
commit
dca8ba79f1
@ -109,13 +109,22 @@ public interface LatestMobileDeviceService extends BaseService<LatestMobileDevic
|
||||
Set<Long> getImeiUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户设备指纹
|
||||
* 获取用户设备指纹(旧版)
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 设备指纹字符串
|
||||
*/
|
||||
String getDeviceFingerprintByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户设备指纹(增强版)
|
||||
* 包含:手机型号 + 系统版本 + IMEI + IP段 + 编译版本
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 设备指纹MD5字符串
|
||||
*/
|
||||
String getEnhancedDeviceFingerprintByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据设备指纹获取所有使用该指纹的用户ID列表
|
||||
*
|
||||
|
||||
@ -12,6 +12,9 @@ import com.red.circle.other.infra.database.rds.dao.user.device.LatestMobileDevic
|
||||
import com.red.circle.other.infra.database.rds.entity.user.user.LatestMobileDevice;
|
||||
import com.red.circle.other.infra.database.rds.service.user.device.LatestMobileDeviceService;
|
||||
import com.red.circle.other.inner.model.cmd.user.device.PageLatestMobileDeviceQryCmd;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@ -297,8 +300,27 @@ public class LatestMobileDeviceServiceImpl extends
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEnhancedDeviceFingerprintByUserId(Long userId) {
|
||||
if (userId == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
LatestMobileDevice device = query()
|
||||
.eq(LatestMobileDevice::getUserId, userId)
|
||||
.orderByDesc(LatestMobileDevice::getCreateTime)
|
||||
.last(PageConstant.LIMIT_ONE)
|
||||
.getOne();
|
||||
|
||||
if (device == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return buildEnhancedDeviceFingerprint(device);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建设备指纹
|
||||
* 构建设备指纹(旧版)
|
||||
*/
|
||||
private String buildDeviceFingerprint(String requestClient,
|
||||
String phoneModel, String ip) {
|
||||
@ -311,6 +333,47 @@ public class LatestMobileDeviceServiceImpl extends
|
||||
return requestClient + "|" + phoneModel + "|" + ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建增强版设备指纹
|
||||
* 组成:手机型号 + 系统版本 + IMEI + IP段 + 编译版本
|
||||
*/
|
||||
private String buildEnhancedDeviceFingerprint(LatestMobileDevice device) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append(StringUtils.isBlank(device.getPhoneModel()) ? "" : device.getPhoneModel()).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(Objects.nonNull(device.getBuildVersion()) ? device.getBuildVersion() : 0);
|
||||
|
||||
return DigestUtils.md5DigestAsHex(sb.toString().getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取IP前缀段(提高稳定性)
|
||||
* IPv4: 取前3段(如 192.168.1.xxx -> 192.168.1)
|
||||
* IPv6: 取前4段(如 2a0d:5600:24:449:xxx -> 2a0d:5600:24:449)
|
||||
*/
|
||||
private String getIpPrefix(String ip) {
|
||||
if (StringUtils.isBlank(ip)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (ip.contains(":")) {
|
||||
String[] parts = ip.split(":");
|
||||
if (parts.length >= 4) {
|
||||
return parts[0] + ":" + parts[1] + ":" + parts[2] + ":" + parts[3];
|
||||
}
|
||||
return ip;
|
||||
} else {
|
||||
String[] parts = ip.split("\\.");
|
||||
if (parts.length >= 3) {
|
||||
return parts[0] + "." + parts[1] + "." + parts[2];
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> listUserIdsByDeviceFingerprint(String fingerprint, String sysOrigin) {
|
||||
if (StringUtils.isBlank(fingerprint) || StringUtils.isBlank(sysOrigin)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user