php定时进行百度推送的代码
虽然现在百度主动推送几乎全无所用,可是聊胜于无,php的推送代码可以加到自己的泛目录里面去。代码还是老代码,宝塔定时任务访问即可触发推送。温馨提示:下方代码修改一下token,并根据你都域名的推送额度自行设置宝塔定时任务访问间隔即可。以上只是部份演示图片,详细可以付费购买。 <?php
// ts.php?dm=www.ccooc.cn&token=oeD4zloWmpFF1sXN
// 1天1440分钟 3分钟1次 一天480次
$server_name = @$_GET['dm'];
$token = @$_GET['token'];
$time = @date('Ymd');
// function rand_str($count = 5)
// {
// $range_array = array_merge(range(0, 9), range('A', 'Z'));
// $str = '';
// foreach ( array_rand($range_array, $count) as $value)
// {
// $str .= $range_array[$value];
// }
// return $str;
// }
function rand_str($length = 5)
{
$str = '';
$strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
$max = strlen($strPol)-1;
for($i = 0; $i < $length; $i++)
{
$str .=$strPol;
}
return $str;
}
$count = 50;
$urls = array();
for ($i = 0; $i < $count; $i++)
{
$urls[] = "http://{$server_name}/{$time}/".rand_str().rand_str().'.html';
}
$api = "http://data.zz.baidu.com/urls?site={$server_name}&token={$token}&type=mip";
$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 "mip推送",$result;
?>
页:
[1]