首先,在根目录,也就是wwwroot文件夹下面,创建bd.php
<?php class bd_pull_url{ /**用于百度自动提交url */ public $_17mb_prev = ''; public $db = ''; public $path = ''; public $bdapi = ''; public $cache = 'bd_cache';//缓存文件名称 public $day_num = '20';//需要清理的天数-之前的第几天需要清理 public $type =2;//决定是选择页面提交还是目录提交,1为页面,2为目录,3为全部 private $t1 = 4; private $fun_num = 1; function bd_pull_url_get($arr){ $db = $this->db; $_17mb_prev = $this->_17mb_prev; $https = $_SERVER['HTTP_HOST']; //清理20天之前的数据 $date = date('Ymd',strtotime('-'.$this->day_num.' day')); include $this->path.$this->cache.'.php';
$day_id = $bd_url_get[$date]['bd_day_id'][$https]; if($day_id['bd_aid']>0)$bd_url_get[$https]['bd_aid'] = array_slice($bd_url_get[$https]['bd_aid'],$day_id['bd_aid']); if($day_id['bd_lid']>0)$bd_url_get[$https]['bd_lid'] = array_slice($bd_url_get[$https]['bd_lid'],$day_id['bd_lid']); unset($bd_url_get[$date]);
file_put_contents($this->path.$this->cache.'.php','<?php $bd_url_get =('.var_export($bd_url_get,true).'); ?>');
//合并首页小说数据 $sort = array_merge($arr['sort'][0],$arr['sort'][1],$arr['sort'][2],$arr['sort'][3]);
$this->bd_url_get = $bd_url_get; $de = date('Ymd'); $ok_num = $bd_url_get[$de]['bd_ok_num'][$https]; if($ok_num<=0){ $this->t1 = $this->type; $this->type = 4; $r = $this->set_bd_pull_dir_page();//测试推送条数 $this->type = $this->t1; } //推送首页 //$r = $this->set_bd_pull_dir_page($sort);//执行首页推送
$bd_url_get = $this->bd_url_get; $ok_num = $bd_url_get[$de]['bd_ok_num'][$https]; //推送最近更新 if($ok_num>0){ $ok_num = $ok_num>2000?1999:$ok_num; $sql_postdate = "select articleid,articlename,author,intro,sortid,imgflag from ".$_17mb_prev."article_article where articleid NOT IN('".join("','",$bd_aid)."') order by lastupdate desc limit 0,".$ok_num; $lastupdate = $db->get_results($sql_postdate);//执行最新入库推送 $r = $this->set_bd_pull_dir_page($lastupdate);//执行最近更新推送,最后一个推送需要添加一个参数1 } //执行最新入库推送-开始 $bd_url_get = $this->bd_url_get; $bd_aid = $bd_url_get[$https]['bd_aid']; $ok_num = $bd_url_get[$de]['bd_ok_num'][$https]; //最新入库 if($ok_num>0){ $ok_num = $ok_num>2000?1999:$ok_num; $sql_postdate = "select articleid,articlename,author,intro,sortid,imgflag from ".$_17mb_prev."article_article where articleid NOT IN('".join("','",$bd_aid)."') order by postdate desc limit 0,".$ok_num; $postdate = $db->get_results($sql_postdate);//执行最新入库推送 $r = $this->set_bd_pull_dir_page($postdate,1);//执行最新入库推送-结束
$bd_url_get = $this->bd_url_get; $ok_num = $bd_url_get[$de]['bd_ok_num'][$https]; $this->fun_num++; if($ok_num>0 && $this->fun_num<=3)$this->bd_pull_url_get($arr); } } /**执行推送, * 规则:先推送首页的数据,然后是最新入库,最后是最近更新 * 2.推送过的目录不能在推,推送过的详情不可以再推,每本小说推送最新的章节, * 3.按照比例对可以推送的条数进行分配,每个权重30%,但是首页推送优先,当首页使用的条数剩余的情况下推送剩余的俩种 * */ function set_bd_pull_dir_page($arr='',$flag=''){ $db = $this->db; $_17mb_prev = $this->_17mb_prev; include $this->path.$this->cache.'.php'; $ok_num = 10; $date = date('Ymd'); $https = $_SERVER['HTTP_HOST']; $bd_url_get_date = $bd_url_get[$date]; if(isset($bd_url_get_date['bd_num'][$https]))$num = $bd_url_get_date['bd_num'][$https];//可以推送的总数 if(isset($bd_url_get_date['bd_ok_num'][$https]))$ok_num = $bd_url_get_date['bd_ok_num'][$https]; //当天剩余可以推送的总数 //if($ok_num<=0){//没有个数了就不推了 // return false; //} $main = $url_alls2 = array();$url_alls = array();
//用于提交域名-开始 if($this->type==4 || $this->type==3){ $date20 = date('Ymd',strtotime('-'.$this->day_num.' day')); if($bd_url_get['https'][$https]<=$date20 || empty($bd_url_get['https'][$https]) || $this->type==4){ $main = $url_alls = array('https://'.$https); $bd_url_get['https'][$https] = $date; $ok_num -=1; } } //以上为提交主域名-结束
if(!empty($arr)){ if($ok_num>0 ){ //获取推送的比例 if($num < 10)$num = 10; $bd_num = intval($num/2); if($flag==1){//最后一个数据的时候,获得所有条数 $bd_num = $ok_num; } $aid = array(); //获取小说的id for($i=0;$i<count($arr);$i++){ $aid[] = $arr[$i]->articleid; } //推送目录-开始 if($this->type==2 || $this->type==3){ if($bd_num>=$ok_num){ $bd_num = $ok_num; $ok_num=0; }else{ $ok_num -= $bd_num; } // 获取可以推送的目录 $bd_aid_k = array_slice(array_diff((array)$aid,(array)$bd_url_get[$https]['bd_aid']),0,$bd_num);//获取未添加过的目录, $url_alls2 = $this->get_bd_url_dir($bd_aid_k);//生成推送url $url_alls = array_merge($url_alls,(array)$url_alls2); } //推送目录-结束 //推送详情开始 if(($this->type==1 || $this->type==3)){ if($bd_num>=$ok_num){ $bd_num = $ok_num; $ok_num=0; }else{ $ok_num -= $bd_num; } //获取详细的页面 $sql = "select lastchapterid,articleid from ".$_17mb_prev."article_article where articleid IN(".join(',',$aid).")"; $article = $db->get_results($sql); $lid =array(); //获取详细页id for($s=0;$s<count($article);$s++){ $lid[$article[$s]->articleid] = $article[$s]->lastchapterid; } $bd_lid_diff = array_diff((array)$lid,(array)$bd_url_get[$https]['bd_lid']);//获取数据 $bd_lid_v = array_slice($bd_lid_diff,0,$bd_num);//获取值 $bd_lid_k = array_slice(array_keys($bd_lid_diff),0,$bd_num);//获取键 $url_lid = $this->get_bd_url_dir($bd_lid_k,$bd_lid_v);//详情页路径 $url_alls = array_merge($url_alls,$url_lid); } } }
$rou = $this->bd_pull_url_option($url_alls); if(!$rou){ echo 'error'.'<br/>'.'<br/>'; }else{ echo 'success:'.$rou['success'].'<br/>'; echo 'remain:'.$rou['remain'].'<br/>'.'<br/>'; }
if($rou){ $sunm = $rou['success'];//成功提交的数据个数 $bd_url_get_date['bd_ok_num'][$https] = $rou['remain'];//获取剩余的可以提交的条数 $total = $rou['remain']+$sunm+1;//可以使用的总条数 if($total>$bd_url_get_date['bd_num'][$https])$bd_url_get_date['bd_num'][$https] = $total; //提交目录的部分开始 if($this->type==2 || $this->type==3){ if($sunm>0){//成功提交的实际url,目录 if($main)$bd_aid_k =array_merge($main,$bd_aid_k); $anum = count((array)$bd_aid_k); if($sunm>=$anum){ $sunm -=$anum; }else{ $sunm = 0; $bd_aid_k = array_slice($bd_aid_k,0,$sunm-1); } $bd_url_get[$https]['bd_aid'] = array_merge((array)$bd_url_get[$https]['bd_aid'],(array)$bd_aid_k); } $bd_aid = $bd_url_get[$https]['bd_aid']; end($bd_aid); $bd_url_get_date['bd_day_id'][$https]['bd_aid'] = key($bd_aid);//当天的最后一个id }//结束
//开始提交详情 if($this->type==1 || $this->type==3){ $lnum = count((array)$bd_lid_v); echo '<pre>'; if($sunm>0 ){//实际提交成功的url详情 if($sunm>=$lnum){ $sunm -=$lnum; }else{ $sunm = 0; $bd_lid_v = array_slice($bd_lid_v,0,$sunm-1); } $bd_url_get[$https]['bd_lid'] = array_merge((array)$bd_url_get[$https]['bd_lid'],(array)$bd_lid_v); } $bd_lid = $bd_url_get[$https]['bd_lid']; end($bd_lid); $bd_url_get_date['bd_day_id'][$https]['bd_lid'] = key($bd_lid);//当天的最后一个id
} //提交详情成功-结束 $bd_url_get[$date] = $bd_url_get_date; $this->bd_url_get = $bd_url_get; file_put_contents($this->path.$this->cache.'.php','<?php $bd_url_get =('.var_export($bd_url_get,true).'); ?>'); return $rou; }else{ return false; } } function get_pag_(){
} //获得url路径 function get_bd_url_dir($key,$val=array()){ $arr1 = array(); for($i=0;$i<count($key);$i++){ $arr1[$i] = 'https://'.$_SERVER['HTTP_HOST'].'/'.intval($key[$i]/1000).'/'.$key[$i].'/'; if(count($val)>0){ $arr1[$i] .= $val[$i].'.html'; } } return $arr1; } //推送url到百度 function bd_pull_url_option($arr){ $urls = $arr; file_put_contents($this->path.'bd_log.txt',date('Y-m-d').':'.$_SERVER['HTTP_HOST'].':'.var_export($urls,true).PHP_EOL,FILE_APPEND); $api = $this->bdapi; $ch = curl_init(); $options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => implode("\n", $urls), CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), ); curl_setopt_array($ch, $options); $result = curl_exec($ch); var_dump($result); //$result = '{"remain":10,"success":2,"success_realtime":0,"remain_realtime":0}'; $result = json_decode($result,true);
if(isset($result['error'])){ return false; } return $result; } } ?>
然后到站点wap文件夹下面创建提交程序budusu.php
<?php require 'main.php'; require '17mb/class/sql.php'; require($_17mb_pcdir."/configs/article/sort.php"); require '../../up_data/bd.php';
$sort1 = $db->get_results($sql_sort1);
$sort2 = $db->get_results($sql_sort2);
$sort3 = $db->get_results($sql_sort3);
$sort4 = $db->get_results($sql_sort4);
$lastupdate = $db->get_results($sql_lastupdate);
$bd_pull = new bd_pull_url(); $bd_pull->_17mb_prev = $_17mb_prev;
$bd_pull->bdapi = 'http://data.zz.baidu.com/urls?site=https://m.budusu.com&token=AzRTa68xBMrPDllQ&type=daily';//设置百度推送的appid设置 $bd_pull->day_num = '20';//需要清理的天数-之前的第几天需要清理 $bd_pull->type =2;//决定是选择页面提交还是目录提交,1为页面,2为目录,3为全部
$bd_pull->db = $db; $bd_pull->path = '../../up_data/'; $bd_pull->bd_pull_url_get(array('sort' => array($sort1,$sort2,$sort3,$sort4),'lastupdate'=>$lastupdate)); $bd_pull->bdapi = 'http://data.zz.baidu.com/urls?site=https://m.budusu.com&token=AzRTa68xBMrPDllQ';//设置百度推送的appid设置 $bd_pull->bd_pull_url_get(array('sort' => array($sort1,$sort2,$sort3,$sort4),'lastupdate'=>$lastupdate));
//神马推送的appid设置 require '../../up_data/smbd.php';
$bd_pull = new sm_bd_pull_url(); $bd_pull->_17mb_prev = $_17mb_prev; $bd_pull->day_num = '20';//需要清理的天数-之前的第几天需要清理 $bd_pull->type =2;//决定是选择页面提交还是目录提交,1为页面,2为目录,3为全部 $bd_pull->db = $db; $bd_pull->path = '../../up_data/'; $bd_pull->bdapi = 'http://data.zhanzhang.sm.cn/push?site=www.budusu.com&user_name=邮件&resource_name=mip_add&token=TI_6a773c3546873dsfs516as7cb33e8835ccc'; $bd_pull->bd_pull_url_get();
$tpl->display('index.html'); ?>
php推送示例
$urls = array( 'http://www.example.com/1.html', 'http://www.example.com/2.html', ); $api = 'http://data.zz.baidu.com/urls?site=https://www.budusu.com&token=AzRTa68xBMrPDllQ'; $ch = curl_init(); $options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => implode("\n", $urls), CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), ); curl_setopt_array($ch, $options); $result = curl_exec($ch); echo $result;post推送示例
POST /urls?site=https://www.budusu.com&token=AzRTa68xBMrPDllQHTTP/1.1 User-Agent: curl/7.12.1 Host: data.zz.baidu.com Content-Type: text/plain Content-Length: 83
http://www.budusu.com/1.html http://www.budusu.com/2.html 成功返回示例: { "remain":99998, "success":2, "not_same_site":[], "not_valid":[] }curl推送示例
curl -H 'Content-Type:text/plain' --data-binary @urls.txt "http://data.zz.baidu.com/urls?site=https://www.budusu.com&token=AzRTa68xBMrPDllQ"
本文由一曲书斋提供:budusu.com
最后:如果快速收录没有资格,那么先开通一个普通收录。
使用说明
1、普通收录工具可以向百度搜索主动推送资源,缩短爬虫发现网站链接的时间,不保证收录效果。2、API提交和手动提交共享配额,每日至多提交10万条有价值的内容,sitemap提交配额不与其他方式共享,具体配额以站点页面显示数据为准,提交内容会进入百度搜索统一管理。3、仅限提交关联过主体的站点下的内容,否则无法成功提交,配额不可累计,当日有效。4、若链接存在跳转关系,请直接提交跳转后链接。如网站换域名,需提交新域名资源;进行HTTPS改造页面,请提交HTTPS资源。注意:
有两个推送的地址,第一个是快速收录,第二个是普通收录,设置完成之后,手动访问budusu.php即可完成提交。每天设置定点执行就可以。