天眼查接口的调用

{
    "msg":"操作成功",
    "result":{
        "result":{
            "result":{
                "historyNames":"深圳发展银行股份有限公司(深圳发展银行)    ",
                "regStatus":"存续",
                "flag":1,
                "regCapital":"1142489.479万人民币",
                "staffNumRange":"1000-4999人",
                "industry":"货币金融服务",
                "bondNum":"000001",
                "type":1,
                "bondName":"平安银行",
                "updateTimes":1544676651000,
                "legalPersonName":"谢永林",
                "regNumber":"440301103098545",
                "property3":"Ping An Bank Co.,Ltd.",
                "creditCode":"91440300192185379H",
                "usedBondName":"深发展A->S深发展A->深发展A",
                "fromTime":567100800000,
                "approvedTime":1482336000000,
                "socialStaffNum":3983,
                "logo":"http://img.tianyancha.com/logo/lll/b84ed9a489c1897c73335cc6c46c36cd.png@!f_200x200",
                "alias":"银行股份",
                "companyOrgType":"股份有限公司(上市)",
                "id":199557844,
                "orgNumber":"192185379",
                "sourceFlag":"http://qyxy.baic.gov.cn/",
                "correctCompanyId":"",
                "toTime":1572537600000,
                "actualCapital":"-",
                "estiblishTime":567100800000,
                "regInstitute":"深圳市市场监督管理局",
                "companyType":201,
                "taxNumber":"91440300192185379H",
                "businessScope":"办理人民币存、贷、结算、汇兑业务;人民币票据承兑和贴现;各项信托业务;经监管机构批准发行或买卖人民币有价证券;外汇存款、汇款;境内境外借款;在境内境外发行或代理发行外币有价证券;贸易、非贸易结算;外币票据的承兑和贴现;外汇放款;代客买卖外汇及外币有价证券,自营外汇买卖;资信调查、咨询、见证业务;保险兼业代理业务;黄金进口业务;经有关监管机构批准或允许的其他业务。(《保险兼业代理业务许可证》有效期限至2015年5月1日)^",
                "regLocation":"深圳市罗湖区深南东路5047号",
                "tags":"中国500强    ;    上市公司    ;",
                "legalPersonId":2176815332,
                "companyId":3976393,
                "categoryScore":8863,
                "name":"平安银行股份有限公司",
                "bondType":"A股",
                "percentileScore":9969,
                "updatetime":1544676654873,
                "isMicroEnt":0,
                "base":"gd"
            },
            "reason":"ok",
            "error_code":0
        }
    },
    "code":1000
}

 

  打开天眼查文档    https://open.tianyancha.com/open/362

 

package com.utils;

