背景:使用企查查接口时发现官网只提供了,java,c#,等接口没有提供php版本企查查接口请求示例代码,为了方便大家在开发完毕后给大家做个总结
查看链接:数据中心-》我的接口
public function qcc_api($name){
//请求参数
$aData = array(
'key' => 'XXXXXXXXX',
'searchName' => $name
);
//要请求的链接
$sUrl = 'https://api.qichacha.com/NameSearch/GetList?'.http_build_query($aData);
$res = $this->qcc_httpGetRequest($sUrl);
var_dump($res);die;
}
public function qcc_httpGetRequest($sUrl){
//生成token
$currentTime = time();
$secretKey = "XXXXXXXXXXX";
$key = "XXXXXXXXXXX";
$token = strtoupper(md5($key.$currentTime.$secretKey));
//header
$aHeader = array('Token: '.$token, 'Timespan: '.$currentTime);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $sUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader);
curl_setopt($ch, CURLOPT_HTTPGET, true);
$sResult = curl_exec($ch);
if($sError=curl_error($ch)){
die($sError);
}
curl_close($ch);
return $sResult;
}