From 56050aa6501f3d9d2f79a2c40a28815878ac56ee Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期四, 24 十一月 2022 15:14:47 +0800 Subject: [PATCH] update 同步 ruoyi 相关提交 * fix 修复Log注解GET请求记录不到参数问题 * fix 修复某些特性的环境生成代码变乱码TXT文件问题 * update 消除Vue3控制台出现的警告信息 * fix 开启TopNav没有子菜单隐藏侧边栏 * fix 修复回显数据字典数组异常问题(I60UYQ) * update 忽略不必要的属性数据返回 --- ruoyi-common/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java | 60 ++++++++++++++++++++++++++++++++---------------------------- 1 files changed, 32 insertions(+), 28 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 4805d25..8d3515e 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 @@ -1,21 +1,25 @@ package com.ruoyi.common.utils.ip; -import cn.hutool.core.util.StrUtil; -import com.alibaba.fastjson.JSONObject; +import cn.hutool.core.lang.Dict; +import cn.hutool.core.net.NetUtil; +import cn.hutool.http.HtmlUtil; +import cn.hutool.http.HttpUtil; import com.ruoyi.common.config.RuoYiConfig; import com.ruoyi.common.constant.Constants; -import com.ruoyi.common.utils.http.HttpUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.ruoyi.common.utils.JsonUtils; +import com.ruoyi.common.utils.StringUtils; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; /** * 鑾峰彇鍦板潃绫� - * - * @author ruoyi + * + * @author Lion Li */ -public class AddressUtils -{ - private static final Logger log = LoggerFactory.getLogger(AddressUtils.class); +@Slf4j +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class AddressUtils { // IP鍦板潃鏌ヨ public static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp"; @@ -23,34 +27,34 @@ // 鏈煡鍦板潃 public static final String UNKNOWN = "XX XX"; - public static String getRealAddressByIP(String ip) - { + public static String getRealAddressByIP(String ip) { String address = UNKNOWN; + if (StringUtils.isBlank(ip)) { + return address; + } // 鍐呯綉涓嶆煡璇� - if (IpUtils.internalIp(ip)) - { + 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 = HttpUtils.sendGet(IP_URL, "ip=" + ip + "&json=true", Constants.GBK); - if (StrUtil.isEmpty(rspStr)) - { + 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; } - JSONObject obj = JSONObject.parseObject(rspStr); - String region = obj.getString("pro"); - String city = obj.getString("city"); + Dict obj = JsonUtils.parseMap(rspStr); + String region = obj.getStr("pro"); + String city = obj.getStr("city"); return String.format("%s %s", region, city); - } - catch (Exception e) - { + } catch (Exception e) { log.error("鑾峰彇鍦扮悊浣嶇疆寮傚父 {}", ip); } } - return address; + return UNKNOWN; } } -- Gitblit v1.9.3