织梦dedecms百度php主动推送代码示例,学技巧亲试绝对成功!废话不多说,直接上代码。
建议先在命名建立文件为baidutuisong.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".$dayBegin.""; //这里dede换成你们自己的表前缀
$urls="";
$dsql->Execute('arch.id,types.typedir',$query);
while($row = $dsql->GetArray('arch.id,types.typedir'))
{
$urls.="https://www.xuejiqiao.com".str_replace("{cmspath}","",$row['typedir'])."/".$row[id].".html".",";
//将上边的https://www.xuejiqiao.com换成你的网址
}
$urls=substr($urls,0,-1);
$urls = explode(",",$urls);
$api = 'http://data.zz.baidu.com/urls?site=www.xuejiqiao.com&token=ok4B5kJBPqGSWwDX&'; // 前边的site换成自己的site xxx换成自己的密钥
$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的话,大家相对应的吧密匙换成mip的url和token。