php模拟用户自动在qq空间发表文章的步骤
时间:2021-07-01 10:21:17
帮助过:28人阅读
php模拟用户自动在qq空间发表文章的方法
我们这里是一个简单的利用php来模拟登录后再到QQ空间发送文章的一个简单的程序,有需要的朋友可以参考,或改进可以给我意见,代码如下:
[php] view plaincopy
-
-
-
- function request($url,$referer='',$postdata='',$cookie='',$cookiefile=''){
-
-
- $header='';
-
- $header.="Content-Type: application/x-www-form-urlencodedrn";
-
- $header.="User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)rn";
-
- $header.="Referer:".$referer."rn";
-
- $header .= "Cookie:".$cookie ;
-
-
- if($postdata=='')$method='GET';
-
- else $method='POST';
-
-
- $opts=array();
-
- $opts['http']=array('method'=>$method,'header'=>$header,'content'=>$postdata);
-
-
- $context=stream_context_create($opts);
-
-
- $yuanma=file_get_contents($url,false,$context);
-
-
- if($cookiefile!=''){
-
- echo '需要保存cookie
'; -
-
- if(!file_exists($cookiefile)){
-
- file_put_contents($cookiefile,'');
-
- }
-
-
- $response=implode("rn",$http_response_header);
-
-
- $zengze="/Set-Cookie:(.*?)rn/";
-
- preg_match_all($zengze,$response,$cookie_arr);
-
-
- if(!emptyempty($cookie_arr[1])){
-
- $cookiestr=implode(';',$cookie_arr[1]);
-
- file_put_contents($cookiefile,$cookiestr);
-
- echo '成功保存cookie
'; -
- }
-
- else echo '没有匹配到cookie
'; -
- }
-
-
- return $yuanma;
-
- }
-
-
- function GetCurUrl()
-
- {
-
- if(!emptyempty($_SERVER["REQUEST_URI"]))
-
- {
-
- $scriptName = $_SERVER["REQUEST_URI"];
-
- $nowurl = $scriptName;
-
- }
-
- else
-
- {
-
- $scriptName = $_SERVER["PHP_SELF"];
-
- if(emptyempty($_SERVER["QUERY_STRING"]))
-
- {
-
- $nowurl = $scriptName;
-
- }
-
- else
-
- {
-
- $nowurl = $scriptName."?".$_SERVER["QUERY_STRING"];
-
- }
-
- }
-
- return $nowurl;
-
- }
-
-
-
-
- $nowurl=GetCurUrl();
-
-
-
-
-
- if(!isset($_POST['qq'])){
-
- echo '';
-
- die();
-
- }
-
-
-
-
-
-
- header('Content-Type:text/html;charset=gb2312');
-
- set_time_limit(0);
-
-
-
-
-
-
- $cookiefile=dirname(__FILE__).'\qq_cookie.txt';
-
- if(!file_exists($cookiefile)){
-
- echo 'qq_cookie.txt不存在,自动创建,请填写抓包的cookie
'; -
- file_put_contents($cookiefile,'');
-
- die('程序退出');
-
- }
-
-
- else{
-
- $cookie=file_get_contents($cookiefile);
-
-
- }
-
-
-
-
-
-
- if(emptyempty($_POST['qq'])||preg_match('/[^0-9]/is',$_POST['qq']))die('qq号码有误,必须数字');
-
- else $qq=$_POST['qq'];
-
- if(emptyempty($_POST['g_tk'])||preg_match('/[^0-9]/is',$_POST['g_tk']))die('post重要参数g_tk不合法,必须数字,请使用抓包的值');
-
- $g_tk=$_POST['g_tk'];
-
-
-
- $title=emptyempty($_POST['title'])?die('标题不得空'):$_POST['title'];
-
- $content=emptyempty($_POST['content'])?die('内容不得空'):$_POST['content'];
-
-
-
- $category='个人日记';
-
- $fabiao='http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk='.$g_tk;//发表处理页
-
- $referer='http://ctc.qzs.qq.com/qzone/v5/toolpages/fp_gbk.html';//来源页
-
- $r1='http://user.qzone.qq.com/'.$qq.'/infocenter';//列表访问来源页
-
- $postdata='uin='.$qq.'&category='.urlencode($category).'&title='.urlencode($title).'&content='.urlencode($content).'&html='.urlencode(''.$content.'').'&tweetflag=0&cb_autograph=1&topflag=0&needfeed=0&g_tk='.$g_tk.'&_fp_refer=http%3A%2F%2Fctc.qzs.qq.com%2Fqzone%2Fnewblog%2Fv5%2Feditor.html%3Fsource%3D1%7Chttp%3A%2F%2Fctc.qzs.qq.com%2Fqzone%2Fnewblog%2Fv5%2Feditor.html%3Fsource%3D1%3Chttp%3A%2F%2Fuser.qzone.qq.com%2F'.$qq.'%2Fmain';
-
-
-
-
- $yuanma=request($fabiao,$r1,$postdata,$cookie,'');
-
- if(strpos($yuanma,'发表成功'))echo $title.' 发表成功
'; -
- else echo '发表失败:右键查看源码,可以看到具体错误'.$yuanma;
-
- ?>
代码仅供参考,成功率有待大家的验证