为Typecho添加百度收录检测,提供五个接口
修改教程
下面就是需要动手的地方了
1.在模板post.php加入(我是handsome,其他的请自行修改)
<!--百度收录-->
<li class="meta-baidu"><span class="post-icons"><i class="glyphicon glyphicon-refresh" id="baidu_icon"></i></span><span class="meta-value" id="baidu_result">加载中</span></li>
2.还是在post.php内加入(必须引入jquery)
<script>
function baidu_check(){
$.getJSON("https://cn1.api.wfblog.net/baidu.php?domain="+window.location.href,function(result){
if (result.code == 200) {
$('#baidu_icon').removeClass('glyphicon-refresh');
$('#baidu_icon').addClass('glyphicon-ok-circle');
$('#baidu_result').text('百度已收录');
}else if(result.code == 403){
$('#baidu_icon').removeClass('glyphicon-refresh');
$('#baidu_icon').addClass('glyphicon-info-sign');
$('#baidu_result').text('百度未收录');
}else{
$('#baidu_icon').removeClass('glyphicon-refresh');
$('#baidu_icon').addClass('glyphicon-remove-circle');
$('#baidu_result').text('查询收录失败');
}
});
}
baidu_check();
更多
哈哈哈为了防止我的API挂掉,所以我把API的代码也放出来,懒得搭建的小伙伴也可以使用我的鸭
<?php
/**
* Baidu
* @editer: Weifeng
* @link: https://wfblog.net
* @version: 1.0
*/
error_reporting(0);
header("Access-Control-Allow-Origin:*");
header('Content-type: application/json');
$domain = @$_GET['domain'];
if(!isset($domain) || empty($domain) || $domain==''){
$data = array(
"code" => false,
"msg" => "未传入请求参数!"
);
echo json_encode($data,JSON_UNESCAPED_UNICODE);
exit;
}
if(substr($domain, -1) == '/'){
$domain = substr($domain,0,strlen($domain)-1);
}
$data = checkBaidu($domain);
echo json_encode($data,JSON_UNESCAPED_UNICODE);
function checkBaidu($url){
$header = array(
"Host:www.baidu.com",
"Content-Type:application/x-www-form-urlencoded",//post请求
"Connection: keep-alive",
"Referer:https://www.baidu.com",
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Safari/537.36"
);
$url = 'https://www.baidu.com/s?ie=UTF-8&wd='.urlencode($url).'&usm=3&rsv_idx=2&rsv_page=1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
if(strpos($output, '没有找到') || strpos($output, '很抱歉')){
$data = array(
"code" => 403,
"msg" => "该域名暂时未被百度收录!"
);
}else{
$number = GetBetween($output,'<span class="nums_text">百度为您找到相关结果约','个</span>');
if(empty($number) || $number == 0){
$number = GetBetween($output,'<b>找到相关结果数约','个</b></p>');
if(empty($number) || $number == 0){
$data = array(
"code" => false,
"msg" => "获取百度收录失败!"
);
return $data;
}
}
$data = array(
"code" => 200,
"msg" => "该域名已被百度收录!",
"number" => str_replace(',','',$number)
);
}
return $data;
}
function GetBetween($content,$start,$end){
$r = explode($start, $content);
if (isset($r[1])){
$r = explode($end, $r[1]);
return $r[0];
}
}
?>
提供另外四个接口
https://api.baoshuo.ren/baidu_check.php (自动解析)
https://cn.api.baoshuo.ren/baidu_check.php (北京)
https://sg.api.baoshuo.ren/baidu_check.php (新加坡)
https://us.api.baoshuo.ren/baidu_check.php (美国)
http://xzh.i3geek.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,请不要用于商业用途及非法用途,否则后果自负!
3. 如果你也有好源码或者教程,可以到审核区发布,分享有金币奖励和额外收入!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,默认解压密码为"qq301.com",如遇到无法解压的请联系管理员!
资源客是一个优秀的分享资源站,本站资源均为各位友友分享而来,特殊原创会标明如有侵犯版权等可联系删除
资源客 » 为Typecho添加百度收录检测,提供五个接口
资源客 » 为Typecho添加百度收录检测,提供五个接口