package cn.juhe;
import net.sf.json.JSONObject;
import org.springframework.web.client.RestTemplate;
/**
* ip地址查询Java版本demo
*/
public class IpDemo {
//请求的接口地址
public static final String REQUEST_URL = "http://apis.juhe.cn/ip/ipNew?ip=%s&key=%s";
//请求的key
public static final String APP_KEY = "这里填写您自己在聚合申请的IP查询的接口key";
public static void main(String[] args) {
System.out.println(getIpResponse("这里填写您要查询的ip地址"));
}
/**
* 调用接口
* @param ip ip地址
* @return 接口返回值
*/
public static JSONObject getIpResponse(String ip){
RestTemplate restTemplate = new RestTemplate();
return restTemplate.getForObject(String.format(REQUEST_URL, ip, APP_KEY), JSONObject.class);
}
}