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

2017-05-11 二次开发 浏览 手机预览
文章来源:http://www.imtr.cn/html/n21.html

        建立一个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运行记录
?>


原文地址:http://www.imtr.cn/html/n21.html
  • 如果你的问题还没有解决,可以点击页面右侧的“ ”,站长收到问题后会尽快回复解决方案到你的邮箱。
  • 创造始于问题,有了问题才会思考,有了思考,才有解决问题的方法,才有找到独立思路的可能。 —— 陶行知