mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-14 05:42:06 +08:00
1、新增ip服务查询接口,对接阿里云第三方服务,服务封装、ip模块旧引用清理、新增ip服务开关和配置;2、新增组织地理信息字段;3、新增登录对地理信息的校验;
This commit is contained in:
-36
@@ -1,36 +0,0 @@
|
||||
package com.cf.imes.framework.ip.core.utils;
|
||||
|
||||
|
||||
import com.cf.imes.framework.ip.core.Area;
|
||||
import com.cf.imes.framework.ip.core.enums.AreaTypeEnum;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* {@link AreaUtils} 的单元测试
|
||||
*
|
||||
* @author 晨丰科技
|
||||
*/
|
||||
public class AreaUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetArea() {
|
||||
// 调用:北京
|
||||
Area area = AreaUtils.getArea(110100);
|
||||
// 断言
|
||||
assertEquals(area.getId(), 110100);
|
||||
assertEquals(area.getName(), "北京市");
|
||||
assertEquals(area.getType(), AreaTypeEnum.CITY.getType());
|
||||
assertEquals(area.getParent().getId(), 110000);
|
||||
assertEquals(area.getChildren().size(), 16);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormat() {
|
||||
assertEquals(AreaUtils.format(110105), "北京 北京市 朝阳区");
|
||||
assertEquals(AreaUtils.format(1), "中国");
|
||||
assertEquals(AreaUtils.format(2), "蒙古");
|
||||
}
|
||||
|
||||
}
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
package com.cf.imes.framework.ip.core.utils;
|
||||
|
||||
import com.cf.imes.framework.ip.core.Area;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.lionsoul.ip2region.xdb.Searcher;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* {@link IPUtils} 的单元测试
|
||||
*
|
||||
* @author wanglhup
|
||||
*/
|
||||
public class IPUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetAreaId_string() {
|
||||
// 120.202.4.0|120.202.4.255|420600
|
||||
Integer areaId = IPUtils.getAreaId("120.202.4.50");
|
||||
assertEquals(420600, areaId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAreaId_long() throws Exception {
|
||||
// 120.203.123.0|120.203.133.255|360900
|
||||
long ip = Searcher.checkIP("120.203.123.250");
|
||||
Integer areaId = IPUtils.getAreaId(ip);
|
||||
assertEquals(360900, areaId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArea_string() {
|
||||
// 120.202.4.0|120.202.4.255|420600
|
||||
Area area = IPUtils.getArea("120.202.4.50");
|
||||
assertEquals("襄阳市", area.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArea_long() throws Exception {
|
||||
// 120.203.123.0|120.203.133.255|360900
|
||||
long ip = Searcher.checkIP("120.203.123.252");
|
||||
Area area = IPUtils.getArea(ip);
|
||||
assertEquals("宜春市", area.getName());
|
||||
}
|
||||
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.cf.imes.framework.ip.service;
|
||||
|
||||
import com.cf.imes.framework.common.exception.ServiceException;
|
||||
import com.cf.imes.framework.ip.config.ChenfengIPAutoConfiguration;
|
||||
import com.cf.imes.framework.ip.core.service.IPQueryService;
|
||||
import com.cf.imes.framework.ip.core.service.dto.IPQueryDataRespDTO;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static com.cf.imes.framework.test.core.util.RandomUtils.randomString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* {@link IPQueryService} 的单元测试
|
||||
*
|
||||
* @author gaoqr
|
||||
*/
|
||||
@SpringBootTest(classes = {ChenfengIPAutoConfiguration.class}, webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
@ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件
|
||||
public class IPQueryServiceTest {
|
||||
@Resource
|
||||
private IPQueryService ipQueryService;
|
||||
|
||||
|
||||
@Test
|
||||
public void testQuerySourceFail() {
|
||||
assertThrows(ServiceException.class, () -> ipQueryService.querySource(randomString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuerySourceSuccess() {
|
||||
IPQueryDataRespDTO ipQueryDataRespDTO = ipQueryService.querySource("220.250.48.74");
|
||||
assertNotNull(ipQueryDataRespDTO);
|
||||
assertEquals(ipQueryDataRespDTO.getProv(), "福建");
|
||||
assertEquals(ipQueryDataRespDTO.getCity(), "福州");
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
# 晨丰配置项,设置当前项目所有自定义的配置
|
||||
chenfeng:
|
||||
encrypt:
|
||||
publicKey: cfimes
|
||||
ipquery:
|
||||
apiUrl: https://ipquery.market.alicloudapi.com/query
|
||||
appCode: zAE0h8wOBZbwIwDob1tXJfJsdxpQ2QYzIgie7oSozCLHXsdD8hhkot6UBs55Vhm35KYrqGj+t0W4IOSr
|
||||
Reference in New Issue
Block a user