织梦DedeCMS新发布文章链接定时自动推送给百度的方法

2445 阅读 2 评论 318 字

在织梦后台建立一个php文件,写入以下代码,然后运行php即可,每次运行PHP都会把10分钟内的所有文章链接推送给百度,时间可以自由调整,适合发布文章较为频繁的新闻站,代码如下:

<?php
require_once ("../include/common.inc.php");//百度推送php文件如果放在根目录,请去掉../
require_once "../include/arc.partview.class.php";//百度推送php文件如果放在根目录,请去掉../
require_once('../include/charset.func.php');//百度推送php文件如果放在根目录,请去掉../
$year = date("Y");  //年
$month = date("m");  //月
$day = date("d");  //日
$dayBegin = time()-600;//开始时间戳--当前时间减去600秒(10分钟)
$dayEnd = time();//结束时间戳--当前时间
$query = "SELECT arch.id,types.typedir FROM 【这里是数据表前缀】_arctype as types inner join 【这里是数据表前缀】_archives as arch on types.id=arch.typeid where pubdate<".$dayEnd." AND pubdate>".$dayBegin."";//从数据表中调用数据
$dsql->Execute('arch.id,types.typedir',$query);//转化
while($row = $dsql->GetArray('arch.id,types.typedir'))
{
$urls.="http://www.【这里是你的域名】.com".str_replace("{cmspath}","",$row['typedir'])."/n".$row[id].".html".",";//文章url规则为:栏目目录/n文章id.html
$apis.="<br>推送成功:http://www.【这里是你的域名】.com".str_replace("{cmspath}","",$row['typedir'])."/n".$row[id].".html"." ";//在反馈页面显示推送了哪些链接
}
$issi=substr($apis,0,-1);//反馈的链接
$urls=substr($urls,0,-1);//推送的链接
$urls=explode(",",$urls);
$api = '接口调用地址';//接口调用地址在百度站长平台获取
$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;//推送状态反馈
echo $issi;//推送链接显示
//php运行记录 生成html
$jui="  返回状态 $result";//生成记录
$a = "<br><br>访问时间:".date("Y-m-d H:i:s").$jui;
$b = "<b style='color:#ff0000;'>$a</b>";//红色加粗
$fp = @fopen("$year-$month-$day.html", "a+");//在当前目录下生成.html的文件,记录运行信息,路径可修改
fwrite($fp,$b.$issi);//文件内容为程序运行的时间
fclose($fp);
//php运行记录
?>
文章评论 (2)
  1. repostone repostone 回复TA
    为什么不是给谷歌。
    1. 运营狗 运营狗站长 回复TA
      @repostone不知道谷歌是否有推送接口,如果有接口直接替换接口就行
QQ咨询
QQ号码
979779692
微信咨询
微信二维码
在线咨询
微信咨询 QQ咨询
客服头像

截屏,微信识别二维码

微信号:itx2021

(点击微信号复制,添加好友)

微信号已复制,请打开微信添加好友!