function push2xzh($us,$type="realtime",$appid="",$token=""){ if(!$appid)$appid="123456"; //你的熊掌号id if (!$token)$token="tfkfsddds";//您的熊掌号token if(!is_array($urls)){ $urls[]=$us; }else{ $urls=$us; } $api = "http://data.zz.baidu.com/urls?appid={$appid}}&token={$token}&type={$type}"; $ch = curl_init(); $options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => implode(chr(10), $urls), CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), ); curl_setopt_array($ch, $options); $result = curl_exec($ch); return json_decode($result,true); }
返回的结果为数组。
自用的函数:
// push to baiduxzh function push2baiduxzh($url,$type='realtime'){ global $public_r; $jhcecms=$GLOBALS['enews']; $GLOBALS['enews']='Push2baiduxzh'; if(preg_match('//index_d+.html/i',$url))return ''; //列表分页不推 if(preg_match('//d+_d+.html/i',$url))return ''; //内容分页不推 eval($public_r['add_p2b']); if(!$p2b_sets['push2baiduxzh'])return ''; $url=str_replace(ECMS_PATH,'',$url); foreach($p2b_sets['disallow'] as $disallowpath){ if(strpos('/'.$url,$disallowpath)===0)return ''; } $domain=$p2b_sets['domainxzh']?$p2b_sets['domainxzh']:$_SERVER['HTTP_HOST']; $url=str_replace($p2b_sets['defaultIndex'],'','http://'.$domain.'/'.$url); $url=str_replace('../../','',$url); $urls[]=$url; $appid=$p2b_sets['appid']; $token=$p2b_sets['tokenxzh']; $api = "http://data.zz.baidu.com/urls?appid={$appid}}&token={$token}&type={$type}"; $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 =json_decode(curl_exec($ch),true); if($p2b_sets['insert_dolog']){ if(isset($result['error'])){ $doing='push2baiduxzh#error#'.$result['message'].'#'.$url; }else{ $doing='push2baiduxzh#success#'.$result['remain'].'#'.$url; } insert_dolog($doing); } $GLOBALS['enews']=$jhcecms; }