在网站根目录下新建php文件,文件名随意,例baiduts.php,填写网站sitemap.xml地址和百度站长的推送接口,把自定义的文件地址添加在宝塔定时任务,选择访问URL,自定义执行时间后,保存即可。
<?phpheader('Content-Type:text/html;charset=utf-8');$xmldata =file_get_contents("https://自己网站/sitemap.xml");$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'];}$api ='百度站长的推送接口';$ch = curl_init();$options = array(CURLOPT_URL => $api,CURLOPT_POST => true,CURLOPT_POSTFIELDS => implode("
",$url),CURLOPT_HTTPHEADER => array('Content-Type:text/plain'),);curl_setopt_array($ch, $options);$result =curl_exec($ch);echo $result;?>