前言

昨天用公司的企业站发布文章后,想看看之前的网站收录了没有,但是又得通过第三方工具查询有点麻烦,看到crm系统的插件还有一个百度收录检测的,我把代码修改了一下,经过测试web页面通用,可以做成php插件

html代码部分

<a id="czmz_baidu" rel="external nofollow" target="_blank"></a>

$(function () {
    $.getJSON('https://www.czmz.top/usr/query.php?url='+window.location.href, function(json, textStatus) {
        if (json.state == 1) {
            $('#czmz_baidu').html('百度已收录');
            $("#czmz_baidu").attr('href','https://www.baidu.com/s?wd='+document.title);         }else{
            $('#czmz_baidu').html('百度暂未收录');
            $('#czmz_baidu').css('color','red');
            $('#czmz_baidu').attr('href','http://zhanzhang.baidu.com/sitesubmit/index?sitename='+window.location.href);
            var bp = document.createElement('script');
            var curProtocol = window.location.protocol.split(':')[0];
            if (curProtocol === 'https') {bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';} 
            else {bp.src = 'http://push.zhanzhang.baidu.com/push.js';}
            var s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(bp, s);
        }
    });
});

query接口搭建

<?php
/**
 * 百度Site查询接口
 * code    200->正常;201->没有请求参数
 * state   1->收录;0->未收录
 */
header("Access-Control-Allow-Origin:*");
header('Content-type: application/json');
if(!isset($_GET['url'])||empty($_GET['url'])||$_GET['url']==''){
    echo json_encode(array('code'=>'201','msg'=>'请填写请求参数'));
    exit();
}
// 请求地址www.czmz.cn
$url = $_GET['url'];
// 百度搜索地址http://www.baidu.com/s?wd=site:czmz.top
$baidu='http://www.baidu.com/s?wd='.$url;
 
$curl=curl_init();
curl_setopt($curl,CURLOPT_URL,$baidu);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,false);curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
$rs=curl_exec($curl);
curl_close($curl);
 
$str = preg_match_all('/很抱歉,没有找到与/',$rs,$baidu);
 
if(!empty($str)){
    // 无以下是网页中包含信息
    echo json_encode(array('code'=>'200','url'=>$url,'state'=>'0'));
}else{
    // 有以下是网页中包含信息
    $str = preg_match_all('/<font class="c-gray">没有找到该URL。您可以直接访问&nbsp;<\/font>/',$rs,$baidu);
    if($str){
        echo json_encode(array('code'=>'200','url'=>$url,'state'=>'0'));
    }else{
        echo json_encode(array('code'=>'200','url'=>$url,'state'=>'1'));
    }
    
}
最后修改:2022 年 11 月 17 日
如果觉得我的文章对你有用,请随意赞赏