织梦charset.func.php,织梦dede实现百度熊掌号API提交的方法(PHP推送)

在熊掌号改造的过程中,相信有很多SEO朋友跟我一样遇到了资源API提交的困扰,今天姜成seo就以自己的深圳seo博客所用的dedecms/' target='_blank'>织梦dede系统来跟大家说下如何利用PHP推送实现DedeCMS的百度熊掌号API提交接口链接。

熊掌号的API提交分为新增内容接口和历史内容接口两个接口。通过新增内容接口,提交站内当天新产生内容的链接。新增内容享受24小时内抓取校验、快速展现优待。仅限提交绑定站点下的内容,否则无法成功提交,配额不可累计当日有效。而通过历史内容接口,每天可提交最多500万条有价值的内容,所提交内容会进入百度搜索统一处理流程,这个过程需要一段时间来进行处理。

通过查看熊掌号API资源提交的推送示例我们了解到,熊掌号的API推送有curl、post、php、ruby 共4种方式,今天我们就以PHP为例来跟大家讲一讲如何利用PHP推送实现DedeCMS的百度熊掌号API提交接口链接。

d4ef3cace0fd7b1a2bab1d3383b0d8fd.png

PHP推送新增内容接口代码(示例):

$urls = array(

'http://www.example.com/1.html',

'http://www.example.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;

Tips:接口调用地址格式为:http://data.zz.baidu.com/urls?appid=XXXXXXXXX&token=xxxxxxxxxxxxx&type=realtime(这句代码中,appid为我们熊掌号的唯一识别ID,必须带。token为在在搜索资源平台申请的推送用的准入密钥,也必须带。而参数type为对提交内容的数据类型说明,新增内容参数为realtime。)

如果仅仅靠这段代码,需要我们将每个文章的地址都复制下来,很麻烦,利用DedeCMS系统,我们可以生成文章地址,这样就节省了不少时间。

DedeCMS熊掌号API提交之新增内容接口代码:

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".$dayBegin."";

//echo $query;

$urls="";

$dsql->Execute('arch.id,types.typedir',$query);

while($row = $dsql->GetArray('arch.id,types.typedir'))

{

$urls.="http://www.seoblogs.cn".str_replace("{cmspath}","",$row['typedir'])."/".$row[id].".html".",";

//将上边www.seoblogs.cn换成你的网址

}

$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;

?>

代码释义:

1、$query中“dede_archives”为自己数据库中存放文章的表,如果你的数据库表头做了修改,这里也要做响应修改。

2、本代码自动获取当天发布的所有文章链接,设置两个时间戳,0:0:0和23:59:59,也就是把当天这两个时间内的文章都自动提取出来,即是当天新增的内容。

c674bcc1366d4706bf0a142908e490dc.png

推送成功效果

PHP推送历史内容接口代码(示例):

$urls = array(

'http://www.example.com/1.html',

'http://www.example.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;

Tips:接口调用地址格式为:http://data.zz.baidu.com/urls?appid=XXXXXXXXXX&token=xxxxxxxxxxxxx&type=batch(这句代码中,appid为我们熊掌号的唯一识别ID,必须带。token为在在搜索资源平台申请的推送用的准入密钥,也必须带。而参数type为对提交内容的数据类型说明,新增内容参数为batch。)

DedeCMS熊掌号API提交之历史内容接口代码:

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".$dayBegin."";

//echo $query;

$urls="";

$dsql->Execute('arch.id,types.typedir',$query);

while($row = $dsql->GetArray('arch.id,types.typedir'))

{

$urls.="http://www.seoblogs.cn".str_replace("{cmspath}","",$row['typedir'])."/".$row[id].".html".",";

//将上边的www.seoblogs.cn换成你的网址

}

$urls=substr($urls,0,-1);

$urls    = explode(",",$urls);

$api = 'http://data.zz.baidu.com/urls?appid=熊掌号ID&token=密钥&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、本代码自动获取网站的所有历史文章链接,设置两个时间戳,mktime(23,59,59,$month,$day,$year)和mktime(0,0,0,7,1,2015),也就是把网站的所有历史文章都自动提取出来。

e29c6ab276157ee1fe3a5e8b0c757d29.png

推送成功效果

下载文件DedeCMS熊掌号API提交新增内容接口文件和DedeCMS熊掌号API提交历史内容接口文件,解压后,修改文件,将文件中的密钥和网址改成自己的即可,将修改后的PHP文件上传到网站根目录,浏览器中输入:你的域名/baiduxz_new.php和你的域名/baiduxz_old.php,即可看到API提交的效果。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值