设置定时任务,

/php根目录/php/bin/php /网站根目录/api/cron/baidu.php

baidu.php文件内容,


//主动推送24小时内最新链接列表至百度

//执行: /php根目录/php/bin/php /网站根目录/api/cron/baidu.php

<?php

require ‘../../common.inc.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;

?>

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。