利用宝塔实现百度站长自动推送

- 新建一个 PHP 文件,复制如下代码
- 填写网站 sitemap.xml 地址和百度的推送接口(http://data.zz.baidu.com/urls?site=你的&token=你的),没token的 百度资源站长 前去获取。
把文件地址添加到宝塔定时任务,选择访问 URL,自定义执行时间后,保存即可。
001002003004005006007008009010011012013014015016017018019020021022023<?phpheader('Content-Type:text/html;charset=utf-8');$xmldata =file_get_contents("你的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_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => implode("\n",$url), CURLOPT_HTTPHEADER => array('Content-Type:text/plain'),);curl_setopt_array($ch, $options);$result =curl_exec($ch);echo $result;?>成功会返回
001{"remain": 今日剩余数,"success": 推送成功数}
正文完