织梦后台一键推送功能

织梦后台一键推送功能_蓝莓博客

第一步:百度站长、MIP、移动推送

织梦后台目录下(默认为dede),新建一个baidu.php文件,放入以下代码。

<?php require_once ("../include/common.inc.php"); require_once "../include/arc.partview.class.php"; require_once('../include/charset.func.php'); $limit = 2000; //百度一次性推送最多2000条记录,所以限制推送数量为2000 $query = "SELECT arch.id,types.typedir FROM dede_arctype as types inner join dede_archives as arch on types.id=arch.typeid ORDER BY pubdate DESC LIMIT $limit"; //这里dede换成你们自己的表前缀 $urls=""; $dsql->Execute('arch.id,types.typedir',$query); while($row = $dsql->GetArray('arch.id,types.typedir')) { $urls.="".str_replace("{cmspath}","",$row['typedir'])."/".$row[id].".html".","; // 换成你们自己的域名 } $urls=substr($urls,0,-1); $urls = explode(",",$urls); $api = '?site=www.dede58.com&token=********'; // 前边的api换成自己的推送 API $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.count($urls); ?>  

注意:上面有三个域名的地方,要改成自己的。

其他MIP推送、移动推送同理,多新建几个PHP,更换下域名和API推送接口即可。

第二步:熊掌号推送

熊掌号只能推送当天更新的数据,所以要代码跟上面的有点不一样,要加个时间限制。

织梦后台目录(默认为dede),新建一个xz.php文件,放入以下代码。

<?php require_once ("../include/common.inc.php"); require_once "../include/arc.partview.class.php"; require_once('../include/charset.func.php'); $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);//当天结束时间戳 $query = "SELECT arch.id,types.typedir FROM dede_arctype as types inner join dede_archives as arch on types.id=arch.typeid where pubdate<".$dayEnd." AND pubdate>".$dayBegin.""; //这里dede换成你们自己的表前缀 $urls=""; $dsql->Execute('arch.id,types.typedir',$query); while($row = $dsql->GetArray('arch.id,types.typedir')) { $urls.="".str_replace("{cmspath}","",$row['typedir'])."/".$row[id].".html".","; // 换成你们自己的域名 } $urls=substr($urls,0,-1); $urls = explode(",",$urls); $api = '?appid=****&token=***&type=realtime'; // 前边的api换成自己的推送 API $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.count($urls); ?>  
第三步:在织梦后台添加推送菜单

打开/dede/inc/inc_menu.php,大概136行下面添加刚刚新建的PHP文件

织梦后台一键推送功能_蓝莓博客

<m:item name='一键推送PC' link='baidu.php' rank='sys_MakeHtml' target='main' /> <m:item name='一键推送PC' link='xz.php' rank='sys_MakeHtml' target='main' />  
测试

显示success,则说明功能正常。

织梦后台一键推送功能_蓝莓博客

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/ee75081156e9dd3a120ea9e0640448b3.html