熊掌號的API提交分為新增內容接口和歷史內容接口兩個接口。通過新增內容接口,提交站內 當天新產生內容的鏈接。新增內容享受24小時內抓取校驗、快速展現優待。僅限提交綁定站點下的內容,否則無法成功提交,配額不可累計,當日有效。而通過歷史內容接口,每天可提交最多500萬條有價值的內容,所提交內容會進入百度搜索統一處理流程,這個過程需要一段時間。
一、PHP推送新增內容接口代碼為:
$urls = array( 'http://www.xiuzhanwang.com/1.html', 'http://www.xiuzhanwang.com/2.html', ); $api = 'http://data.zz.baidu.com/urls?appid=XXXXXXXXX&token=xxxxxxxxxxxxx&type=realtime'; $ch = curl_init(); $options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => implode(" ", $urls), CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), ); curl_setopt_array($ch, $options); $result = curl_exec($ch); echo $result; |
DedeCMS熊掌號API提交之新增內容接口代碼:
<?php require_once ("include/common.inc.php"); require_once "include/arc.partview.class.php"; require_once('include/charset.func.php');
$year = date("Y"); $month = date("m"); $day = date("d"); $dayBegin = mktime(0,0,0,$month,$day,$year);//當天開始時間戳 $dayEnd = mktime(23,59,59,$month,$day,$year);//當天結束時間戳
$query = "SELECT arch.id,types.typedir FROM dede_arctype as types inner join dede_archives as arch on types.id=arch.typeid where pubdate<".$dayEnd." AND pubdate>".$dayBegin.""; //echo $query;
$urls="";
$dsql->Execute('arch.id,types.typedir',$query); while($row = $dsql->GetArray('arch.id,types.typedir')) { $urls.="https://m.xiuzhanwang.com".str_replace("{cmspath}","",$row['typedir'])."/".$row[id].".html".","; //將上邊m.xiuzhanwang.com換成你的網址 } $urls=substr($urls,0,-1); $urls = explode(",",$urls);
$api = 'http://data.zz.baidu.com/urls?appid=熊掌號ID&token=密鑰&type=realtime'; // 前邊的熊掌號ID和密鑰換成自己的 $ch = curl_init(); $options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => implode(" ", $urls), CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), ); curl_setopt_array($ch, $options); $result = curl_exec($ch); echo $result; ?> |
二、PHP推送歷史內容接口代碼為
$urls = array( 'http://www.xiuzhanwang.com/1.html', 'http://www.xiuzhanwang.com/2.html', ); $api = 'http://data.zz.baidu.com/urls?appid=XXXXXXXXXX&token=xxxxxxxxxxxxx&type=batch'; $ch = curl_init(); $options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => implode(" ", $urls), CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), ); curl_setopt_array($ch, $options); $result = curl_exec($ch); echo $result; |
DedeCMS熊掌號API提交之歷史內容接口代碼:
<?php require_once ("include/common.inc.php"); require_once "include/arc.partview.class.php"; require_once('include/charset.func.php');
$year = date("Y"); $month = date("m"); $day = date("d"); $dayBegin = mktime(0,0,0,7,1,2015);//網站開始運行時間戳 $dayEnd = mktime(23,59,59,$month,$day,$year);//當天結束時間戳
$query = "SELECT arch.id,types.typedir FROM dede_arctype as types inner join dede_archives as arch on types.id=arch.typeid where pubdate<".$dayEnd." AND pubdate>".$dayBegin.""; //echo $query;
$urls="";
$dsql->Execute('arch.id,types.typedir',$query); while($row = $dsql->GetArray('arch.id,types.typedir')) { $urls.="https://m.xiuzhanwang.com".str_replace("{cmspath}","",$row['typedir'])."/".$row[id].".html".","; //將上邊的https://m.xiuzhanwang.com換成你的網址 } $urls=substr($urls,0,-1); $urls = explode(",",$urls);
$api = 'http://data.zz.baidu.com/urls?appid=XXXXXXXXXX&token=xxxxxxxxxxxxx&type=batch';// 前邊的熊掌號ID和密鑰換成自己 $ch = curl_init(); $options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => implode(" ", $urls), CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), ); curl_setopt_array($ch, $options); $result = curl_exec($ch); echo $result; ?> |
代碼釋義:
1、$query中“dede_archives”為自己數據庫中存放文章的表,如果你的數據庫表頭做了修改,這里也要做相應修改。
2、本代碼自動獲取當天發布的所有文章鏈接,設置兩個時間戳,0:0:0和23:59:59,也就是把當天這兩個時間內的文章都自動提取出來,即是當天新增內容內容。
3、$api=http://data.zz.baidu.com/urls?appid=熊掌號ID&token=密鑰&type=realtime,請登錄您的賬號查看接口調用地址。
下載文件DedeCMS熊掌號API提交新增內容接口文件和DedeCMS熊掌號API提交歷史內容接口文件,解壓后,修改文件,將文件中的密鑰和網址改成自己的即可,將修改后的PHP文件上傳到網站根目錄,瀏覽器中輸入:你的域名/baiduxz_new.php和你的域名/baiduxz_old.php,即可看到API提交的效果。
網盤下載:https://pan.baidu.com/s/1unqgztIpc9CoU7D2voNa5w 提取碼: mjuz
新聞熱點
疑難解答