海洋CMS 熊掌号 历史数据推送

海洋CMS 熊掌号 历史数据推送

正文内容:

海洋CMS 熊掌号 历史数据推送

该部分和最新数据推送类似,可以先参考链接 http://www.zhwb9190.com/html/article/index64.html

1、新建php文件,如baiduxzh_history.php,复制以下内容:

<?php


require_once("include/common.php");


require_once("include/main.class.php");


require_once("data/config.cache.inc.php");

//设置每次推送的条数


$tnum = 30;


$pagesize=$tnum;


$wheresql = "where v_xz is null";


$trow = $dsql->GetOne("Select count(*) as dd From `sea_news` $wheresql");


$totalnum = $trow['dd'];


//当总页数小于每页数目的时候,替换pagesize


if($totalnum<$pagesize)


$pagesize = $totalnum;


if(empty($totalpage)) $totalpage=ceil($totalnum/$pagesize);


if($totalnum==0 || $page>$totalpage || $remain==0){


/*---------------------------如果依然想重复推送的朋友,你可以把下面三行代码给注释掉。------------------------------*/


echo "恭喜,已推送所有内容页!";


echo "<br>暂停3秒后继续推送<script language=\"javascript\">setTimeout(\"baiduxz();\",3000);function baiduxz(){location.href='?remain=1';}</script></div>";


return;


/*---------------------------如果依然想重复推送的朋友,你可以把上面三行代码给注释掉。------------------------------*/




/*---------------------------如果依然想重复推送的朋友,你可以把下面三行代码注释给取消掉。-------------------------*/


//$query = "Update `sea_data` set v_push=0";


//$dsql->ExecuteNoneQuery($query);


//$pagesize = $tnum;


/*---------------------------如果依然想重复推送的朋友,你可以把上面三行代码注释给取消掉。-------------------------*/


}


$dsql->SetQuery("Select n_id From `sea_news` $wheresql order by n_id desc limit 0,$pagesize");


$dsql->Execute('news_list');


$plink ="";


$urls  = array();


$ids  = array();


$result ="{}";


while($row=$dsql->GetObject('news_list'))


{


$n_id = $row->n_id;


/*-----------------------------------------------------------------------------------------------------------*/


/*通过v_id来拼接内容页的地址,动态、伪静态、静态的内容页地址规律都不一样,请大家自行修改。$cfg_basehost代表你的域名*/


/*!!!!!!!!注意这里暂不支持已电影拼音做内容页地址的链接推送!!!!!!!!!!*/


/*-----------------------------------------------------------------------------------------------------------*/


$plink = $cfg_basehost."/html/article/index".$n_id.".html"; //来源页面网址


array_push($urls ,$plink);


array_push($ids ,$n_id);


@ob_flush();


@flush();


}


//百度熊掌号推送API地址,请各自去百度站长平台查看自己的token


$api = 'http://data.zz.baidu.com/urls?appid=1610457536810690&token=16lwIn8boNeOd0wh&type=batch';

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

$result_json = json_decode($result, true);



//对ids数组循环,提示推送成功id,更新对应id的v_push=1


foreach ($ids as $nid){ 

      $query = "Update `sea_news` set v_xz=1 where n_id='$nid'";

  $dsql->ExecuteNoneQuery($query);

  echo $result ."已成功推送URL:".$cfg_basehost."/html/article/index".$nid.".html";

  echo '<br />';

    } 

$remaincount = $result_json["remain"];

echo "<br>暂停3秒后继续推送<script language=\"javascript\">setTimeout(\"baiduxz_history();\",3000);function baiduxz_history(){location.href='?remain=".$remaincount."';}</script></div>";




?>

2、上传PHP文件到服务器根目录,直接浏览器输入: http://你的域名/baiduxzh_history.php


评论加载中..