diff --git a/luoo_user/pom.xml b/luoo_user/pom.xml index 1dd057a..a388fc2 100644 --- a/luoo_user/pom.xml +++ b/luoo_user/pom.xml @@ -1,17 +1,19 @@ - - 4.0.0 - - com.luoo - luoo_parent - 1.0-SNAPSHOT - - luoo_user - - - org.springframework.boot - spring-boot-starter-data-mongodb - - + + 4.0.0 + + com.luoo + luoo_parent + 1.0-SNAPSHOT + + luoo_user + + + org.springframework.boot + spring-boot-starter-data-mongodb + + org.springframework.boot spring-boot-starter-data-jpa @@ -19,48 +21,48 @@ mysql mysql-connector-java - - org.springframework.boot - spring-boot-starter-data-redis - - - org.springframework.boot - spring-boot-starter-amqp - + + org.springframework.boot + spring-boot-starter-data-redis + + + org.springframework.boot + spring-boot-starter-amqp + com.luoo luoo_common 1.0-SNAPSHOT - - org.apache.commons - commons-lang3 - - - org.springframework.boot - spring-boot-starter-security - - - org.springframework.cloud - spring-cloud-starter-netflix-eureka-client - - - org.springframework.cloud - spring-cloud-starter-config - - - org.springframework.cloud - spring-cloud-bus - - - org.springframework.cloud - spring-cloud-stream-binder-rabbit - - - org.springframework.boot - spring-boot-starter-actuator - - + + org.apache.commons + commons-lang3 + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + org.springframework.cloud + spring-cloud-starter-config + + + org.springframework.cloud + spring-cloud-bus + + + org.springframework.cloud + spring-cloud-stream-binder-rabbit + + + org.springframework.boot + spring-boot-starter-actuator + + org.projectlombok lombok true @@ -71,35 +73,39 @@ 1.0.21 - com.h2database - h2 - - + com.h2database + h2 + - - - - - - - - software.amazon.awssdk - s3 - + + + + + - - com.aliyun - aliyun-java-sdk-dysmsapi - 1.0.0 - - - com.aliyun - aliyun-java-sdk-core - 3.2.5 - + + + software.amazon.awssdk + s3 + - + + com.aliyun + aliyun-java-sdk-dysmsapi + 1.0.0 + + + com.aliyun + aliyun-java-sdk-core + 3.2.5 + + + org.lionsoul + ip2region + 2.7.0 + + app @@ -107,15 +113,18 @@ org.springframework.boot spring-boot-maven-plugin - + com.spotify docker-maven-plugin 0.4.13 - 116.62.145.60:5000/${project.artifactId}:${project.version} + + 116.62.145.60:5000/${project.artifactId}:${project.version} jdk1.8 - ["java", "-jar","/${project.build.finalName}.jar"] + ["java", + "-jar","/${project.build.finalName}.jar"] / diff --git a/luoo_user/src/main/java/com/luoo/user/util/IpUtil.java b/luoo_user/src/main/java/com/luoo/user/util/IpUtil.java index dbf1577..2192461 100644 --- a/luoo_user/src/main/java/com/luoo/user/util/IpUtil.java +++ b/luoo_user/src/main/java/com/luoo/user/util/IpUtil.java @@ -1,7 +1,30 @@ package com.luoo.user.util; +import java.io.InputStream; +import org.lionsoul.ip2region.xdb.Searcher; +import org.springframework.core.io.ClassPathResource; +import org.springframework.util.StreamUtils; + public class IpUtil { + private static final String IP2REGION_DB_FILE_PATH = "ip2region.xdb"; + private static final String UNKNOW_IP = "未知IP"; + private static final Searcher searcher = initSearcher(); + + private static Searcher initSearcher() { + try (InputStream is = new ClassPathResource(IP2REGION_DB_FILE_PATH).getInputStream();) { + byte[] cBuff = StreamUtils.copyToByteArray(is);// Searcher.loadContent(randomAccessFile); + return Searcher.newWithBuffer(cBuff); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + public static String getIpLocation(String ip) { - return "中国"; + try { + return searcher.search(ip).split("\\|")[2].replaceFirst("省", ""); + } catch (Exception e) { + return UNKNOW_IP; + } } } diff --git a/luoo_user/src/main/resources/ip2region.xdb b/luoo_user/src/main/resources/ip2region.xdb new file mode 100644 index 0000000..c78b792 Binary files /dev/null and b/luoo_user/src/main/resources/ip2region.xdb differ diff --git a/luoo_user/src/test/java/com/luoo/user/util/IpUtilTest.java b/luoo_user/src/test/java/com/luoo/user/util/IpUtilTest.java new file mode 100644 index 0000000..94146ac --- /dev/null +++ b/luoo_user/src/test/java/com/luoo/user/util/IpUtilTest.java @@ -0,0 +1,15 @@ +package com.luoo.user.util; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class IpUtilTest { + + @Test + public void test() { + String ip="121.8.215.106"; + System.out.println(IpUtil.getIpLocation(ip)); + } + +}