import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public class HttpClientUtillsByTYC {  
    private static Logger logger = LoggerFactory  
            .getLogger(HttpClientUtillsByTYC.class); // 日志记录  
  
      
    /** 
     * post请求传输json参数 
     *  
     * @param url 
     *            url地址 
     *            参数
     * @return 
     */  
    public static JSONObject httpPost(String url, JSONObject jsonParam) {  
        // post请求返回结果  
        CloseableHttpClient httpClient = HttpClients.createDefault();  
        JSONObject jsonResult = null;  
        HttpPost httpPost = new HttpPost(url);  
        // 设置请求和传输超时时间  
        RequestConfig requestConfig = RequestConfig.custom()  
                .setSocketTimeout(2000).setConnectTimeout(2000).build();  
        httpPost.setConfig(requestConfig);  
        try {  
            if (null != jsonParam) {  
                // 解决中文乱码问题  
                StringEntity entity = new StringEntity(jsonParam.toString(),  
                        "utf-8");  
                entity.setContentEncoding("UTF-8");  
                entity.setContentType("application/json");  
                httpPost.setEntity(entity);  
            }  
            CloseableHttpResponse result = httpClient.execute(httpPost);  
            //请求发送成功,并得到响应  
            if (result.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {  
                String str = "";  
                try {  
                    //读取服务器返回过来的json字符串数据   
                    str = EntityUtils.toString(result.getEntity(), "utf-8");  
                    //把json字符串转换成json对象   
                    jsonResult = JSONObject.parseObject(str);  
                } catch (Exception e) {  
                    logger.error("post请求提交失败:" + url, e);  
                }  
            }  
        } catch (IOException e) {  
            logger.error("post请求提交失败:" + url, e);  
        } finally {  
            httpPost.releaseConnection();  
        }  
        return jsonResult;  
    }  
      
      
    /** 
     * post请求传输String参数 
     * 例如:name=Jack&sex=1&type=2 
     * Content-type:application/x-www-form-urlencoded 
     * @param url 
     *            url地址 
     * @param strParam 
     *            参数 
     *            不需要返回结果
     * @return 
     */  
    public static String httpPost(String url, String strParam) {  
        // post请求返回结果  
        CloseableHttpClient httpClient = HttpClients.createDefault();  
        String res = "";
        HttpPost httpPost = new HttpPost(url);  
        // 设置请求和传输超时时间  
        RequestConfig requestConfig = RequestConfig.custom()  
                .setSocketTimeout(200000).setConnectTimeout(200000).build();  
        httpPost.setConfig(requestConfig);  
        try {  
            if (null != strParam) {  
                // 解决中文乱码问题  
                StringEntity entity = new StringEntity(strParam,"utf-8");  
                entity.setContentEncoding("UTF-8");  
                entity.setContentType("application/json");  
                httpPost.setEntity(entity);  
            }  
            CloseableHttpResponse result = httpClient.execute(httpPost);  
            //请求发送成功,并得到响应  
            if (result.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {  
                String str = "";  
                try {  
                    //读取服务器返回过来的json字符串数据  
                    str = EntityUtils.toString(result.getEntity(), "utf-8");  
                    //把json字符串转换成json对象  
                    res = str;
                } catch (Exception e) {  
                    logger.error("post请求提交失败:" + url, e);  
                }  
            }  
        } catch (IOException e) {  
            logger.error("post请求提交失败:" + url, e);  
        } finally {  
            httpPost.releaseConnection();  
        }  
        return res;  
    }  
  
    /** 
     * 发送get请求 
     *  
     * @param url 
     *            路径 
     * @return 
     */  
    public static JSONObject httpGet(String url) {  
        // get请求返回结果  
        JSONObject jsonResult = null;  
        CloseableHttpClient client = HttpClients.createDefault();  
        // 发送get请求  
        HttpGet request = new HttpGet(url);  
        // 设置请求和传输超时时间  
        RequestConfig requestConfig = RequestConfig.custom()  
                .setSocketTimeout(6000).setConnectTimeout(6000).build();  
        request.setConfig(requestConfig); 
         request.setHeader("Authorization","xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");//token值
        try {  
            CloseableHttpResponse response = client.execute(request);  
  
            //请求发送成功,并得到响应  
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {  
                //读取服务器返回过来的json字符串数据  
                HttpEntity entity = response.getEntity();  
                String strResult = EntityUtils.toString(entity, "utf-8");  
                //把json字符串转换成json对象  
                jsonResult = JSONObject.parseObject(strResult);  
            } else {  
                logger.error("get请求提交失败:" + url);  
            }  
        } catch (IOException e) {  
            logger.error("get请求提交失败:" + url, e);  
        } finally {  
            request.releaseConnection();  
        }  
        return jsonResult;  
    }  
      
    public static void main(String[] args) {
        JSONObject httpGet = httpGet("http://open.api.tianyancha.com/services/v4/open/baseinfo?name=平安银行股份有限公司");
        System.out.println(httpGet);
    }  
} 

返回结果

 

posted @ 2018-12-25 16:10  春眠不觉笑  阅读(9932)  评论(1编辑  收藏  举报