discuzX2.5的自动发贴 刚用php curl写的
时间:2013-04-16
来源:互联网
<?php /* * * 作者:大水车 * 类用途: 实现discuz2.5登陆发帖 */ class discuz_post{ var $login_url; var $post_login_array=array( ); var $post_url; var $cookie_file; public function get_formhash($login_url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $login_url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $contents = curl_exec($ch);//print_r($contents);die; curl_close($ch); //正常发布的版本用如下方法可以获得登陆部分的formhash preg_match('/<input type="hidden" name="formhash" value="(.*)" \/>/isU', $contents, $matches); //echo "<pre>"; //print_r($matches);die; if(!empty($matches)) { $formhash = $matches[1]; } else { // die('Not found the forumhash.'); } return $formhash; } public function getcookie($login_url,$post){ $cookie_file = tempnam('./temp','cookie'); //print_r($cookie_file);die; $ch = curl_init($login_url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_exec($ch); curl_close($ch); $this->cookie_file=$cookie_file; return $cookie_file; } public function use_cookie($send_url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $send_url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_file); $contents = curl_exec($ch); curl_close($ch); //获得发帖页面的fromhash preg_match_all('/<input type="hidden" name="formhash" id="formhash" value="(.*)" \/>/isU',$contents,$matches); if(!empty($matches)){ $formhash = $matches[1][0]; }else { $formhash='';//没有 } return $formhash; } public function post_newthread($send_url,$thread_data){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $send_url); curl_setopt($ch, CURLOPT_REFERER, $send_url);//伪装REFERER curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_file); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $thread_data); $contents = curl_exec($ch); curl_close($ch); return 1; } }
//下面是代码例子******************************************************************************* $rc= new discuz_post(); //登陆的地址 $login_url='http://bbs.phpchina.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes'; $theformhash= $rc->get_formhash($login_url); //登陆部分需要发送的数据,这里处理没有验证码的 $login_array=array( 'username'=>'用户名', 'password'=>'密码', 'referer'=>'http://bbs.phpchina.com/', 'questionid'=>0, 'answer'=>'', 'seccodeverify'=>'', 'formhash'=>$theformhash,//这个貌似没有也可以发帖滴 ); //获得cookie文件 $the_cookie_file= $rc->getcookie($login_url,$login_array); $send_url ='http://bbs.phpchina.com/forum.php?mod=post&action=newthread&fid=2&infloat=yes'; $thesendformhash= $rc->use_cookie($send_url);//利用cookie文件的 $post_array=array( 'subject' => "发帖,发帖测试",//标题 'message' =>" 内容噢噢噢噢噢噢噢噢",//要超过10个字,奶奶的 'topicsubmit' => "yes", 'extra' => '', 'tags' => 'Curl',//帖子标签 'formhash'=>$thesendformhash, ); $rc->post_newthread($send_url,$post_array);//发了一贴 echo "<pre>"; print_r($rc); echo $theformhash; echo $the_cookie_file; echo $thesendformhash; unlink($rc->cookie_file);//删除cookie文件,也可以不删除 echo "ok!";
作者: 大水车 发布时间: 2013-04-16
/*
*
* 作者:大水车
* 类用途: 实现discuz2.5登陆发帖
*/
class discuz_post{
var $login_url;
var $post_login_array=array( );
var $post_url;
var $cookie_file;
public function get_formhash($login_url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $login_url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$contents = curl_exec($ch);//print_r($contents);die;
curl_close($ch);
//正常发布的版本用如下方法可以获得登陆部分的formhash
preg_match('/<input type="hidden" name="formhash" value="(.*)" \/>/isU', $contents, $matches);
//echo "<pre>";
//print_r($matches);die;
if(!empty($matches)) {
$formhash = $matches[1];
} else {
// die('Not found the forumhash.');
}
return $formhash;
}
public function getcookie($login_url,$post){
$cookie_file = tempnam('./temp','cookie');
//print_r($cookie_file);die;
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);
curl_close($ch);
$this->cookie_file=$cookie_file;
return $cookie_file;
}
public function use_cookie($send_url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $send_url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_file);
$contents = curl_exec($ch);
curl_close($ch);
//获得发帖页面的fromhash
preg_match_all('/<input type="hidden" name="formhash" id="formhash" value="(.*)" \/>/isU',$contents,$matches);
if(!empty($matches)){
$formhash = $matches[1][0];
}else {
$formhash='';//没有
}
return $formhash;
}
public function post_newthread($send_url,$thread_data){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $send_url);
curl_setopt($ch, CURLOPT_REFERER, $send_url);//伪装REFERER
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_file);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $thread_data);
$contents = curl_exec($ch);
curl_close($ch);
return 1;
}
}
//下面是代码例子*******************************************************************************
$rc= new discuz_post();
//登陆的地址
$login_url='http://bbs.phpchina.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes';
$theformhash= $rc->get_formhash($login_url);
//登陆部分需要发送的数据,这里处理没有验证码的
$login_array=array(
'username'=>'用户名',
'password'=>'密码',
'referer'=>'http://bbs.phpchina.com/',
'questionid'=>0,
'answer'=>'',
'seccodeverify'=>'',
'formhash'=>$theformhash,//这个貌似没有也可以发帖滴
);
//获得cookie文件
$the_cookie_file= $rc->getcookie($login_url,$login_array);
$send_url ='http://bbs.phpchina.com/forum.php?mod=post&action=newthread&fid=2&infloat=yes';
$thesendformhash= $rc->use_cookie($send_url);//利用cookie文件的
$post_array=array(
'subject' => "发帖,发帖测试",//标题
'message' =>" 内容噢噢噢噢噢噢噢噢",//要超过10个字,奶奶的
'topicsubmit' => "yes",
'extra' => '',
'tags' => 'Curl',//帖子标签
'formhash'=>$thesendformhash,
);
$rc->post_newthread($send_url,$post_array);//发了一贴
echo "<pre>";
print_r($rc);
echo $theformhash;
echo $the_cookie_file;
echo $thesendformhash;
unlink($rc->cookie_file);//删除cookie文件,也可以不删除
echo "ok!";
?>
作者: 大水车 发布时间: 2013-04-16
作者: shenshike 发布时间: 2013-04-16
作者: webdna 发布时间: 2013-04-17
图片上传呢?我写的采集发贴貌似被我整理硬盘的时候删了。。。。都是日本电影惹的祸 ...
你写过图片上传?
作者: 大水车 发布时间: 2013-04-17
图片上传呢?我写的采集发贴貌似被我整理硬盘的时候删了。。。。都是日本电影惹的祸 ...
你写过图片上传?
作者: 大水车 发布时间: 2013-04-17
作者: qai41 发布时间: 2013-04-17
你写过图片上传?
写过呀,discuz和phpwind都写过。。。
当年买了一个采集软件居然tmd是没有图片上传的,一怒之下自己就写了。
作者: shenshike 发布时间: 2013-04-17
上传是本地的,还是通过flash的上传?
作者: 大水车 发布时间: 2013-04-17
作者: fansuser 发布时间: 2013-04-17
能模拟发帖就行了,
作者: 大水车 发布时间: 2013-04-17
把人家论坛搞挂了,我艹!!!!!!!!!!
作者: 大水车 发布时间: 2013-04-19
作者: qxhy123 发布时间: 2013-04-19
里面的post数据超过 1024的时候要设置
有两种方法 ,curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
另外一个是 把http协议 CURLOPT_HTTP_VERSION CURL_HTTP_VERSION_1_0
作者: 大水车 发布时间: 2013-04-21
作者: ylyy 发布时间: 2013-04-21
主要代码如下
var myids=new Array(); for(var i in Meilishuo.config.p4p.tInfo){ myids[i]=Meilishuo.config.p4p.tInfo[i].twitter_id; } function curl(){ var tid=myids.shift(); $.post("http://www.meilishuo.com/twitter/ajax_voteTwitter",{"fws":"%5B%E5%B0%8F%E7%BA%A2%E5%BF%83%5D","stid":tid,"tvd":tid}); } var mary=setInterval("curl()", 2000); //window.clearInterval(mary);
作者: iminto 发布时间: 2013-04-21
作者: ipsnowj 发布时间: 2013-04-26
http://task.zhubajie.com/2698323/###
作者: jiahuafu 发布时间: 2013-05-02
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28