From 44fce503194c02969dab38879fae84a458523049 Mon Sep 17 00:00:00 2001 From: shimingxy Date: Fri, 7 Mar 2025 09:06:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IpLocationAutoConfiguration.java | 21 +---- .../maxkey/ip2location/online/Ip138.java | 63 --------------- .../ip2location/online/Ip138Response.java | 81 ------------------- .../maxkey/ip2location/IpRegionIp138Test.java | 31 ------- .../ip2location/IpRegionParserTest.java | 33 -------- 5 files changed, 2 insertions(+), 227 deletions(-) delete mode 100644 maxkey-starter/maxkey-starter-ip2location/src/main/java/org/dromara/maxkey/ip2location/online/Ip138.java delete mode 100644 maxkey-starter/maxkey-starter-ip2location/src/main/java/org/dromara/maxkey/ip2location/online/Ip138Response.java delete mode 100644 maxkey-starter/maxkey-starter-ip2location/src/test/java/org/dromara/maxkey/ip2location/IpRegionIp138Test.java delete mode 100644 maxkey-starter/maxkey-starter-ip2location/src/test/java/org/dromara/maxkey/ip2location/IpRegionParserTest.java diff --git a/maxkey-starter/maxkey-starter-ip2location/src/main/java/org/dromara/maxkey/autoconfigure/IpLocationAutoConfiguration.java b/maxkey-starter/maxkey-starter-ip2location/src/main/java/org/dromara/maxkey/autoconfigure/IpLocationAutoConfiguration.java index 46d52d110..ff84dc9e5 100644 --- a/maxkey-starter/maxkey-starter-ip2location/src/main/java/org/dromara/maxkey/autoconfigure/IpLocationAutoConfiguration.java +++ b/maxkey-starter/maxkey-starter-ip2location/src/main/java/org/dromara/maxkey/autoconfigure/IpLocationAutoConfiguration.java @@ -21,7 +21,6 @@ import org.dromara.maxkey.ip2location.IpLocation; import org.dromara.maxkey.ip2location.IpLocationParser; import org.dromara.maxkey.ip2location.offline.GeoIP2V4; import org.dromara.maxkey.ip2location.offline.Ip2regionV2; -import org.dromara.maxkey.ip2location.online.Ip138; import org.lionsoul.ip2region.xdb.Searcher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -94,23 +93,7 @@ public class IpLocationAutoConfiguration { return ipLocationOffLine; } - /** - * builder Online Provider IpLocation - * @param onlineProvider - * @return IpLocation - */ - public IpLocation builderOnlineProvider(String onlineProvider) { - //need on line provider - IpLocation ipLocationOnLine = null; - if(onlineProvider.equalsIgnoreCase("none")) { - //do nothing - _logger.debug("IpLocation online Provider none"); - }else if(onlineProvider.equalsIgnoreCase("Ip138")){ - ipLocationOnLine = new Ip138(); - _logger.debug("IpLocation online Provider Ip138"); - } - return ipLocationOnLine; - } + /** * IP转换区域地址解析 @@ -127,7 +110,7 @@ public class IpLocationAutoConfiguration { @Value("${maxkey.login.iplocation.offline.provider:Ip2Region}") String offlineProvider) throws Exception { return new IpLocationParser( isIplocation, - builderOnlineProvider(onlineProvider), + null, builderOfflineProvider(offlineProvider) ); } diff --git a/maxkey-starter/maxkey-starter-ip2location/src/main/java/org/dromara/maxkey/ip2location/online/Ip138.java b/maxkey-starter/maxkey-starter-ip2location/src/main/java/org/dromara/maxkey/ip2location/online/Ip138.java deleted file mode 100644 index b50d6588c..000000000 --- a/maxkey-starter/maxkey-starter-ip2location/src/main/java/org/dromara/maxkey/ip2location/online/Ip138.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright [2023] [MaxKey of copyright http://www.maxkey.top] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.dromara.maxkey.ip2location.online; - -import org.dromara.maxkey.ip2location.AbstractIpLocation; -import org.dromara.maxkey.ip2location.IpLocation; -import org.dromara.maxkey.ip2location.Region; -import org.dromara.maxkey.util.JsonUtils; -import org.jsoup.Jsoup; -import org.jsoup.nodes.Document; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Ip138查询ip地址 - * - * @author Crystal.Sea - * - */ -public class Ip138 extends AbstractIpLocation implements IpLocation{ - static final Logger _logger = LoggerFactory.getLogger(Ip138.class); - - public static final String REGION_URL = "https://www.ip138.com/iplookup.asp?ip=%s&action=2"; - - public static final String BEGIN = "\"ip_c_list\":["; - public static final String END = "], \"zg\":0};"; - - @Override - public Region region(String ipAddress) { - try { - Document doc; - doc = Jsoup.connect(String.format(REGION_URL, ipAddress)) - .timeout(TIMEOUT) - .userAgent(USERAGENT) - .header("Host", "www.ip138.com") - .header("Referer", "https://www.ip138.com/") - .header("sec-ch-ua", "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"98\", \"Google Chrome\";v=\"98\"") - .header("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9") - .get(); - String htmlData = doc.toString(); - _logger.trace("html {}",htmlData); - String jsonData = htmlData.substring(htmlData.indexOf(BEGIN) + BEGIN.length() , htmlData.indexOf(END)); - Ip138Response response = JsonUtils.stringToObject(jsonData, Ip138Response.class); - return response == null ? null : new Region(response.getCt(),response.getProv(),response.getCity(),getLocation(response.toString())); - } catch (Exception e) { - _logger.error("Exception ",e); - } - return null; - } -} diff --git a/maxkey-starter/maxkey-starter-ip2location/src/main/java/org/dromara/maxkey/ip2location/online/Ip138Response.java b/maxkey-starter/maxkey-starter-ip2location/src/main/java/org/dromara/maxkey/ip2location/online/Ip138Response.java deleted file mode 100644 index 994febaad..000000000 --- a/maxkey-starter/maxkey-starter-ip2location/src/main/java/org/dromara/maxkey/ip2location/online/Ip138Response.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright [2023] [MaxKey of copyright http://www.maxkey.top] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.dromara.maxkey.ip2location.online; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -/** - * Ip138返回结果 - * - * @author Crystal.Sea - * - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Ip138Response { - - String ct; - String prov; - String city; - String area; - String yunyin; - - public Ip138Response() { - } - public String getCt() { - return ct; - } - public void setCt(String ct) { - this.ct = ct; - } - public String getProv() { - return prov; - } - public void setProv(String prov) { - this.prov = prov; - } - public String getCity() { - return city; - } - public void setCity(String city) { - this.city = city; - } - public String getArea() { - return area; - } - public void setArea(String area) { - this.area = area; - } - public String getYunyin() { - return yunyin; - } - public void setYunyin(String yunyin) { - this.yunyin = yunyin; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append(ct) - .append(prov) - .append(city) - .append(area) - .append(" ") - .append(yunyin); - return builder.toString(); - } - - -} diff --git a/maxkey-starter/maxkey-starter-ip2location/src/test/java/org/dromara/maxkey/ip2location/IpRegionIp138Test.java b/maxkey-starter/maxkey-starter-ip2location/src/test/java/org/dromara/maxkey/ip2location/IpRegionIp138Test.java deleted file mode 100644 index 3890132fb..000000000 --- a/maxkey-starter/maxkey-starter-ip2location/src/test/java/org/dromara/maxkey/ip2location/IpRegionIp138Test.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright [2023] [MaxKey of copyright http://www.maxkey.top] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.dromara.maxkey.ip2location; - - -import org.dromara.maxkey.ip2location.online.Ip138; -import org.junit.Test; - -public class IpRegionIp138Test { - - @Test - public void test(){ - IpLocation ipRegion = new Ip138(); - System.out.println(ipRegion.region("117.155.70.59")); - } - -} diff --git a/maxkey-starter/maxkey-starter-ip2location/src/test/java/org/dromara/maxkey/ip2location/IpRegionParserTest.java b/maxkey-starter/maxkey-starter-ip2location/src/test/java/org/dromara/maxkey/ip2location/IpRegionParserTest.java deleted file mode 100644 index 165e1fae1..000000000 --- a/maxkey-starter/maxkey-starter-ip2location/src/test/java/org/dromara/maxkey/ip2location/IpRegionParserTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright [2023] [MaxKey of copyright http://www.maxkey.top] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.dromara.maxkey.ip2location; - -import org.dromara.maxkey.ip2location.online.Ip138; -import org.junit.Test; - -public class IpRegionParserTest { - - @Test - public void test(){ - System.out.println( - new IpLocationParser().region("127.0.0.1") - ); - - System.out.println( - new IpLocationParser(true,new Ip138(),null).region("117.155.70.59") - ); - } -}