麻辣堂|资源主站|开发论坛|在线手册
首页 Apache Linux Java MySQL 注册帮助 
PHP项目开发组是PHP开发资源网于2007组年建成立的项目开发团队,目前核心开发成员有27人, 项目协作成员8名.下设7个开发组,主要承接大/中型网站项目开发任务。

    由于开发任务较多,人员比较紧张,现面向社会招聘全职或者兼职开发人员,不管你是在校大学生,还是全职开发人员,以及SOHO都可以联系本站,我们可以长期合作,并为您带来丰厚的报酬。
  您现在的位置:PHP开发资源网 > 麻辣堂 > 详细资料
待解决
百度贴吧自动回帖机PHP源码
悬赏分:20 - 2007年08月22日


CODE:
<?php
/**
* baidu 贴吧自动回帖机
* author: hetal
* email : huoqi29@163.com
* qq : 231073376
* msn : hetao29@hotmail.com
* web : http://www.haqoo.com
*
*/
class Baidu_Post{
var $proxyPort;
var $proxyHost;
var $cookie;
//设置代理 ,ok
function setProxy($proxyHost,$proxyPort){
$this->proxyPort=$proxyPort;
$this->proxyHost=$proxyHost;
}
//初始化baiduID ,ok
function init(){
$data = $this->_getUrl("http://www.baidu.com/search/img/logo.gif");
preg_match_all ("/Set-Cookie: (.+?)=(.+?);/", $data, $_matches,PREG_SET_ORDER);
$tmp=array();
for($i=0;$i<count($_matches);$i++){
$tmp[]=$_matches[$i][1]."=".$_matches[$i][2];
}
$this->cookie=implode(';',$tmp);
}
//登录
function login($user,$pass){
$cookie=$this->cookie;
$post_data ="tpl=&tpl_ok=&skip_ok=&aid=0&need_pay=&need_coin=0&pay_method=0&u=&next_target=&return_method=&more_param=&return_type=&username=$user&password=$pass&Submit=+%B5%C7%C2%BC+";
$post_data_le = strlen($post_data);
if(!empty($this->proxyPort) and !empty($this->proxyHost)){
$post_url="http://passport.baidu.com/?login";
$post_port=$this->proxyPort;
$post_host=$this->proxyHost;
$connect="Proxy-Connection";
}else{
$post_url="/?login";
$post_port=80;
$connect="Connection";
$post_host="passport.baidu.com";
}
$data="POST $post_url HTTP/1.1\nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\nReferer: http://passport.baidu.com/?login\nAccept-Language: zh-cn\nContent-Type: application/x-www-form-urlencoded\nAccept-Encoding: gzip, deflate\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Alexa Toolbar)\nHost: passport.baidu.com\nContent-Length: $post_data_le\n$connect: Keep-Alive\nCache-Control: no-cache\nCookie: $cookie\n\n$post_data\n";
$sock = fsockopen($post_host,$post_port,$errno,$error,3);
fputs($sock,$data);
while($rt[]=fgets($sock)){}
fclose($sock);
$rt=implode("",$rt);
$rt=str_replace("\n","",$rt);
$rt=str_replace("\t","",$rt);
preg_match_all ("/Set-Cookie: (.+?)=(.+?);/", $rt, $_matches,PREG_SET_ORDER);
$tmp=array();
for($i=0;$i<count($_matches);$i++){
$tmp[]=$_matches[$i][1]."=".$_matches[$i][2];
}
$this->cookie=$cookie.";".implode(';',$tmp);
if(isset($tmp['BDUSS']) and !empty($tmp['BDUSS'])){
return 0;
}else{
return 1;
}
}
//得到最热的500个贴吧
function getTop500($url="http://post.baidu.com/tb/firstindex/1.html"){
$content=$this->_getUrl($url);
$title=array();
//preg_match_all ("/\<a href=\"http\:\/\/post\.baidu\.com\/f(.+?)\"(.+?)\>(.+?)\<\/a\>/", $content, $_matches,PREG_SET_ORDER);
preg_match_all ("/\<a href=\"\/f(.+?)\"(.+?)\>(.+?)\<\/a\>/", $content, $_matches,PREG_SET_ORDER);
foreach($_matches as $value){
$tmp=array();
$tmp['url']="http://post.baidu.com/f".$value[1];
$tmp['title']=$value[3];
$title[]=$tmp;
}
return $title;

}
//得到每个贴吧对应的第1页的贴子
function getTitle($tieba_url){
$content=$this->_getUrl($tieba_url);
//echo $content;
$title=array();
preg_match_all ("/\<a(.+?)href=\"\/f\?kz=(.+?)\"(.+?)\>(.+?)\<\/a\>/", $content, $_matches,PREG_SET_ORDER);
//print_r($_matches);
foreach($_matches as $value){
$tmp=array();
$tmp['url']="http://post.baidu.com/f?kz=".$value[2];
$tmp['title']=$value[4];
$title[]=$tmp;
}
return $title;
}
//回贴
function huitie($url,$title1,$title="",$content="",$logo="http://"){
$fileds=$this->_getTie($url);
if(empty($fileds)){return -1;}
$tmp[]="ct=".$fileds['ct'];
$tmp[]="tn=".$fileds['tn'];
$tmp[]="word=".urlencode($fileds['word']);
$tmp[]="lm=".$fileds['lm'];
$tmp[]="z=".$fileds['z'];
$tmp[]="sc=".$fileds['sc'];//贴子总数
$tmp[]="cm=".$fileds['cm'];
$tmp[]="rn=".$fileds['rn'];
$tmp[]="bs=".$fileds['bs'];
$tmp[]="str2=".$fileds['str2'];
$tmp[]="rs3=".$fileds['rs3'];
$tmp[]="bu=".urlencode($url);//这是回跳地址 //window.location
$tmp[]="ti=".rawurlencode($title);//标题
$tmp[]="ti1=".rawurlencode($title1);
$tmp[]="co=".rawurlencode($content);
$tmp[]="str1=".rawurlencode($logo);
$tmp[]="ch1=on";
$tmp[]="Submit3=%B7%A2%B1%ED%CC%F9%D7%D3";
$cookie=$this->cookie;
$post_data =implode("&",$tmp);
$post_data_le = strlen($post_data);
if(!empty($this->proxyPort) and !empty($this->proxyHost)){
$post_url="http://tiebacommit.baidu.com/f";
$post_port=$this->proxyPort;
$connect="Proxy-Connection";
$post_host=$this->proxyHost;
}else{
$post_url="/f";
$post_port=80;
$connect="Connection";
$post_host="tiebacommit.baidu.com";
}
$data="POST $post_url HTTP/1.1\nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\nAccept-Language: zh-cn\nContent-Type: application/x-www-form-urlencoded\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Alexa Toolbar)\nHost: tiebacommit.baidu.com\nContent-Length: $post_data_le\nConnection: Keep-Alive\nCache-Control: no-cache\nCookie: $cookie\n\n$post_data\n";
$sock = fsockopen($post_host,$post_port,$errno,$error,3);
fputs($sock,$data);
while (!feof($sock)) {
$rt[]=fgets($sock,1024);
}
fclose($sock);
$rt=implode("",$rt);
$rt=str_replace("\n","",$rt);
$rt=str_replace("\t","",$rt);
preg_match_all ("/var rsn=(.+?);/", $rt, $_matches,PREG_SET_ORDER);
return isset($_matches[0][1])?$_matches[0][1]:-99;
}
function _getTie($url="http://post.baidu.com/f?kz=190275966"){
$content=$this->_getUrl($url);
$title=array();
preg_match_all ("/\<input type=hidden name=(.+?) value=(.+?)\>/", $content, $_matches,PREG_SET_ORDER);
foreach($_matches as $value){
$key =trim($value[1]);
$v =str_replace("\"","",trim($value[2]));
$title[$key]=($v);
}
preg_match_all ("/fr_as_js_tr\(\)\{(.+)\}/", $content, $_matches,PREG_SET_ORDER);
$title['str2']=$this->_getStr2($_matches[0][1]);
unset($title['pn']);
unset($title['kw']);
unset($title['rs2']);
preg_match_all ("/var need_verify=(.+?);/", $content, $_matches,PREG_SET_ORDER);
if($_matches[0][1]==10){
return null;
}
return $title;
}
function _getStr2($cmd){
$cmd = str_replace("var ","",$cmd);
$cmd = str_replace("Math.","",$cmd);
$cmd = str_replace("v",'$v',$cmd);
$cmd = str_replace("i",'$i',$cmd);
return eval($cmd);
}
function _getUrl($url,$referer="")
{
$purl= parse_url($url);
$host=$purl['host'];
if(!empty($this->proxyHost) and !empty($this->proxyPort)){
$port=$this->proxyPort;
$post_host=$this->proxyHost;
}else{
$post_host=$purl['host'];
if(empty($purl['port'])){
$port=80;
}else{
$port=$purl['port'];
}
}
$cookie = $this->cookie;
$path=$purl['path'];
$query=empty($purl['query'])?"":$purl['query'];
if(!empty($proxyhost) and !empty($proxyport)){
$content="";
$content.="GET $url HTTP/1.0\r\n";
$content.="Accept: */*\r\n";
if(!empty($referer))
$content.="Referer: $referer\r\n";
$content.="Accept-Language: zh-cn\r\n";
$content.="Proxy-Connection: Keep-Alive\r\n";
$content.="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n";
$content.="Host: $host\r\n";
$content.="Pragma: no-cache\r\n";
$content.="Cookie: $cookie\r\n";
$content.="\r\n\r\n";
}else{
$content="";
if(!empty($query))
$content.="GET $path?$query HTTP/1.0\r\n";
else
$content.="GET $path HTTP/1.0\r\n";
$content.="Accept: */*\r\n";
if(!empty($referer))
$content.="Referer: $referer\r\n";
$content.="Accept-Language: zh-cn\r\n";
$content.="Connection: Keep-Alive\r\n";
$content.="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n";
$content.="Host: $host\r\n";
$content.="Pragma: no-cache\r\n";
$content.="Cookie: $cookie\r\n";
$content.="\r\n\r\n";
}
$sock=fsockopen ($post_host,$port,$errno, $errstr, 3);
if($sock){
fwrite($sock,$content);
}else{
return null;
}
while($r[]=fgets($sock)){};
fclose($sock);
return implode("\n",$r);
}


}
init();
if(!login("user","pass")){
echo "Login Fail:\n";
}else{
echo "Login Success:\n";
};
$title = _getTitle();
foreach($title as $value){
$i++;
if($i==31){
$url = $value['url'];
$title = $value['title'];
echo huitie($url,$title,"好","牛人啊");
exit;
}
}
?&gt;


baidu.class.rar

提问者:HeTal   08-22 15:03
答复
路过。。。顺便帮顶:)
回答者:玉米づ冰冻可乐 - 瓦岗村民 8-22 09:10
我也来回答:
不管你有没有帮助我们,瓦岗寨8万村民将感谢你。。。。。

为防止灌水,您需要计算一道数学题: 答案:
85 + 7 = ? 请将计算结果填在上面

 
[]
©2007 PhpRes.COM