织梦百度php主动推送代码示例,亲试绝对成功!废话不多说,直接上代码。
建议先在命名建立文件为baidu.php,代码如下自己修改
<?phprequire_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<".$dayEnd." AND pubdate>".$dayBegin.""; //这里dede换成你们自己的表前缀$urls="";$dsql->Execute('arch.id,types.typedir',$query);while($row = $dsql->GetArray('arch.id,types.typedir')){ $urls.="www.zhishitu.com".str_replace("{cmspath}","",$row['typedir'])."/".$row[id].".html".","; //将上边的http://www.zhishitu.com换成你的网址}$urls=substr($urls,0,-1);$urls = explode(",",$urls);$api = 'http://data.zz.baidu.com/urls?site=www.zhishitu.com&token=VtDwNoCne61ZfPRzh'; // 前边的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);?>
然后保存为baidu.php,直接上传到网站的根目录,直接在浏览器输入www.zhishitu.com/baidu.php(网址改成自己的) 就能看到主动推送成功!
其他示例代码(收藏备用):
public function pushall_m(){ $this->check_token(); $sql="select * from 表名字 where 条件; $result=$this->db->query($sql); $sites=$result->result_array(); foreach($sites as $k=>$v){ $table=get_sites_table_name($v['id']); $sql="select * from ".$table." where 条件 order by id desc limit 50"; $result=$this->db->query($sql); $result=$result->result_array(); $urls = array(); foreach ( $result as $v1){ $urls[]="http://www.zhishitu.com".get_show_url($v1); } $token=$v['zhanzhang_tijiao_code']; if(!$token){ echo "站长提交key is null"; continue; } $s='www.zhishitu.com'; $api="http://data.zz.baidu.com/urls?site=".$s."&token=".$token; $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; }}