From 661cc0afdb7699abcaafff23fa2fe9283979ee06 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期四, 14 五月 2020 16:25:43 +0800
Subject: [PATCH] Merge branch 'master' of https://gitee.com/y_project/RuoYi-Vue
---
ruoyi/src/main/java/com/ruoyi/common/constant/Constants.java | 7 ++++++-
ruoyi/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java | 31 +++++++++++++++++++++----------
ruoyi/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java | 16 +++++++++++++++-
ruoyi/src/main/resources/application.yml | 2 +-
ruoyi/src/main/resources/mybatis/system/SysDeptMapper.xml | 2 +-
5 files changed, 44 insertions(+), 14 deletions(-)
diff --git a/ruoyi/src/main/java/com/ruoyi/common/constant/Constants.java b/ruoyi/src/main/java/com/ruoyi/common/constant/Constants.java
index 3466445..de1c16e 100644
--- a/ruoyi/src/main/java/com/ruoyi/common/constant/Constants.java
+++ b/ruoyi/src/main/java/com/ruoyi/common/constant/Constants.java
@@ -13,7 +13,12 @@
* UTF-8 瀛楃闆�
*/
public static final String UTF8 = "UTF-8";
-
+
+ /**
+ * GBK 瀛楃闆�
+ */
+ public static final String GBK = "GBK";
+
/**
* 閫氱敤鎴愬姛鏍囪瘑
*/
diff --git a/ruoyi/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java b/ruoyi/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java
index a027518..736d9d8 100644
--- a/ruoyi/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java
+++ b/ruoyi/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java
@@ -18,6 +18,7 @@
import javax.net.ssl.X509TrustManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.ruoyi.common.constant.Constants;
/**
* 閫氱敤http鍙戦�佹柟娉�
@@ -37,6 +38,19 @@
*/
public static String sendGet(String url, String param)
{
+ return sendGet(url, param, Constants.UTF8);
+ }
+
+ /**
+ * 鍚戞寚瀹� URL 鍙戦�丟ET鏂规硶鐨勮姹�
+ *
+ * @param url 鍙戦�佽姹傜殑 URL
+ * @param param 璇锋眰鍙傛暟锛岃姹傚弬鏁板簲璇ユ槸 name1=value1&name2=value2 鐨勫舰寮忋��
+ * @param contentType 缂栫爜绫诲瀷
+ * @return 鎵�浠h〃杩滅▼璧勬簮鐨勫搷搴旂粨鏋�
+ */
+ public static String sendGet(String url, String param, String contentType)
+ {
StringBuilder result = new StringBuilder();
BufferedReader in = null;
try
@@ -49,7 +63,7 @@
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
connection.connect();
- in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ in = new BufferedReader(new InputStreamReader(connection.getInputStream(), contentType));
String line;
while ((line = in.readLine()) != null)
{
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 2f172a8..4d2041e 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
@@ -3,6 +3,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSONObject;
+import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.framework.config.RuoYiConfig;
@@ -16,11 +17,15 @@
{
private static final Logger log = LoggerFactory.getLogger(AddressUtils.class);
- public static final String IP_URL = "http://ip.taobao.com/service/getIpInfo.php";
+ // IP鍦板潃鏌ヨ
+ public static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp";
+
+ // 鏈煡鍦板潃
+ public static final String UNKNOWN = "XX XX";
public static String getRealAddressByIP(String ip)
{
- String address = "XX XX";
+ String address = UNKNOWN;
// 鍐呯綉涓嶆煡璇�
if (IpUtils.internalIp(ip))
{
@@ -28,17 +33,23 @@
}
if (RuoYiConfig.isAddressEnabled())
{
- String rspStr = HttpUtils.sendPost(IP_URL, "ip=" + ip);
- if (StringUtils.isEmpty(rspStr))
+ try
+ {
+ String rspStr = HttpUtils.sendGet(IP_URL, "ip=" + ip + "&json=true", Constants.GBK);
+ if (StringUtils.isEmpty(rspStr))
+ {
+ log.error("鑾峰彇鍦扮悊浣嶇疆寮傚父 {}", ip);
+ return UNKNOWN;
+ }
+ JSONObject obj = JSONObject.parseObject(rspStr);
+ String region = obj.getString("pro");
+ String city = obj.getString("city");
+ return String.format("%s %s", region, city);
+ }
+ catch (Exception e)
{
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;
}
return address;
}
diff --git a/ruoyi/src/main/resources/application.yml b/ruoyi/src/main/resources/application.yml
index 029e77a..40afbec 100644
--- a/ruoyi/src/main/resources/application.yml
+++ b/ruoyi/src/main/resources/application.yml
@@ -11,7 +11,7 @@
# 鏂囦欢璺緞 绀轰緥锛� Windows閰嶇疆D:/ruoyi/uploadPath锛孡inux閰嶇疆 /home/ruoyi/uploadPath锛�
profile: D:/ruoyi/uploadPath
# 鑾峰彇ip鍦板潃寮�鍏�
- addressEnabled: true
+ addressEnabled: false
# 寮�鍙戠幆澧冮厤缃�
server:
diff --git a/ruoyi/src/main/resources/mybatis/system/SysDeptMapper.xml b/ruoyi/src/main/resources/mybatis/system/SysDeptMapper.xml
index b89370e..a07d8a0 100644
--- a/ruoyi/src/main/resources/mybatis/system/SysDeptMapper.xml
+++ b/ruoyi/src/main/resources/mybatis/system/SysDeptMapper.xml
@@ -71,7 +71,7 @@
select * from sys_dept where find_in_set(#{deptId}, ancestors)
</select>
- <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="java.lang.Integer">
+ <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors)
</select>
--
Gitblit v1.9.3