海洋CMS 熊掌号 新增内容接口推送

海洋CMS 熊掌号 新增内容接口推送方法

正文内容:

海洋CMS 熊掌号 新增内容接口推送方法

对于无编程基础的人来说,只需要复制过去直接使用就可以

下边详述步骤,并粘贴代码:

1、在数据库表sea_data中增加字段v_xz,栏位类型为int




2、新建PHP文件baiduxzh.php,内容为:

<?php


require_once("include/common.php");


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


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

//设置每次推送的条数


$tnum = 10;  //默认是每次推送10条


$pagesize=$tnum;


$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);//当天结束时间戳


$wheresql = "where v_xz is null and v_addtime BETWEEN $dayBegin AND $dayEnd ";


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


$totalnum = $trow['dd'];


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


if($totalnum<$pagesize)


$pagesize = $totalnum;


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


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


$dsql->Execute('video_list');


$plink ="";


$urls = array();


$ids = array();


$result ="{}";


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


{


$v_id = $row->v_id;


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


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


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


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


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


array_push($urls ,$plink);


array_push($ids ,$v_id);


@ob_flush();


@flush();


}


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


$api = 'http://data.zz.baidu.com/urls?appid=1610457536810690&token=16lwIn8boNeOd0wh&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);

$result_json = json_decode($result, true);



foreach ($ids as $vid){

$query = "Update `sea_data` set v_xz=1 where v_id='$vid'";

$dsql->ExecuteNoneQuery($query);

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

echo '<br />';

}

?>

3、将该PHP文件上传至你的根目录,你的域名/baiduxzh.php 访问即可

如对您有帮助,请收藏关注本站维和社影视


评论加载中..