天眼查接口的調用


{
    "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);
    }  
} 

返回結果

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM