DedeCMS5.7百度主動(dòng)推送PHP代碼,如果,你還是不明白,那。。。。只能幫你到這里了…
這是干貨,懂點(diǎn)代碼的可以自己延伸(保存為任意php文件,放到plus目錄下,訪問(wèn)看下結(jié)果?)。另外,避免手動(dòng)提交的麻煩,可以服務(wù)器端設(shè)置個(gè)時(shí)間每天自動(dòng)執(zhí)行。
<?php
require_once(dirname(__FILE__).'/../include/common.inc.php');
require_once(DEDEINC."/channelunit.class.php");
$whereSql = '';
//設(shè)置推送時(shí)間 每天有指定配額
$year = date("Y");
$month = date("m");
$day = date("d");
$dayBegin = mktime(0,0,0,$month,$day,$year);//當(dāng)天開(kāi)始時(shí)間戳
$dayEnd = mktime(23,59,59,$month,$day,$year);//當(dāng)天結(jié)束時(shí)間戳
$whereSql = "where arc.pubdate<".$dayEnd." AND arc.pubdate>".$dayBegin;
$query = "SELECT arc.*,tp.* FROM `2ky_archives` arc
LEFT JOIN `2ky_arctype` tp ON arc.typeid=tp.id
$whereSql
ORDER BY arc.id DESC";
//下面網(wǎng)址換成自己的網(wǎng)站
$urls = "";
$dsql->SetQuery($query);
$dsql->Execute();
while($row = $dsql->GetArray())
{
$urls .= "http://www.dedecms51.com".GetFileUrl($row['id'],$row['typeid'],$row['senddate'],$row['title'],$row['ismake'],
$row['arcrank'],$row['namerule'],$row['typedir'],$row['money'],$row['filename'],$row['moresite'],$row['siteurl'],$row['sitepath']).",";
}
$urls = substr($urls,0,-1);
$urls = explode(",",$urls);
//api url換成自己的,站長(zhǎng)工具里有
$api = 'http://data.zz.baidu.com/urls?site=www.dedecms51.com&token=uUGps6ZBwuEYk0LW';
$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;
?>