背景
起因,我在腾讯云开发者社区看到这个帖子
https://cloud.tencent.com/developer/article/1579323
调用的是https://urlsec.qq.com/check.html这个网页的的api(https://cgi.urlsec.qq.com/index.php?m=check&a=check&url=)
参数 | 说明 |
---|---|
url | 检测的网址 |
type | 网址类型:为"1",则网址未知(包括腾讯云绿标)为"2",则网址报毒为"3",则网址安全(即有付费的绿标) |
beian | 是否备案:为"1",则已经备案为"0",则未备案 |
beiancode | 备案号,未备案则空 |
beianorg | 备案主体,未备案则空 |
word | 报毒原因,未报毒则空 |
wordtit | 报毒原因标题,未报毒则空 |
于是,照着他给的接口,写下了这篇文章。
尝试
直接复制粘贴看看能不能用
<?php
header('Content-Type:application/json; charset=utf-8');
function doCurl($url, $data=array(), $header=array(), $referer='', $timeout=30){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_REFERER, $referer);
$response = curl_exec($ch);
if($error=curl_error($ch)){
die($error);
}
curl_close($ch);
return $response;
}
// 调用
$url = 'https://cgi.urlsec.qq.com/index.php?m=check&a=check&url='.$_GET["url"];
$data = array();
// 设置IP
$header = array(
'CLIENT-IP: 192.168.1.100',
'X-FORWARDED-FOR: 192.168.1.100'
);
$referer = 'https://urlsec.qq.com/';
$response = doCurl($url, $data, $header, $referer, 5);
$data = substr($response, 1, -1);
$data = json_decode($data, true);
$url = $data['data']['results']['url'];
$type = $data['data']['results']['whitetype'];
$beian = $data['data']['results']['isDomainICPOk'];
$icpdode = $data['data']['results']['ICPSerial'];
$icporg = $data['data']['results']['Orgnization'];
$word = $data['data']['results']['Wording'];
$wordtit = $data['data']['results']['WordingTitle'];
$json = [
'url' => $url,
'type' => $type,
'beian' => $beian,
'icpdode' => $icpdode,
'icporg' => $icporg,
'word' => $word,
'wordtit' => $wordtit,
];
exit(json_encode($json));
?>
可以使用,中文用的是Unicode编码,后面会提到如何转中文


响应时间:2秒左右

接口是有了,但是,有个查询页面岂不是更加方便?
改变
因为不会html和php
手搓了一个非常烂的查询页面(东拼西凑)


搓完这个页面,我发现原有api输出的json不能满足我的需求(主要因为我是小白,前端写不出改后端
),域名标识类型不能识别,于是我再次手搓,搓出了修改版的api,并且规范了json返回。


大致修改了哪些?
1.加了判断,判断输入是否是域名/网址。(我为了防止报错,两个判断是相互独立的,大佬们可以把两个范围写在一起)
2.对每个事件设计了切确返回值。
3.输出json时,我加了JSON_UNESCAPED_UNICODE,解决开头的Unicode编码问题。
展示
查询qq.com

查询非法字符


这个模板看起来不太行,于是我二开了一个模板。

查询成功

看看非法参数

成功判断
写到最后
文章末尾有打包下载~
php接口源代码:
lb-domain.php
<?php
//域名查询
//文章地址:https://www.mlvlog.com/1546.html
//禁止滥用该接口,以免损害他人权益。
//屏蔽意外错误信息,防止运行目录路径泄露等问题,开发测试时建议注释掉!
//error_reporting(0);
//获取url
$C_url='https://'.$_GET["url"];
$str2="/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/";
//首次参数验证(是否符合url格式)
if (!preg_match($str2,$C_url)){
$error_url = [
'code' => '501',
'message' => '参数错误',
'url' => 'null',
'type' => 'error',
'icpdode' => 'error',
'icporg' => 'error',
'word' => 'error',
'wordtit' => 'error',];
exit(json_encode($error_url,JSON_UNESCAPED_UNICODE))
;
}else{
$C_url=str_replace('https://','',$C_url);
header('Content-Type:application/json; charset=utf-8');
function doCurl($url, $data=array(), $header=array(), $referer='', $timeout=30){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_REFERER, $referer);
$response = curl_exec($ch);
if($error=curl_error($ch)){
die($error);
}
curl_close($ch);
return $response;
}
// 调用
$url = 'https://cgi.urlsec.qq.com/index.php?m=check&a=check&url='.$C_url;
$data = array();
// 设置IP
$header = array(
'CLIENT-IP: 192.168.1.100',
'X-FORWARDED-FOR: 192.168.1.100'
);
$referer = 'https://urlsec.qq.com/';
$response = doCurl($url, $data, $header, $referer, 5);
$data = substr($response, 1, -1);
$data = json_decode($data, true);
$url = $data['data']['results']['url'];
$type = $data['data']['results']['whitetype'];
$beian = $data['data']['results']['isDomainICPOk'];
$icpdode = $data['data']['results']['ICPSerial'];
$icporg = $data['data']['results']['Orgnization'];
$word = $data['data']['results']['Wording'];
$wordtit = $data['data']['results']['WordingTitle'];
//多if嵌套,逐一返回切确值
if ($type==3 AND $beian==1) {
$json = [
'code' => '200',
'message' => '成功',
'url' => $url,
'type' => '网址安全(付费的绿标)',
'icpdode' => $icpdode,
'icporg' => $icporg,
'word' => $word,
'wordtit' => $wordtit,];
exit(json_encode($json,JSON_UNESCAPED_UNICODE));
;}
elseif ($type==3 AND $beian==0){
$json = [
'code' => '200',
'message' => '成功',
'url' => $url,
'type' => '网址安全(付费的绿标)',
'icpdode' => '未备案',
'icporg' => '未备案',
'word' => $word,
'wordtit' => $wordtit,];
exit(json_encode($json,JSON_UNESCAPED_UNICODE));
;}
else {
if ($type==2 AND $beian==1) {
$json = [
'code' => '200',
'message' => '成功',
'url' => $url,
'type' => '报毒',
'icpdode' => $icpdode,
'icporg' => $icporg,
'word' => $word,
'wordtit' => $wordtit,];
exit(json_encode($json,JSON_UNESCAPED_UNICODE));
;}
elseif ($type==2 AND $beian==0){
$json = [
'code' => '200',
'message' => '成功',
'url' => $url,
'type' => '报毒',
'icpdode' => '未备案',
'icporg' => '未备案',
'word' => $word,
'wordtit' => $wordtit,];
exit(json_encode($json,JSON_UNESCAPED_UNICODE));
;}
else {
if ($type==1 AND $beian==1){
$json = [
'code' => '200',
'message' => '成功',
'url' => $url,
'type' => '网址未知(包括腾讯云绿标)',
'icpdode' => $icpdode,
'icporg' => $icporg,
'word' => $word,
'wordtit' => $wordtit,];
exit(json_encode($json,JSON_UNESCAPED_UNICODE));
;}
elseif ($type==1 AND $beian==0){
$json = [
'code' => '200',
'message' => '成功',
'url' => $url,
'type' => '网址未知(包括腾讯云绿标)',
'icpdode' => '未备案',
'icporg' => '未备案',
'word' => $word,
'wordtit' => $wordtit,];
exit(json_encode($json,JSON_UNESCAPED_UNICODE));
;}
else {
$json = [
'code' => '500',
'message' => '参数错误、服务器内部错误',
'url' => 'null',
'type' => 'api出现无法预料的故障',
'icpdode' => '请联系管理员',
'icporg' => 'null',
'word' => 'null',
'wordtit' => 'null',];
exit(json_encode($json,JSON_UNESCAPED_UNICODE));
;}
;}
;}
;}
?>
lb-url.php
<?php
//网址url查询
//文章地址:https://www.mlvlog.com/1546.html
//禁止滥用该接口,以免损害他人权益。
//屏蔽意外错误信息,防止运行目录路径泄露等问题,开发测试时建议注释掉!
//error_reporting(0);
//获取url
error_reporting(0);
$C_url=$_GET["url"];
$str="/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/";
//首次参数验证(是否符合url格式)
if (!preg_match($str,$C_url)){
$error_url = [
'code' => '501',
'message' => '参数错误',
'url' => 'null',
'type' => 'error',
'icpdode' => 'error',
'icporg' => 'error',
'word' => 'error',
'wordtit' => 'error',];
exit(json_encode($error_url,JSON_UNESCAPED_UNICODE))
;
}else{
header('Content-Type:application/json; charset=utf-8');
function doCurl($url, $data=array(), $header=array(), $referer='', $timeout=30){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_REFERER, $referer);
$response = curl_exec($ch);
if($error=curl_error($ch)){
die($error);
}
curl_close($ch);
return $response;
}
// 调用
$url = 'https://cgi.urlsec.qq.com/index.php?m=check&a=check&url='.$C_url;
$data = array();
// 设置IP
$header = array(
'CLIENT-IP: 192.168.1.100',
'X-FORWARDED-FOR: 192.168.1.100'
);
$referer = 'https://urlsec.qq.com/';
$response = doCurl($url, $data, $header, $referer, 5);
$data = substr($response, 1, -1);
$data = json_decode($data, true);
$url = $data['data']['results']['url'];
$type = $data['data']['results']['whitetype'];
$beian = $data['data']['results']['isDomainICPOk'];
$icpdode = $data['data']['results']['ICPSerial'];
$icporg = $data['data']['results']['Orgnization'];
$word = $data['data']['results']['Wording'];
$wordtit = $data['data']['results']['WordingTitle'];
//多if嵌套,逐一返回切确值
if ($type==3 AND $beian==1) {
$json = [
'code' => '200',
'message' => '成功',
'url' => $url,
'type' => '网址安全(付费的绿标)',
'icpdode' => $icpdode,
'icporg' => $icporg,
'word' => $word,
'wordtit' => $wordtit,];
exit(json_encode($json,JSON_UNESCAPED_UNICODE));
;}
elseif ($type==3 AND $beian==0){
$json = [
'code' => '200',
'message' => '成功',
'url' => $url,
'type' => '网址安全(付费的绿标)',
'icpdode' => '未备案',
'icporg' => '未备案',
'word' => $word,
'wordtit' => $wordtit,];
exit(json_encode($json,JSON_UNESCAPED_UNICODE));
;}
else {
if ($type==2 AND $beian==1) {
$json = [
'code' => '200',
'message' => '成功',
'url' => $url,
'type' => '报毒',
'icpdode' => $icpdode,
'icporg' => $icporg,
'word' => $word,
'wordtit' => $wordtit,];
exit(json_encode($json,JSON_UNESCAPED_UNICODE));
;}
elseif ($type==2 AND $beian==0){
$json = [
'code' => '200',
'message' => '成功',
'url' => $url,
'type' => '报毒',
'icpdode' => '未备案',
'icporg' => '未备案',
'word' => $word,
'wordtit' => $wordtit,];
exit(json_encode($json,JSON_UNESCAPED_UNICODE));
;}
else {
if ($type==1 AND $beian==1){
$json = [
'code' => '200',
'message' => '成功',
'url' => $url,
'type' => '网址未知(包括腾讯云绿标)',
'icpdode' => $icpdode,
'icporg' => $icporg,
'word' => $word,
'wordtit' => $wordtit,];
exit(json_encode($json,JSON_UNESCAPED_UNICODE));
;}
elseif ($type==1 AND $beian==0){
$json = [
'code' => '200',
'message' => '成功',
'url' => $url,
'type' => '网址未知(包括腾讯云绿标)',
'icpdode' => '未备案',
'icporg' => '未备案',
'word' => $word,
'wordtit' => $wordtit,];
exit(json_encode($json,JSON_UNESCAPED_UNICODE));
;}
else {
$json = [
'code' => '500',
'message' => '参数错误、服务器内部错误',
'url' => 'null',
'type' => 'api出现无法预料的故障',
'icpdode' => '请联系管理员',
'icporg' => 'null',
'word' => 'null',
'wordtit' => 'null',];
exit(json_encode($json,JSON_UNESCAPED_UNICODE));
;}
;}
;}
;}
?>
以上仅供参考(屎山代码)
如有疑问,欢迎在评论区讨论
源,意味着起点,是开始,是探索的动力。
————陌罗
附
件
下
载
Comments | NOTHING