From 46a1695292f0ad4f9618aed1faa551eb94468ae1 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sun, 23 Feb 2020 15:43:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=B0=E5=9D=80=E5=BC=80?= =?UTF-8?q?=E5=85=B3=E6=97=A0=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/utils/ip/AddressUtils.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/ruoyi/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java b/ruoyi/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java index d70351f9..2709f457 100644 --- a/ruoyi/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java +++ b/ruoyi/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java @@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory; import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.http.HttpUtils; +import com.ruoyi.framework.config.RuoYiConfig; /** * 获取地址类 @@ -25,17 +26,20 @@ public class AddressUtils { return "内网IP"; } - String rspStr = HttpUtils.sendPost(IP_URL, "ip=" + ip); - if (StringUtils.isEmpty(rspStr)) + if (RuoYiConfig.isAddressEnabled()) { - log.error("获取地理位置异常 {}", ip); - return address; + String rspStr = HttpUtils.sendPost(IP_URL, "ip=" + ip); + if (StringUtils.isEmpty(rspStr)) + { + log.error("获取地理位置异常 {}", ip); + return address; + } + JSONObject obj = JSONObject.parseObject(rspStr); + JSONObject data = obj.getObject("data", JSONObject.class); + String region = data.getString("region"); + String city = data.getString("city"); + address = region + " " + city; } - JSONObject obj = JSONObject.parseObject(rspStr); - JSONObject data = obj.getObject("data", JSONObject.class); - String region = data.getString("region"); - String city = data.getString("city"); - address = region + " " + city; return address; } }