2018-07-09 08:44:52 +08:00
|
|
|
package com.ruoyi.common.utils;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
2018-07-12 09:58:12 +08:00
|
|
|
import com.ruoyi.common.utils.http.HttpUtils;
|
2018-08-10 14:36:31 +08:00
|
|
|
import com.ruoyi.framework.config.RuoYiConfig;
|
2018-07-09 08:44:52 +08:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取地址类
|
|
|
|
*
|
|
|
|
* @author ruoyi
|
|
|
|
*/
|
|
|
|
public class AddressUtils
|
|
|
|
{
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(AddressUtils.class);
|
|
|
|
|
|
|
|
public static final String IP_URL = "http://ip.taobao.com/service/getIpInfo.php";
|
|
|
|
|
|
|
|
public static String getRealAddressByIP(String ip)
|
|
|
|
{
|
|
|
|
String address = "";
|
|
|
|
try
|
|
|
|
{
|
2018-08-10 14:36:31 +08:00
|
|
|
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;
|
|
|
|
}
|
2018-07-09 08:44:52 +08:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2018-07-26 12:37:33 +08:00
|
|
|
log.error("获取地理位置异常:", e);
|
2018-07-09 08:44:52 +08:00
|
|
|
}
|
|
|
|
return address;
|
|
|
|
}
|
|
|
|
}
|