|
|
|
@ -19,22 +19,20 @@ public class AddressUtils
|
|
|
|
|
|
|
|
|
|
public static String getRealAddressByIP(String ip)
|
|
|
|
|
{
|
|
|
|
|
String address = "";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
String address = "XX XX";
|
|
|
|
|
if (RuoYiConfig.isAddressEnabled())
|
|
|
|
|
{
|
|
|
|
|
address = HttpUtils.sendPost(IP_URL, "ip=" + ip);
|
|
|
|
|
JSONObject json = JSONObject.parseObject(address);
|
|
|
|
|
JSONObject object = json.getObject("data", JSONObject.class);
|
|
|
|
|
String region = object.getString("region");
|
|
|
|
|
String city = object.getString("city");
|
|
|
|
|
address = region + " " + city;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
String rspStr = HttpUtils.sendPost(IP_URL, "ip=" + ip);
|
|
|
|
|
if (StringUtils.isEmpty(rspStr))
|
|
|
|
|
{
|
|
|
|
|
log.error("获取地理位置异常:", 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;
|
|
|
|
|
}
|
|
|
|
|