Java Code Examples for com.ruoyi.common.utils.http.HttpUtils

The following examples show how to use com.ruoyi.common.utils.http.HttpUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: supplierShop   Source File: AddressUtils.java    License: MIT License 5 votes vote down vote up
public static String getRealAddressByIP(String ip)
{
    String address = "XX XX";

    // 内网不查询
    if (IpUtils.internalIp(ip))
    {
        return "内网IP";
    }
    if (Global.isAddressEnabled())
    {
        String rspStr = HttpUtils.sendPost(IP_URL, "ip=" + ip);
        if (StringUtils.isEmpty(rspStr))
        {
            log.error("获取地理位置异常 {}", ip);
            return address;
        }
        JSONObject obj;
        try
        {
            obj = JSON.unmarshal(rspStr, JSONObject.class);
            JSONObject data = obj.getObj("data");
            String region = data.getStr("region");
            String city = data.getStr("city");
            address = region + " " + city;
        }
        catch (Exception e)
        {
            log.error("获取地理位置异常 {}", ip);
        }
    }
    return address;
}
 
Example 2
Source Project: RuoYi-Vue   Source File: AddressUtils.java    License: MIT License 5 votes vote down vote up
public static String getRealAddressByIP(String ip)
{
    String address = UNKNOWN;
    // 内网不查询
    if (IpUtils.internalIp(ip))
    {
        return "内网IP";
    }
    if (RuoYiConfig.isAddressEnabled())
    {
        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;
}
 
Example 3
Source Project: ruoyiplus   Source File: AddressUtils.java    License: MIT License 5 votes vote down vote up
public static String getRealAddressByIP(String ip)
{
    String address = "XX XX";

    // 内网不查询
    if (IpUtils.internalIp(ip))
    {
        return "内网IP";
    }
    if (Global.isAddressEnabled())
    {
        String rspStr = HttpUtils.sendPost(IP_URL, "ip=" + ip);
        if (StringUtils.isEmpty(rspStr))
        {
            log.error("获取地理位置异常 {}", ip);
            return address;
        }
        JSONObject obj;
        try
        {
            obj = JSON.unmarshal(rspStr, JSONObject.class);
            JSONObject data = obj.getObj("data");
            String region = data.getStr("region");
            String city = data.getStr("city");
            address = region + " " + city;
        }
        catch (Exception e)
        {
            log.error("获取地理位置异常 {}", ip);
        }
    }
    return address;
}