百度api推送示例php,百度最新推送2020,百度站长自动推送
PHP开发 2020-08-22编辑:深圳网站建设阅读()
百度api推送示例 php
百度api推送示例 php ,百度最新推送2020,百度站长自动推送,代码复制可用。百度后台有示例代码。他的示例代码前面加<?php 和结尾<?就行。这里分别写了百度推送所有文章。百度推送最近更新24小时内。及最新30条。以满足不同的用户需求。
<?php
在度自动推送 所有的文章
function PushUrlToBaiduAllArticle(){
$list=syDB('article')->findAll(" isshow=1 ");
$urls=[];
foreach($list as $k=>$v){
$urls[$k]='http://www.smysq.com'.html_url('article',$v);
}
$api='http://data.zz.baidu.com/urls?site=www.smysq.com&token=2dz6luI1brMrmvK4';
$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;
}
百度站长自动推送,24小时内
function PushUrlToBaiduT(){
$add_time=time()-60*60*24;
//24小时内的
$list=syDB('article')->findAll("addtime >=".$add_time." and isshow=1 ");
$urls=[];
foreach($list as $k=>$v){
$urls[$k]='http://www.smysq.com'.html_url('article',$v);
}
$api='http://data.zz.baidu.com/urls?site=www.smysq.com&token=2dz6luI1brMrmvK4';
$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;
}
百度站长自动推送 最新的30条
function PushUrlToBaiduNew(){
$list=syDB('article')->findAll(" isshow=1 ",'id desc','','30');//30为条数
$urls=[];
foreach($list as $k=>$v){
$urls[$k]='http://www.smysq.com'.html_url('article',$v);
}
$api='http://data.zz.baidu.com/urls?site=www.smysq.com&token=2dz6luI1brMrmvK4';
$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;
}
<?