ICP备案信息查询 PHP 源代码

优秀源码 无标签
0 841
WIZ
WIZ 自成一派 2023-01-16 18:07:37
Lv:36级
调用方法 icp.php?d=www.gov.cn
<?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;
}

 ?>



#0000FF
楼主签名:DNSWIZ 站长故事
回帖
回复列表