Commit cd2a8bb9 authored by Administrator's avatar Administrator

2022-11.24 解析ip地址异常处理

parent d09a4c4f
...@@ -175,10 +175,14 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils { ...@@ -175,10 +175,14 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
* 根据ip获取详细地址 * 根据ip获取详细地址
*/ */
public static String getCityInfo(String ip) { public static String getCityInfo(String ip) {
if (ElAdminProperties.ipLocal) { try {
return getLocalCityInfo(ip); if (ElAdminProperties.ipLocal) {
} else { return getLocalCityInfo(ip);
return getHttpCityInfo(ip); } else {
return getHttpCityInfo(ip);
}
} catch (Exception e) {
return "解析失败";
} }
} }
...@@ -187,6 +191,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils { ...@@ -187,6 +191,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
*/ */
public static String getHttpCityInfo(String ip) { public static String getHttpCityInfo(String ip) {
String api = String.format(ElAdminConstant.Url.IP_URL, ip); String api = String.format(ElAdminConstant.Url.IP_URL, ip);
System.out.println("api = " + api);
JSONObject object = JSONUtil.parseObj(HttpUtil.get(api)); JSONObject object = JSONUtil.parseObj(HttpUtil.get(api));
return object.get("addr", String.class); return object.get("addr", String.class);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment