import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Maps;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.util.EntityUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;

public class Test {

        public static void main(String[] args) throws UnsupportedEncodingException {
            // token可以从 数据中心 -> 我的接口 中获取
            String token = "2358629f-0599-4c3f-b2c9-59d601f6f70e";
            String url = "http://open.api.tianyancha.com/services/open/ic/baseinfoV2/2.0?keyword=北京中润长弘管理咨询有限公司";
            System.out.println(executeGet(url, token));
        }

        protected static String executeGet(String url, String token) {
            BasicHttpParams httpParams = new BasicHttpParams();
            HttpConnectionParams.setConnectionTimeout(httpParams, 1000);
            HttpConnectionParams.setSoTimeout(httpParams, 1000);
            HttpClient httpClient = new DefaultHttpClient(httpParams);
            String result = null;
            try {
                HttpGet get = new HttpGet(url);
                // 设置header
                get.setHeader("Authorization",token);
                // 设置类型
                HttpResponse response = httpClient.execute(get);
                HttpEntity entity = response.getEntity();
                result = EntityUtils.toString(entity, "utf-8");
                ObjectMapper objectMapper = new ObjectMapper();
                JsonNode jsonNode = objectMapper.readTree(result);


                String name = jsonNode.get("name").asText();
                int age = jsonNode.get("age").asInt();


            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                httpClient.getConnectionManager().shutdown();
            }
            return result;
        }

}