|
@@ -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"));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|