|
|

楼主 |
发表于 2012-8-1 16:20:00
|
显示全部楼层
|
重发下代码。。。有想刷的尽管去吧。。。[ol]site = $site; $this->cookiefile = '/tmp/cookie'.getmypid().'.txt'; $this->useragent = 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'; $this->version = $version; } // 登录 function login($username, $password){ switch($this->version){ case '72': $url_login = "http://".$this->site."/logging.php?action=login"; $argv_login = array( 'action'=>'login', 'loginsubmit'=>'yes', 'username'=>$username, 'password'=>$password, 'cookietime'=>'2592000' ); break; case 'x20': $url_login = "http://".$this->site. "/member.php?mod=logging&action=login&loginsubmit=yes". "&infloat=yes&lssubmit=yes&inajax=1"; $argv_login = array( 'action'=>'login', 'loginsubmit'=>'yes', 'username'=>$username, 'password'=>$password, 'cookietime'=>'2592000' ); break; } $ch_login = curl_init(); curl_setopt($ch_login, CURLOPT_URL, $url_login); curl_setopt($ch_login, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch_login, CURLOPT_POST, TRUE); curl_setopt($ch_login, CURLOPT_POSTFIELDS, $argv_login); curl_setopt($ch_login, CURLOPT_HEADER, TRUE); curl_setopt($ch_login, CURLOPT_COOKIEJAR, $this->cookiefile); curl_setopt($ch_login, CURLOPT_USERAGENT, $this->useragent); $html_login = curl_exec($ch_login); if(!strpos($html_login, 'errorhandle_')){ return TRUE; } } // 获得formhash function getformhash($fid){ switch($this->version){ case '72': $url = "http://".$this->site."/post.php?action=newthread&fid={$fid}"; break; case 'x20': $url = "http://".$this->site."/forum.php?mod=post&action=reply&fid={$fid}"; break; } $html_formhash = $this->get_html($url); preg_match("/"formhash" value="(.*?)"/", $html_formhash, $array); $formhash = $array[1]; return $formhash; } function get_html($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookiefile); curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookiefile); curl_setopt($ch, CURLOPT_USERAGENT, $this->useragent); $html = curl_exec($ch); return $html; } function post_subject($subject, $message, $fid, $typeid=NULL){ if(empty($this->formhash)){ $this->formhash = $this->getformhash($fid); } switch($this->version){ case '72': $url = "http://".$this->site."/post.php?action=newthread&fid={$fid}&extra=&topicsubmit=yes"; $argv = array( 'action'=>'newthread', 'fid'=>$fid, 'formhash'=>$this->formhash, 'subject'=>$subject, 'typeid'=>'1', 'message'=>$message, 'topicsubmit'=>'yes', 'usesig'=>'1' ); break; case 'x20': $url = "http://".$this->site."/forum.php?mod=post&action=newthread&fid={$fid}&extra=&topicsubmit=yes"; $argv = array( 'formhash'=>$this->formhash, 'message'=>$message, 'subject'=>$subject, 'fid'=>$fid, 'replysubmit'=>'yes' ); break; } isset($typeid) && $argv['typeid'] = $typeid; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $argv); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookiefile); curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookiefile); curl_setopt($ch, CURLOPT_USERAGENT, $this->useragent); $html = curl_exec($ch); switch($this->version){ case '72': preg_match("/location: viewthread.php\?tid=(\d+)/", $html, $preg_array); break; case 'x20': preg_match("/window.location.href \='forum.php\?mod=viewthread&tid=(\d+)/", $html, $preg_array); break; } if(!empty($preg_array[1])){ return $preg_array[1]; }else{ return FALSE; } } // 发回复 function post_reply($message, $fid, $tid){ if(empty($this->formhash)){ $this->formhash = $this->getformhash($fid); } switch($this->version){ case '72': $url = "http://".$this->site."/post.php?action=reply&fid={$fid}&tid={$tid}"; $argv= array( 'action'=>'reply', 'fid'=>$fid, 'tid'=>$tid, 'formhash'=>$this->formhash, 'message'=>$message, 'replysubmit'=>'yes', 'usesig'=>'1' ); break; case 'x20': $url = "http://".$this->site."/forum.php?mod=post&action=reply&fid={$fid}"; $argv = array( 'formhash'=>$this->formhash, 'message'=>$message, 'subject'=>'', 'forum'=>'post', 'action'=>'reply', 'fid'=>$fid, 'tid'=>$tid, 'replysubmit'=>'yes' ); break; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $argv); curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookiefile); curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookiefile); curl_setopt($ch, CURLOPT_USERAGENT, $this->useragent); $html = curl_exec($ch); if(strpos($html, "tid={$tid}")){ return TRUE; }else{ return FALSE; } } function get_id($fids, $orderby='lastpost', $page=1){ $fid_key = array_rand($fids); $fid = $fids[$fid_key]; switch($this->version){ case 'x20': $furl = "http://".$this->site."/forum.php?mod=forumdisplay&fid={$fid}&filter=author&orderby={$orderby}&page={$page}"; break; case '72': $furl = "http://".$this->site."/forumdisplay.php?fid={$fid}&orderby={$orderby}&page={$page}"; break; } $html = $this->get_html($furl); preg_match_all("/id="normalthread_(\d+)"/", $html, $preg_tid); $tid_array = $preg_tid[1]; return array($fid, $tid_array[0]); }}[/ol]复制代码 |
|