调用方式为:icp.php?d=www.xxx.com
<?php
error_reporting(0);
header("Content-type:application/json; charset=UTF-8");
header('Access-Control-Allow-Origin:*');
$domain = htmlspecialchars($_GET['d'],ENT_QUOTES);
$code = 500;
if ($domain) {
$timeStamp = time();
$authKey = md5("testtest" . $timeStamp);
$token = json_decode(post("auth", "authKey=$authKey&timeStamp=$timeStamp", "", "application/x-www-    form-urlencoded;"));
$token = $token->params->bussiness;
$query = json_decode(post('icpAbbreviateInfo/queryByCondition',"{'unitName': '$domain'}",$token,'application/json;'));
$msg = $query->msg;
$query = $query->params->list[0];
if ($query) {
    $code = 200;
    $domain = $query->domain;
    $data = array(
        'serviceLicence' => $query->serviceLicence,
        'unitName'       => $query->unitName,
        'natureName'     => $query->natureName,
        'updateRecordTime' => $query->updateRecordTime,
    );
}
}

$json = array(
'code'  => $code,
'domain'=> $domain,
'data'  => $data,
'msg'   => $msg
);
foreach ($json as $key => $val) {//清除null
if (empty($val)) {
    unset($json[$key]);
}
}
print_r(json_encode($json,128|256));

function post($url,$data,$token,$content){
$miit = 'https://beian.miit.gov.cn/';
$headers = array(
    "Content-Type: {$content}charset=UTF-8",
    "Origin: $miit",
    "Referer: $miit",
    "token: $token",
    "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36",
);
$options = array(
    'http' => array(
        'header'  => implode("\r\n", $headers),
        'method'  => 'POST',
        'content' => $data,
    ),
);
$contexts  = stream_context_create($options);
$result = file_get_contents("https://hlwicpfwc.miit.gov.cn/icpproject_query/api/$url", false, $contexts);
return $result;
}

?>
最后修改:2023 年 01 月 15 日
如果觉得我的文章对你有用,请随意赞赏