" />

DedeCMS5.7百度主动推送(非实时)

shape
shape
shape
shape
shape
shape
shape
shape
DedeCMS5.7百度主动推送(非实时)缩略图

dedecms5.7百度主动推送php代码,如果,你还是不明白,那。。。。只能帮你到这里了…

这是干货,懂点代码的可以自己延伸(保存为任意php文件,放到plus目录下,访问看下结果?)。另外,避免手动提交的麻烦,可以服务器端设置个时间每天自动执行。

DedeCMS5.7百度主动推送(非实时)插图

  1. require_once(dirname(__FILE__).'/../include/common.inc.php');
  2. require_once(DEDEINC."/channelunit.class.php");
  3. $whereSql = '';
  4. //设置推送时间 每天有指定配额
  5. $year = date("Y");
  6. $month = date("m");
  7. $day = date("d");
  8. $dayBegin = mktime(0,0,0,$month,$day,$year);//当天开始时间戳
  9. $dayEnd = mktime(23,59,59,$month,$day,$year);//当天结束时间戳
  10. $whereSql = "where arc.pubdate<".$dayEnd." AND arc.pubdate>".$dayBegin;
  11. $query = "SELECT arc.*,tp.* FROM `2ky_archives` arc
  12. LEFT JOIN `2ky_arctype` tp ON arc.typeid=tp.id
  13. $whereSql
  14. ORDER BY arc.id DESC";
  15. //下面网址换成自己的网站
  16. $urls = "";
  17. $dsql->SetQuery($query);
  18. $dsql->Execute();
  19. while($row = $dsql->GetArray())
  20. {
  21. $urls .= "http://www.2ky.cn".GetFileUrl($row['id'],$row['typeid'],$row['senddate'],$row['title'],$row['ismake'],
  22. $row['arcrank'],$row['namerule'],$row['typedir'],$row['money'],$row['filename'],$row['moresite'],$row['siteurl'],$row['sitepath']).",";
  23. }
  24. $urls = substr($urls,0,-1);
  25. $urls = explode(",",$urls);
  26. //api url换成自己的,站长工具里有
  27. $api = 'http://data.zz.baidu.com/urls?site=www.2ky.cn&token=uUGps6ZBwuEYk0LW';
  28. $ch = curl_init();
  29. $options = array(
  30. CURLOPT_URL => $api,
  31. CURLOPT_POST => true,
  32. CURLOPT_RETURNTRANSFER => true,
  33. CURLOPT_POSTFIELDS => implode("n", $urls),
  34. CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
  35. );
  36. curl_setopt_array($ch, $options);
  37. $result = curl_exec($ch);
  38. echo $result;
  39. ?>

发表评论