destoon 调用第三方api接口

调用企查查企业工商信息接口为例:

在 \api\extend.func.php 文件下   注意:有注释内容可能接口无法访问

function select_list($k){
	$query_data = array(
		'key'=>'',
		'keyword'=>$k
	);
	$url = "https://api.qichacha.com/ECIV4/GetBasicDetailsByName?".http_build_query($query_data);
	$data = "xxxxxxxxxxxxxxx".time()."xxxxxxxxxxxxxxxxxx";//这里参考文档
	$data = md5($data);
	$data = strtoupper($data);
	$Timespan = time();
	 $header = array(
         'Token:'. $data,
		 'Timespan:'.$Timespan,
     );
	$curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_TIMEOUT, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    $data = curl_exec($curl);
    if (curl_error($curl)) {
        print "Error: " . curl_error($curl);
    } else {
		$result = json_decode($data,true);	
        return $result;
    }
	var_dump($k);
}

 模板页面调用:

{php $QCC = select_list('测试');}	
{if $QCC['Status']==200}
    {$QCC['Result']['Name']}
{/if}	

你可能感兴趣的:(destoon,php)