<?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);//當(dāng)天開始時(shí)間戳
$dayEnd = mktime(23,59,59,$month,$day,$year);//當(dāng)天結(jié)束時(shí)間戳
$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.""; //這里dede換成你們自己的表前綴
$urls="";
$dsql->Execute('arch.id,types.typedir',$query);
while($row = $dsql->GetArray('arch.id,types.typedir'))
{
$urls.="http://bnxb.com".str_replace("{cmspath}","",$row['typedir'])."/".$row[id].".html".",";
//將上邊的http://bnxb.com換成你的網(wǎng)址
}
$urls=substr($urls,0,-1);
$urls = explode(",",$urls);
$api = 'http://data.zz.baidu.com/urls?site=bnxb.com&token=xxxxx'; // 前邊的site換成自己的site xxx換成自己的密鑰
$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.count($urls);
?>
百度接口返回說明:
推送成功
狀態(tài)碼為200,可能返回以下字段:
字段 |
是否必選 |
參數(shù)類型 |
說明 |
success |
是 |
int |
成功推送的url條數(shù) |
remain |
是 |
int |
當(dāng)天剩余的可推送url條數(shù) |
not_same_site |
否 |
array |
由于不是本站url而未處理的url列表 |
not_valid |
否 |
array |
不合法的url列表 |
成功返回示例:
{ "remain":4999998, "success":2, "not_same_site":[], "not_valid":[] }
推送失敗
狀態(tài)碼為4xx,返回字段有:
字段 |
是否必傳 |
類型 |
說明 |
error |
是 |
int |
錯(cuò)誤碼,與狀態(tài)碼相同 |
message |
是 |
string |
錯(cuò)誤描述 |