文件大小:0.1M
设置定时任务,
/php根目录/php/bin/php /网站根目录/api/cron/baidu.php
baidu.php文件内容,
//主动推送24小时内最新链接列表至百度 //执行: /php根目录/php/bin/php /网站根目录/api/cron/baidu.php
<?php
$time = time(); $starttime = $time - 24*3600;//24小时 $query = "SELECt linkurl FROM {$DT_PRE}sell_5 WHERe edittime > $starttime ORDER BY itemid ASC"; $result = $db->query($query); $urls=""; while ($r=$db->fetch_array(($result))) { $linkurl = $r['linkurl']; //修改域名 $urls.="https://域名/sell/".$linkurl.","; } $urls=substr($urls,0,-1); $urls = explode(",",$urls); //修改下一行 $api = 'https://data.zz.baidu.com/urls?site=域名&token=XXXXXXXXXXXXXXXX'; $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; ?> |