小么熊🐻 2 жил өмнө
parent
commit
5e17d6d2f5

BIN
nbjk-admin/src/main/resources/geolite/GeoLite2-City.mmdb


+ 96 - 0
nbjk-admin/src/test/java/com/miaxis/test/NormalTest2.java

@@ -0,0 +1,96 @@
+package com.miaxis.test;
+
+import com.maxmind.geoip2.DatabaseReader;
+import com.maxmind.geoip2.exception.GeoIp2Exception;
+import com.maxmind.geoip2.model.CityResponse;
+import com.miaxis.NbjkApplication;
+import com.miaxis.score.service.IScoreInfoService;
+import com.miaxis.vip.service.IVipUserExamService;
+import com.miaxis.wx.service.IWxGzhService;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+@ActiveProfiles("dev")
+@SpringBootTest(classes = NbjkApplication.class)
+@RunWith(SpringRunner.class)
+public class NormalTest2 {
+
+    @Autowired
+    private IScoreInfoService iScoreInfoService;
+
+
+    @Autowired
+    private IWxGzhService wxGzhService;
+
+
+    @Autowired
+    private IVipUserExamService vipUserExamService;
+
+    @Test
+    public void test1() throws Exception {
+
+// 替换成你自己的 GeoIP 数据库文件路径
+        //File database = new File("geolite/GeoLite2-City.mmdb");
+
+        File database = new ClassPathResource("geolite/GeoLite2-City.mmdb").getFile();
+
+
+        // 初始化 GeoIP 数据库
+        DatabaseReader reader = new DatabaseReader.Builder(database).build();
+
+        // 替换成你要查询的 IP 地址
+        InetAddress ipAddress = InetAddress.getByName("37.19.195.69");
+
+        // 获取 IP 地址的位置信息
+        CityResponse response = reader.city(ipAddress);
+
+        // 输出位置信息
+        System.out.println(response.getCountry().getNames().get("zh-CN"));
+        System.out.println(response.getMostSpecificSubdivision().getNames().get("zh-CN"));
+        System.out.println(response.getCity().getNames().get("zh-CN"));
+
+    }
+
+    public static void main(String[] args) throws IOException, GeoIp2Exception {
+        // 替换成你自己的 GeoIP 数据库文件路径
+        //File database = new File("geolite/GeoLite2-City.mmdb");
+        File database = new ClassPathResource("geolite/GeoLite2-City.mmdb").getFile();
+        // 初始化 GeoIP 数据库
+        DatabaseReader reader = new DatabaseReader.Builder(database).build();
+
+        // 替换成你要查询的 IP 地址
+        InetAddress ipAddress = InetAddress.getByName("218.85.55.253");
+
+        // 获取 IP 地址的位置信息
+        CityResponse response = reader.city(ipAddress);
+
+        // 输出位置信息
+        System.out.println(response.getCountry().getNames().get("zh-CN"));
+        System.out.println(response.getMostSpecificSubdivision().getNames().get("zh-CN"));
+        System.out.println(response.getCity().getNames().get("zh-CN"));
+    }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}

+ 7 - 0
nbjk-common/pom.xml

@@ -266,6 +266,13 @@
             <version>0.0.3</version>
         </dependency>
 
+        <!-- https://mvnrepository.com/artifact/com.maxmind.geoip2/geoip2 -->
+        <dependency>
+            <groupId>com.maxmind.geoip2</groupId>
+            <artifactId>geoip2</artifactId>
+            <version>2.16.0</version>
+        </dependency>
+
     </dependencies>
 
 </project>

+ 0 - 9
pom.xml

@@ -233,15 +233,6 @@
                 <version>${feign.version}</version>
             </dependency>
 
-            <!-- https://mvnrepository.com/artifact/com.maxmind.geoip2/geoip2 -->
-            <dependency>
-                <groupId>com.maxmind.geoip2</groupId>
-                <artifactId>geoip2</artifactId>
-                <version>3.0.1</version>
-            </dependency>
-
-
-
         </dependencies>
     </dependencyManagement>