用post推送文章至百度

网站根目录下建 post.php文件 并加入代码

<?
header('Content-Type:text/html;charset=utf-8');
$xmldata =file_get_contents("https://xxx/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;...

代码中推送地址及sitemap地址自行修改

本文由 湖畔网 作者:湖畔网 发表,其版权均为 湖畔网 所有,文章内容系作者个人观点,不代表 湖畔网 对观点赞同或支持。如需转载,请注明文章来源。

发表回复


网站已运行: