<?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.""; //这里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换成你的网址
}
$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);
?>
百度接口返回说明:
推送成功
状态码为200,可能返回以下字段:
字段 |
是否必选 |
参数类型 |
说明 |
success |
是 |
int |
成功推送的url条数 |
remain |
是 |
int |
当天剩余的可推送url条数 |
not_same_site |
否 |
array |
由于不是本站url而未处理的url列表 |
not_valid |
否 |
array |
不合法的url列表 |
成功返回示例:
{ "remain":4999998, "success":2, "not_same_site":[], "not_valid":[] }
推送失败
状态码为4xx,返回字段有:
字段 |
是否必传 |
类型 |
说明 |
error |
是 |
int |
错误码,与状态码相同 |
message |
是 |
string |
错误描述 |