Pbootcms百度推送插件:定时全自动推送源码免费下载
Pbootcms免费插件下载:轻松实现百度推送定时发布,可自定义推送时间及间隔,自由设定百度推送计划
前言:
在使用PbootCMS的小伙伴应该都知道,在后台配置后百度Token后,在文章内容列表中通过勾选对应的文章,就能手动的向百度搜索主动推送资源,缩短爬虫发现网站链接的时间。
但是用过的都知道,这种推送方式只能手动,非常麻烦,那有没有更好的方法呢?答案是有的,而且不少。
在看到本文前,我想你应该已经在网上找了好久也会花了不少时间,在网上确实已经有不少类似实现自动或定时向百度推送文章的方法,但大都都是诸如:通过文章新增修改时自动推送、通过宝塔面板的计划任务定时推送,甚至所谓的百度自动推送收费插件......
但我想,你之前所看到的那些文章或教程都没有完美的解决你想解决的问题,有的要收费,有的不好用,有的不能用。
【划重点】
本文将介绍免费、好用的能实现全自动、定时自动向百度推送资源的方法(并附上源码下载链接)!
后面增加了一篇《Pbootcms必应推送插件源码免费下载: 加速收录,多倍流量助力SEO优化》,需要的可以点击标题去查看下载。
另外,本插件源码只修改“ExtLabelController.php”一个文件,并且PbootCMS更新时不会更新或覆盖该文件,再也不用担心手滑更新系统后功能失败了!!!
【Pbootcms百度推送功能实现教程】
第一步:登陆PbootCMS后台,在”全局配置-->配置参数-->百度接口-->普通收录token“中填写你从百度站长平台获取的Token并提交;

第二步:打开”appshomecontrollerExtLabelController.php“
1、找到 ”use coreasicController;“,在下面增加一行:
use appdminmodelsystemConfigModel;
2、找到”class ExtLabelController“,将其修改为”class ExtLabelController extends Controller“
3、找到”protected $content;“,在下面增加代码:
private $model;
public function __construct()
{
$this->model = new ConfigModel();
}4、找到方法”test()“:
// 测试扩展单个标签
public function test()
{
$this->content = str_replace('{pboot:userip}', get_user_ip(), $this->content);
}5、在”test(***){***}“后面增加代码:
public function auto_tool()
{
$data = $this->model->getConfig();
if (array_key_exists('expire_time',$data)) {
$expire_time = $data["expire_time"];
if (! $expire_time) {
$expire_time = get_datetime(time() -60); // 如果字段存在,但值为空时 expire_time=当前时间-60s
$this->model->modValue("expire_time", $expire_time);
}
if ($expire_time && strcmp($expire_time, get_datetime(time())) < 0) {
ignore_user_abort(true);
set_time_limit(7200);
ob_start();
ob_end_flush();
flush();
$rs1 = $this->post_baidu();
if ($rs1) {
$expire_time = get_datetime(time() + 60 * 60 * 24); // 下一次执行时间
$this->model->modValue("expire_time", $expire_time);
return 'console.warn("百度推送结果:'.$rs1;
}
} else {
return 'console.warn("时间未到,下次执行时间:'.$expire_time.'");';
}
} else {
$expire_time = get_datetime(time() - 60 * 60 * 24); // 初始化执行时间
$data = array(
'name' => "expire_time",
'value' => $expire_time,
'type' => 2,
'sorting' => 255,
'description' => ''
);
$this->model->addConfig($data); //增加配置字段
}
}
//百度推送
public function post_baidu()
{
$domain = get_http_url();
if (!$token = $this->config('baidu_zz_token')) {
alert_back('请先到系统配置中填写百度普通收录推送token值!');
}
if (!$sitemap_data = file_get_contents("$domain/sitemap.txt")) {
alert_back('获取站点sitemap.txt失败,请检查!');
}
$api = "http://data.zz.baidu.com/urls?site=$domain&token=$token";
$result = $this->request($api, $sitemap_data, "baidu");
if (isset($result->error)) {
alert_back('百度普通收录推送发生错误:' . $result->message);
} elseif (isset($result->success)) {
return '成功推送' . $result->success . '条,今天剩余可推送' . $result->remain . '条数!';
} else {
return '发生未知错误!';
}
}
// POST请求
function request($api, $urls, $type_)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
if ($type_ == "baidu") {
curl_setopt($ch, CURLOPT_POSTFIELDS, $urls);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));
} else {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($urls));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
}
$result = curl_exec($ch);
return json_decode($result);
}第三步:在前端公共模板(一般是“footer.html”)底部添加下面代码:
<!--执行自动任务--> <script src='/?p=/ExtLabel/auto_tool' async='async'></script>
至此,整个修改就结束了,最后到网站页面F12进入开发人员控制台,刷新页面就能查看到自动提交结果!
