¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.common.utils.ip; |
| | | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.http.HttpUtils; |
| | | |
| | | /** |
| | | * è·åå°åç±» |
| | | * |
| | | * @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 = "XX XX"; |
| | | // å
ç½ä¸æ¥è¯¢ |
| | | if (IpUtils.internalIp(ip)) |
| | | { |
| | | return "å
ç½IP"; |
| | | } |
| | | String rspStr = HttpUtils.sendPost(IP_URL, "ip=" + ip); |
| | | if (StringUtils.isEmpty(rspStr)) |
| | | { |
| | | 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; |
| | | } |
| | | } |