网站优化

网站优化

Products

当前位置:首页 > 网站优化 >

百度API推送 WellCMS网站地图API自动提交到百度

GG网络技术分享 2025-03-18 16:15 0


WellCMS是个不错的CMS程序,官方的商店里有个Sitemap的插件,是生成网站地图的,生成的地图格式仅支持txt格式。

https://www.ggplus.cn/sitemap/1.txt

https://www.ggplus.cn/sitemap/2.txt

...

https://www.ggplus.cn/sitemap/10.txt

 

Sitemap中的URL格式是:

https://www.ggplus.cn/1.html

https://www.ggplus.cn/2.html

 

官方的商店里也有个 百度主动推送 的插件,虽然是收费的,但是它不能提交历史文章,只有在新发布文章时或编辑文章时才会提交。

小编找来Wordpress的自动提交php文件,进行了一番修改,代码如下,丢进去然后开启宝塔的计划任务即可实现自动提交,并且还增加了随机抽取urls。

代码如下:[rihide]

<?php

header('Content-Type: text/html; charset=utf-8');

$html = file_get_contents("https://域名/sitemap/1.txt,https://域名/sitemap/2.txt);

$regex = '#(.+?)n#';

preg_match_all($regex,$html,$mats);

$urls = $mats[1];

// 打乱 $urls 数组的顺序

shuffle($urls);

$chunk_result = array_chunk($urls,500);

//百度收录提交

foreach($chunk_result as $k){

$urls=$k;

$api = 'http://data.zz.baidu.com/urls?site=https://域名&token=你的token';

$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 . '<br/>';

}

?>
[/rihide]

标签:

提交需求或反馈

Demand feedback