<?php namespace Org\Util;class Caiji{public $randip;public $timeout;public $user_agent;public $referer;public $proxy;public $proxy_mode;function __construct($xzv_28=null){if($xzv_28){if(strexists($xzv_28,'api##')){list($xzv_18,$xzv_28)=explode('##',$xzv_28);$this->proxy=$xzv_28;$this->proxy_mode='api';}else{$xzv_31=explode('//',$xzv_28);$xzv_31=explode(':',$xzv_31[1]);$this->randip=$xzv_31[0];$this->proxy=$xzv_28;}}else{$this->randip=rand(13,255).'.'.rand(13,255).'.'.rand(13,255).'.'.rand(13,255);}$this->timeout=8;$this->user_agent='Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)';$this->referer='https://www.baidu.com/s?wd=%E7%99%BE%E5%BA%A6&rsv_spt=1&rsv_iqid=0xe5a39f3b0003c303&issp=1&f=8&rsv_bp=0&rsv_idx=2&ie=utf-8&tn=baiduhome_pg&rsv_enter=1&rsv_sug3=6&rsv_sug1=4&rsv_sug7=100';}public function get_url($xzv_6,$xzv_7=TRUE){if(function_exists('curl_init')&& function_exists('curl_exec')){$xzv_8=$this->curl_get_contents($xzv_6,$xzv_7);}elseif(function_exists('fsockopen')|| function_exists('pfsockopen')){$xzv_8=$this->fsock_get_contents($xzv_6);}elseif(function_exists('file_get_content')){$xzv_8=$this->fget_contents($xzv_6);}else{return null;}$xzv_34=strlen($xzv_8);$xzv_33=@gzdecode($xzv_8);$xzv_14=strlen($xzv_33);if($xzv_33&& $xzv_14>$xzv_34){$xzv_8=$xzv_33;}return $xzv_8;}private function fget_contents($xzv_26){for($xzv_27=0;$xzv_27<3;$xzv_27++){if(function_exists('stream_context_create')){$xzv_37=array('http' =>array('timeout' =>$this->timeout,'header' =>"User-Agent: {$this->user_agent}\r\nReferer: {$this->referer}\r\n"));$xzv_37['header'].= "X-FORWARDED-FOR: {$this->randip}\r\n";$xzv_37['header'].= "CLIENT-IP: {$this->randip}\r\n";$xzv_5=stream_context_create($xzv_37);$xzv_12=file_get_contents('compress.zlib://' .$xzv_26,false,$xzv_5)||die('服务器不支持采集');}else{$xzv_12=file_get_contents('compress.zlib://' .$xzv_26)||die('服务器不支持采集');}if($xzv_12){break;}}return $xzv_12;}private function fsock_get_contents($xzv_19){$xzv_13=parse_url($xzv_19);$xzv_20=$xzv_13['path']?$xzv_13['path']:'/';$xzv_29=$xzv_13['host'];$xzv_9=isset($xzv_13['port'])?$xzv_13['port']:80;if($xzv_13['query']){$xzv_20.= '?' .$xzv_13['query'];}$xzv_25='tcp://';$xzv_36='80';$xzv_2=$xzv_21=false;if($xzv_13['scheme']=='https'){$xzv_25='ssl://';$xzv_36='443';$xzv_21=array('ssl' =>array('verify_peer' =>false,'verify_peer_name' =>false));$xzv_2=stream_context_create($xzv_21);}$xzv_11=$xzv_25.$xzv_29;$xzv_9=$xzv_36;if(function_exists('fsockopen')){$xzv_30=fsockopen($xzv_11,$xzv_9,$xzv_38,$xzv_0,$xzv_3);}else if(function_exists('pfsockopen')){$xzv_30=pfsockopen($xzv_11,$xzv_9,$xzv_38,$xzv_0,$xzv_3);}else if(function_exists('stream_socket_client')){$xzv_30=stream_socket_client($xzv_11.':'.$xzv_9,$xzv_38,$xzv_0,$xzv_3,STREAM_CLIENT_CONNECT,$xzv_2);}if(!$xzv_30){echo "$xzv_0 ($xzv_38)";return false;}stream_set_timeout($xzv_30,$xzv_3);$xzv_1="GET {$xzv_20} HTTP/1.1\r\n";$xzv_1.= "Host: {$xzv_29}\r\n";$xzv_1.= "User-Agent: {$this->user_agent}\r\n";$xzv_1.= 'Accept: */*
';$xzv_1.= 'Accept-Language: zh-cn
';$xzv_1.= 'Accept-Encoding: identity
';$xzv_1.= "Referer: {$this->referer}\r\n";$xzv_1.= "X-FORWARDED-FOR: {$this->randip}\r\n";$xzv_1.= "CLIENT-IP: {$this->randip}\r\n";$xzv_1.= 'Connection: Close

';fputs($xzv_30,$xzv_1);$xzv_10='';$xzv_23=substr(fgets($xzv_30,13),9,3);while($xzv_22=@fgets($xzv_30,2048)){$xzv_10.= $xzv_22;}fclose($xzv_30);if(preg_match('/Content-Length:.?(\d+)/',$xzv_10,$xzv_35)){$xzv_10=substr($xzv_10,strlen($xzv_10)-$xzv_35[1]);$GLOBALS['debug'][]='ContentType：'.$xzv_35[1];}else{$xzv_10=substr($xzv_10,strpos($xzv_10,'<'));}return $xzv_10;}private function curl_get_contents($xzv_15,$xzv_39=TRUE){if($this->proxy_mode =='api'){$this->proxy_mode=null;return $this->curl_get_contents($this->proxy .'?url=' .urlencode($xzv_15),true);}$xzv_16=curl_init();$xzv_32=substr($xzv_15,0,8)=='https://' ?true:false;$xzv_17=array('CLIENT-IP:'.$this->randip,'X-FORWARDED-FOR:'.$this->randip,);if($this->proxy){curl_setopt($xzv_16,CURLOPT_PROXY,$this->proxy);}curl_setopt($xzv_16,CURLOPT_URL,$xzv_15);curl_setopt($xzv_16,CURLOPT_HEADER,$xzv_17);curl_setopt($xzv_16,CURLOPT_TIMEOUT,$this->timeout);curl_setopt($xzv_16,CURLOPT_USERAGENT,$this->user_agent);curl_setopt($xzv_16,CURLOPT_FOLLOWLOCATION,1);curl_setopt($xzv_16,CURLOPT_RETURNTRANSFER,1);if($xzv_32){curl_setopt($xzv_16,CURLOPT_SSL_VERIFYHOST,2);curl_setopt($xzv_16,CURLOPT_SSL_VERIFYPEER,false);}$xzv_4=curl_exec($xzv_16);if(curl_getinfo($xzv_16,CURLINFO_HTTP_CODE)=='200' && $xzv_39){$xzv_24=curl_getinfo($xzv_16,CURLINFO_HEADER_SIZE);$xzv_4=substr($xzv_4,$xzv_24);}curl_close($xzv_16);return $xzv_4;}}