|
|
@ -58,10 +58,10 @@ public class ProxyServiceImpl implements ProxyService {
|
|
|
|
// 2、有绑定关系直接返回
|
|
|
|
// 2、有绑定关系直接返回
|
|
|
|
ProxyAccountEntity entity = proxyAccountMapper.selectOne(new LambdaQueryWrapper<ProxyAccountEntity>().eq(ProxyAccountEntity::getNid, phone));
|
|
|
|
ProxyAccountEntity entity = proxyAccountMapper.selectOne(new LambdaQueryWrapper<ProxyAccountEntity>().eq(ProxyAccountEntity::getNid, phone));
|
|
|
|
if (ObjectUtil.isNull(entity)) {
|
|
|
|
if (ObjectUtil.isNull(entity)) {
|
|
|
|
throw new BadRequestException("未绑定代理Ip,请绑定ip后重试");
|
|
|
|
throw new BadRequestException("未绑定代理Ip,请绑定ip后重试,号码:" + phone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ProxyEntity proxyEntity = proxyMapper.selectById(entity.getProxyId());
|
|
|
|
ProxyEntity proxyEntity = proxyMapper.selectById(entity.getProxyId());
|
|
|
|
return verifyProxy(proxyEntity);
|
|
|
|
return verifyProxy(proxyEntity, phone);
|
|
|
|
// if (entity != null && entity.getId() != null) {
|
|
|
|
// if (entity != null && entity.getId() != null) {
|
|
|
|
// return proxyMapper.selectById(entity.getProxyId());
|
|
|
|
// return proxyMapper.selectById(entity.getProxyId());
|
|
|
|
// }
|
|
|
|
// }
|
|
|
@ -200,7 +200,7 @@ public class ProxyServiceImpl implements ProxyService {
|
|
|
|
entities = proxyAccountMapper.selectList(new LambdaQueryWrapper<>());
|
|
|
|
entities = proxyAccountMapper.selectList(new LambdaQueryWrapper<>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Map<Long, List<ProxyAccountEntity>> map = entities.stream().collect(Collectors.groupingBy(ProxyAccountEntity::getProxyId));
|
|
|
|
Map<Long, List<ProxyAccountEntity>> map = entities.stream().collect(Collectors.groupingBy(ProxyAccountEntity::getProxyId));
|
|
|
|
|
|
|
|
wrapper.orderByDesc(ProxyEntity::getCreateTime);
|
|
|
|
Page<ProxyEntity> iPage = proxyMapper.selectPage(page, wrapper);
|
|
|
|
Page<ProxyEntity> iPage = proxyMapper.selectPage(page, wrapper);
|
|
|
|
for (ProxyEntity record : iPage.getRecords()) {
|
|
|
|
for (ProxyEntity record : iPage.getRecords()) {
|
|
|
|
if (map.containsKey(record.getId())) {
|
|
|
|
if (map.containsKey(record.getId())) {
|
|
|
@ -215,7 +215,7 @@ public class ProxyServiceImpl implements ProxyService {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<ProxyEntity> list() {
|
|
|
|
public List<ProxyEntity> list() {
|
|
|
|
return proxyMapper.selectList(new QueryWrapper<>());
|
|
|
|
return proxyMapper.selectList(new QueryWrapper<ProxyEntity>().orderByDesc("create_time"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -226,8 +226,21 @@ public class ProxyServiceImpl implements ProxyService {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void addAccountIp(Long proxyId, String phone) {
|
|
|
|
public void addAccountIp(Long proxyId, String phone) {
|
|
|
|
ProxyAccountEntity proxyAccountEntity = new ProxyAccountEntity(phone, proxyId);
|
|
|
|
List<ProxyAccountEntity> list = new ArrayList<>();
|
|
|
|
proxyAccountMapper.insert(proxyAccountEntity);
|
|
|
|
String[] split = phone.split(",");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (String p : split) {
|
|
|
|
|
|
|
|
log.info("号码 =" + p.trim());
|
|
|
|
|
|
|
|
ProxyAccountEntity proxyAccountEntity = new ProxyAccountEntity(p.trim(), proxyId);
|
|
|
|
|
|
|
|
list.add(proxyAccountEntity);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(list)) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
proxyAccountMapper.insertAll(list);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
throw new BadRequestException("请检查输入是否正确");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -262,13 +275,18 @@ public class ProxyServiceImpl implements ProxyService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void addSurplusDay(ProxyDTO proxyDTO) {
|
|
|
|
|
|
|
|
proxyMapper.addSurplusDay(proxyDTO.getIds(), proxyDTO.getSurplusDay());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 验证代理ip是否可用
|
|
|
|
* 验证代理ip是否可用
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param proxyEntity
|
|
|
|
* @param proxyEntity
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private ProxyEntity verifyProxy(ProxyEntity proxyEntity) {
|
|
|
|
private ProxyEntity verifyProxy(ProxyEntity proxyEntity, String phone) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String account = proxyEntity.getAccount();
|
|
|
|
String account = proxyEntity.getAccount();
|
|
|
|
String password = proxyEntity.getPassword();
|
|
|
|
String password = proxyEntity.getPassword();
|
|
|
@ -290,12 +308,12 @@ public class ProxyServiceImpl implements ProxyService {
|
|
|
|
.timeout(2_000)
|
|
|
|
.timeout(2_000)
|
|
|
|
.execute();
|
|
|
|
.execute();
|
|
|
|
if (execute.getStatus() != 200) {
|
|
|
|
if (execute.getStatus() != 200) {
|
|
|
|
log.info("代理请求失败: {}", proxyEntity.getIp());
|
|
|
|
log.info("代理请求失败: {},号码:{}", proxyEntity.getIp(), phone);
|
|
|
|
throw new BadRequestException("代理Ip不可用,请重新绑定");
|
|
|
|
throw new BadRequestException("代理Ip不可用,请重新绑定,号码:" + phone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error("无效的代理地址: {}, 错误信息:{}", proxyEntity.getIp(), e.getMessage());
|
|
|
|
log.error("无效的代理地址: {},号码:{}, 错误信息:{}", proxyEntity.getIp(), phone, e.getMessage());
|
|
|
|
throw new BadRequestException("代理Ip不可用,请重新绑定");
|
|
|
|
throw new BadRequestException("代理Ip不可用,请重新绑定,号码:" + phone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return proxyEntity;
|
|
|
|
return proxyEntity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|