织梦系统实现百度自动推送方法

2020/05/3118:22:30 1 1,777

织梦系统实现百度推送。百度已经下线熊掌号下的每日链接提交功能,上线每日“快速提交”,在dedecms系统中,可以再发布文章时候自动提交给百度。

网站自己写的文章,作为网站优化的角度,我们都希望在文章发布后的第一时间,提交给百度,进行抓取收录,等待展现机会。

织梦系统实现百度自动推送方法

来自百度搜索资源移动专区的“资源提交”功能,注意区分百度后台的资源提交下的“普通收录”功能,在我们发布文章后,可以选择手动在百度后台、程序API自动提交的两种方式,享受天级搜索展现服务,注意网站对应的每天提交数量是有限的,在织梦系统建站中,采用“API提交”的方式如下。

百度给出了4种网址推送方式,我选择php推送。

curl推送示例
post推送示例
php推送示例
ruby推送示例

百度的php示例代码:

$urls = array(
'http://www.example.com/1.html',
'http://www.example.com/2.html',
);
$api = 'http://data.zz.baidu.com/urls?appid=1590645461433&token=ff8GTo9Ho4ImR&type=realtime';
$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;

我在dedecms中的改造步骤。

1

dedecms站点后台,找到

/dede/templets/article_add.htm

/dede/templets/article_edit.htm

搜索:“简略标题”,在下面添加

<tr>
      <td width="100%" height="24" colspan="2" class="bline">
<table width="800" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="90">&nbsp;提交连接:</td>
            <td><input name="auto_submit_baidu" type="checkbox" class="np" id="auto_submit_baidu" value="1" />百度</td>
          </tr>
        </table>
  </td>
</tr>

如图

织梦系统实现百度自动推送方法

在后台发布文章是这样的

织梦系统实现百度自动推送方法

在后面添加先前在百度站长后台复制的代码,要稍微修改一些代码。

在5月15日以前的推送代码接口(重点看API接口)

    if($artUrl=='')
    {
        $artUrl = $cfg_phpurl."/view.php?aid=$arcID";
    }else{
        if($auto_submit_baidu){
               $urls = str_replace("www.domain", "m.domain", array($artUrl));
               // var_dump($urls);
               $api = 'http://data.zz.baidu.com/urls?appid=XX858487587&token=xxo9HovvvvvmR&type=realtime';
               $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;
       }
}

因为百度弃用熊掌号下的“资源提交”功能,需要修改成如下:

if($artUrl=='')
    {
        $artUrl = $cfg_phpurl."/view.php?aid=$arcID";
    }else{
        if($auto_submit_baidu){
               $urls = array('http://'.$_SERVER['HTTP_HOST'].$artUrl);
               $api = 'http://data.zz.baidu.com/urls?site=www.domain.com&token=KBD0vTSxXSMRLe4g';
               $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;
       }
}

在发布文章时候,选择推送按钮,就会自动推送给百度。

注意:百度的提交API接口可能会调整,根据百度资源后台最新示例代码实现功能。

 

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin

评论已关闭!

目前评论:1   其中:访客  0   博主  0

    • 拉吉儿 拉吉儿 0

      这写的啥呀,表示看不懂,后面的那代码写到什么文件里