在站點(diǎn)根目錄新建一個(gè)PHP文件,例如:baidu.php,并復(fù)制下方代碼添加到baidu.php文件中。
注意:兩處需要修改的博主都已經(jīng)在末尾添加了注釋?zhuān)浀眯薷臑樽约旱模缓蟊4妗?/span>
<?php
header('Content-Type:text/html;charset=utf-8');
/**?只需修改這里面的兩個(gè)鏈接?**/
$xml_url?=?"https://www.dedesos.com/sitemap.xml";?//?這里修改你站點(diǎn)的xml地圖鏈接
$baidu_api?=?'http://data.zz.baidu.com/urls?site=https://www.dedesos.com&token=123456789';//?這里修改為你在百度站長(zhǎng)獲取到的推送接口
/***只需修改這里面的兩個(gè)鏈接**/
$xmldata?=file_get_contents($xml_url);
$xmlstring?=?simplexml_load_string($xmldata,'SimpleXMLElement',LIBXML_NOCDATA);
$value_array?=?json_decode(json_encode($xmlstring),true);
$url?=?[];
for?($i?=0;$i?<?count($value_array['url']);$i++){
????//?echo?$value_array['url'][$i]['loc']."<br/>";
????$url[]=?$value_array['url'][$i]['loc'];
}
//百度推送接口一次只支持推送2000條數(shù)據(jù),所以超過(guò)2000條的話需要分組推送
$url_group?=?array_chunk($url,2000);
$count=count($url_group);
for($i=0;$i<$count;$i++){
????$ch?=?curl_init();
????$options?=?array(
???????CURLOPT_URL?=>?$baidu_api,
???????CURLOPT_POST?=>?true,
???????CURLOPT_RETURNTRANSFER?=>?true,
???????CURLOPT_POSTFIELDS?=>?implode("\n",$url_group[$i]),
???????CURLOPT_HTTPHEADER?=>?array('Content-Type:text/plain'),
????);
????curl_setopt_array($ch,?$options);
????$result?=curl_exec($ch);
????curl_close($ch);
????echo?$result;
}
?>
?
把文件地址添加到寶塔定時(shí)任務(wù)