DEDECMS百度天级收录

首先在项目根目录建一个api文件夹

DEDECMS百度天级收录_第1张图片

require_once ("../include/common.inc.php");
require_once ("../include/arc.partview.class.php");
require_once('../include/charset.func.php');
require_once('../include/helpers/cache.helper.php');
$nid=0;
$today = strtotime(date("Y-m-d"),time());//只显示年月日,time()是获得当前时间的时间戳
//从缓存中取数据
if(GetCache('commons','baidudaypushnewsid')){
    $nid = GetCache('commons',"baidudaypushnewsid");
}
//$where_news = " and pubdate>$today and arch.id >$nid order by arch.id desc";
//从数据库中取数据
$query = "SELECT arch.id,types.tempindex FROM #@__arctype as types inner join #@__archives as arch on types.id=arch.typeid where templist like '%article%' and pubdate>$today and arch.id >$nid order by arch.id desc";

$dsql->Execute('arch.id,types.tempindex',$query);
$num=1;
while($row = $dsql->GetArray('arch.id,types.tempindex')){
     if(strpos($row['tempindex'],'article') !== false){ 
            $urls[] = "https://m.ucbug.cc/news/".$row[id].".html".",";
    }else{
            $urls[] ="https://m.ucbug.cc/soft/".$row[id].".html".",";
    }
    if($num==1){
        SetCache('commons',"baidudaypushnewsid",$row['id']);
    }
    $num++;      
}
//百度天级推送api
$api = 'http://data.zz.baidu.com/urls?appid=xxxxx&token=xxxx&type=realtime'; // 前边的熊掌号ID和密钥换成自己的
$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;
?>

测试:http://www.xxx.com/api/baidudaypush.php

亲测有效!!

你可能感兴趣的:(php)