企查查接口

<?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;
    }
}

猜你喜欢

转载自www.cnblogs.com/zwtqf/p/10740094.html