企查查接口

<?php
namespace app\api\controller;

class QiChaCha extends Base
{

    private $key = 'key';
    private $SecretKey = 'value';

    function tocurl($url, $headers)
    {
        //初始化
        $curl = curl_init();
        //設置抓取的url
        curl_setopt($curl, CURLOPT_URL, $url);
        //設置頭文件的信息做爲數據流輸出
        curl_setopt($curl, CURLOPT_HEADER, 0);
        //設置獲取的信息以文件流的形式返回,而不是直接輸出。
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 0);

        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        //執行命令
        $data = curl_exec($curl);
        //關閉URL請求
        curl_close($curl);
        return $data;
    }


    public function search($search_url)
    {
        $time      =  time();
        $key       =  $this->key;
        $Timespan  =  $time;
        $SecretKey =  $this->SecretKey;
        $token =  strtoupper(md5($key.$Timespan.$SecretKey));
        //獲取搜索的關鍵字
        $keyword = input('post.keyword', '');

        $url = $search_url.'?key='.$key.'&keyword='.$keyword;
        $header = array("Token:{$token}","Timespan:{$time}");
        $content = array(
            'key'     => $key,
            'keyword' => $keyword,
        );

        $response = $this->tocurl($url, $header, $content);
        $data = json_decode($response, true);
        return $data;
    }


    /**
     *  企業關鍵字模糊查詢
     */
    public function institutionSearch()
    {
        $data = $this->search('http://api.qichacha.com/ECIV4/Search');
        return $data;
    }

    /**
     * 企業關鍵字精確獲取詳細信息(master)
     */
    function institutionDetail()
    {
        $data = $this->search('http://api.qichacha.com/ECIV4/GetDetailsByName');
        return $data;
    }
}
相關文章
相關標籤/搜索