飘仙建站论坛

标题: 织梦DedeCMS发布文章后主动推送给百度(实时推送) [打印本页]

作者: 天外飘仙    时间: 2019-8-4 14:51
标题: 织梦DedeCMS发布文章后主动推送给百度(实时推送)
织梦DEDECMS发布文章后如何添加百度主动推送功能,下面来看看吧,so easy~

后台系统参数新建字段

cfg_bdtoken:百度接口
cfg_bdhost:推送域名
(, 下载次数: 73) (, 下载次数: 85) (, 下载次数: 68)

修改相关PHP文件
打开/dede/article_add.php

找到

  1. $artUrl = MakeArt($arcID,true,true,$isremote);
  2. if($artUrl=='')
  3. {
  4.   $artUrl = $cfg_phpurl."/view.php?aid=$arcID";
  5. }
复制代码

在下面加入

  1. else{
  2. $urls[]='http://'.$cfg_bdhost.''.$artUrl;  //如果网站开启了SSL,请把http改成https
  3. $api = $cfg_bdtoken;
  4. $ch = curl_init();
  5. $options =  array(
  6.     CURLOPT_URL => $api,
  7.     CURLOPT_POST => true,
  8.     CURLOPT_RETURNTRANSFER => true,
  9.     CURLOPT_POSTFIELDS => implode("\n", $urls),
  10.     CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
  11. );
  12. curl_setopt_array($ch, $options);
  13. $result = curl_exec($ch);
  14. }
复制代码

继续找到

  1. <a href='catalog_do.php?cid=$typeid&dopost=listArchives'><u>已发布文章管理</u></a>
复制代码

在下面加入

  1. <a href=''><u>百度提交返回".$result."</u></a>  
  2. &nbsp;&nbsp;
复制代码

保存。

继续操作,打开/dede/article_edit.php
找到

  1. $artUrl = MakeArt($id,true,true,$isremote);
  2.    if($artUrl=='')
  3.    {
  4.        $artUrl = $cfg_phpurl."/view.php?aid=$id";
  5.    }
复制代码

在下面加入

  1. else{
  2. $urls[]='http://'.$cfg_bdhost.''.$artUrl;  //如果网站开启了SSL,请把http改成https
  3. $api = $cfg_bdtoken;
  4. $ch = curl_init();
  5. $options =  array(
  6.     CURLOPT_URL => $api,
  7.     CURLOPT_POST => true,
  8.     CURLOPT_RETURNTRANSFER => true,
  9.     CURLOPT_POSTFIELDS => implode("\n", $urls),
  10.     CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
  11. );
  12. curl_setopt_array($ch, $options);
  13. $result = curl_exec($ch);
  14. }
复制代码

继续找到

  1. <a href='catalog_do.php?cid=$typeid&dopost=listArchives'><u>管理文章</u></a>
复制代码

在下面加入

  1. <a href=''><u>百度提交返回".$result."</u></a>  
  2. &nbsp;&nbsp;
复制代码

完成,发布文章和更新文章都实现百度主动推送了。

功能测试

(, 下载次数: 70)
如上图则推送成功。




欢迎光临 飘仙建站论坛 (https://bbs.piaoxian.net/) Powered by Discuz! X3.5