From 695cb6d76b838b1e4cb161bae335faa948dca12a Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期三, 27 十月 2021 13:16:19 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into satoken --- ruoyi-common/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java | 70 +++++++++++++++++----------------- 1 files changed, 35 insertions(+), 35 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java index bd7522c..808cc8d 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java @@ -14,45 +14,45 @@ /** * 鑾峰彇鍦板潃绫� * - * @author ruoyi + * @author Lion Li */ @Slf4j public class AddressUtils { - // IP鍦板潃鏌ヨ - public static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp"; + // IP鍦板潃鏌ヨ + public static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp"; - // 鏈煡鍦板潃 - public static final String UNKNOWN = "XX XX"; + // 鏈煡鍦板潃 + public static final String UNKNOWN = "XX XX"; - public static String getRealAddressByIP(String ip) { - String address = UNKNOWN; - if (StringUtils.isBlank(ip)){ - return address; - } - // 鍐呯綉涓嶆煡璇� - ip = "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : HtmlUtil.cleanHtmlTag(ip); - if (NetUtil.isInnerIP(ip)) { - return "鍐呯綉IP"; - } - if (RuoYiConfig.isAddressEnabled()) { - try { - String rspStr = HttpUtil.createGet(IP_URL) - .body("ip=" + ip + "&json=true", Constants.GBK) - .execute() - .body(); - if (StringUtils.isEmpty(rspStr)) { - log.error("鑾峰彇鍦扮悊浣嶇疆寮傚父 {}", ip); - return UNKNOWN; - } - Map<String, String> obj = JsonUtils.parseMap(rspStr); - String region = obj.get("pro"); - String city = obj.get("city"); - return String.format("%s %s", region, city); - } catch (Exception e) { - log.error("鑾峰彇鍦扮悊浣嶇疆寮傚父 {}", ip); - } - } - return address; - } + public static String getRealAddressByIP(String ip) { + String address = UNKNOWN; + if (StringUtils.isBlank(ip)) { + return address; + } + // 鍐呯綉涓嶆煡璇� + ip = "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : HtmlUtil.cleanHtmlTag(ip); + if (NetUtil.isInnerIP(ip)) { + return "鍐呯綉IP"; + } + if (RuoYiConfig.isAddressEnabled()) { + try { + String rspStr = HttpUtil.createGet(IP_URL) + .body("ip=" + ip + "&json=true", Constants.GBK) + .execute() + .body(); + if (StringUtils.isEmpty(rspStr)) { + log.error("鑾峰彇鍦扮悊浣嶇疆寮傚父 {}", ip); + return UNKNOWN; + } + Map<String, String> obj = JsonUtils.parseMap(rspStr); + String region = obj.get("pro"); + String city = obj.get("city"); + return String.format("%s %s", region, city); + } catch (Exception e) { + log.error("鑾峰彇鍦扮悊浣嶇疆寮傚父 {}", ip); + } + } + return address; + } } -- Gitblit v1.9.3