<?php
defined('IN_DESTOON') or exit('Access Denied');
$time = time();
$starttime = $time - 24*3600;//24小时
$limitList=10; //限制条数
$query = "SELECt linkurl FROM {$DT_PRE}article_21 WHERe edittime > $starttime ORDER BY itemid ASC LIMIT $limitList";
//开始全部推送
$result = $db->query($query);
$urls="";
$domain="http://m.snw.com.cn/news/";//修改您的网站域名
while ($r=$db->fetch_array(($result))
{
$linkurl = $r['linkurl'];
$urls.=$domain.$linkurl.",";
}
$urls=substr($urls,0,-1);
$urls = explode(",",$urls);
//百度熊掌推送接口
$api = 'http://data.zz.baidu.com/urls?appid=1615930139655476&token=7jDdRhA8Lf7HqWva&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);
$jieguo = date('Y-m-d H:i:s',time())."返回结果:".$result."\r\n";
$numbytes = file_put_contents('file/cache/xz.txt', $jieguo); //执行记录
?>
有的教程说要在$time = time();前//引入全局变量函数require 'common.inc.php';
经测试不需要引入,有的获取移动url使用下面的这代码是无法获取的
{
$linkurl = $r['linkurl'];
//添加手机端url
$urls.="{$EXT[mobile_url]}".$linkurl.",";
}
用法:
脚本文件:将上面的代码命名为xz.inc.php 放到/api/cron路径目录
在后台-定时任务 中添加一个任务
任务名称:任意名
脚本:xz.inc.php