切换风格

默认晚霞 雪山 粉色心情 伦敦 花卉 绿野仙踪 加州 白云 星空 薰衣草 城市 简约黑色 简约米色 龙珠
回复 0

3768

主题

3768

帖子

1万

积分

论坛元老

Rank: 8Rank: 8

积分
12525
【全网首发】自动获取ICP北岸号接口源码[复制链接]
发表于 2022-6-24 22:10:14 | 显示全部楼层 |阅读模式
首先先创建个ICP北岸查询接口
代码如下:
<?php
header("Access-Control-Allow-Origin:*");
header("Access-Control-Allow-Methods:GET");
header("Access-Control-Allow-Headers:x-requested-with,content-type");
header("Content-Type:text/html,application/json;charset=utf-8");
if($_GET['domain']){
$domain=getTopHost($_GET['domain']);
}else{
exit("缺少参数");
}
$timeStamp=time();
$authKey=md5("testtest".$timeStamp);
$token=json_decode(curl_post("auth","authKey=$authKey&amp;timeStamp=$timeStamp","application/x-www-form-urlencoded;charset=UTF-8","0"));
$token=$token->params->bussiness;
$query=json_decode(curl_post("icpAbbreviateInfo/queryByCondition",'{"pageNum":"","pageSize":"","unitName":"'.$domain.'"}',"application/json;charset=UTF-8",$token));
$query=json_encode($query->params->list);
$query=str_replace("[","",$query);
$query=json_decode(str_replace("]","",$query));
$icp=$query->serviceLicence;
$unitName=$query->unitName;
$natureName=$query->natureName;
if(!$token){
$icp="服务器请求频率过高,请稍后再试";
$msg="查询失败";
$code="0";
}elseif(!$icp){
$icp="未北岸";
$msg="查询成功";
$code="1";
}else{
$msg="查询成功";
$code="1";
}
$json=array(
'icp'=>$icp,
'unitName'=>$unitName,
'natureName'=>$natureName,
'msg'=>$msg,
'result'=>$code
);
print_r(json_encode($json,JSON_UNESCAPED_UNICODE));
functioncurl_post($url,$data,$Content,$token){
$ip="101.".mt_rand(1,255).".".mt_rand(1,255).".".mt_rand(1,255);
$ch=curl_init();
$headers=array(
"Content-TypeContent",
"Origin:https://beian.miit.gov.cn/",
"Referer:https://beian.miit.gov.cn/",
"tokentoken",
"User-Agent:Mozilla/5.0(WindowsNT10.0;WOW64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/80.0.3987.87Safari/537.36",
"CLIENT-IPip",
"X-FORWARDED-FORip"
);
curl_setopt($ch,CURLOPT_URL,"https://hlwicpfwc.miit.gov.cn/icpproject_query/api/".$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_TIMEOUT,10);
$content=curl_exec($ch);
curl_close($ch);
return$content;
}
functiongetTopHost($url){
if(stristr($url,"http")===false){
$url="http://".$url;
}
$url=strtolower($url);
$hosts=parse_url($url);
$host=$hosts['host'];
$data=explode('.',$host);
$n=count($data);
$preg='/[\w].+\.(com|net|org|gov|edu)\.cn$/';
$pregip='/((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}/';
if(($n>2)&amp;&amp;preg_match($preg,$host)){
$host=$data[$n-3].'.'.$data[$n-2].'.'.$data[$n-1];
}elseif(preg_match($pregip,$host)){
$host=$host;
}else{
$host=$data[$n-2].'.'.$data[$n-1];
}
return$host;
}
复制代码
接下来创建自动获取ICP北岸号接口代码
代码如下:
<?php
header("Content-type:application/json;charset=utf-8");
//echook(get_Domain());
echo"{document.write('".ok(get_Domain())."');}";
functionok($url){
$url='这里文字替换成icp北岸查询接口地址?domain='.$url;
$data=curl_get($url);
$data=json_decode($data,true);
$info=$data['icp'];
return$info;
}
functionget_Domain()
{
$scriptpath=str_replace('\\','/',$_SERVER['SCRIPT_NAME']);
$sitepath=substr($scriptpath,0,strrpos($scriptpath,'/'));
$siteurl=($_SERVER['SERVER_PORT']=='443').$_SERVER['HTTP_REFERER'].$sitepath.'/';
return$siteurl;
}
functioncurl_get($url)
{
$ch=curl_init($url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0(Linux;U;Android4.4.1;zh-cn;R815TBuild/JOP40D)AppleWebKit/533.1(KHTML,likeGecko)Version/4.0MQQBrowser/4.5MobileSafari/533.1');
curl_setopt($ch,CURLOPT_TIMEOUT,30);
$content=curl_exec($ch);
curl_close($ch);
return($content);
}
复制代码
调用代码示例:
<atarget="_blank"><scriptsrc="这里填入接口地址"></script></a>
复制代码
把调用代码放入你网站北岸号填写位置就可以根据当前网站域名自动获取北岸号并显示,方便了域名比较多又懒得一个个查询北岸号的站长。
221014ox4mlu7y9lo970rb.jpg
----------------------------
技术有限,大佬勿喷,不接受任何反驳,如果你觉得不行,那么请你开源!
最后的最后!!!免费的威望可以来一波吗
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|不懂 ( 粤ICP备14042591号-1 )|网站地图

GMT+8, 2024-11-1 22:31 , Processed in 0.125940 second(s), 30 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

返回顶部