PHP挂QQ源码 ____PHP挂QQ代码

sjqzone 2013-06-19 01:55:25

<?php

/**
* @author 陈德华 <chen@dehua.me>
*/
class TencentServer {

static $userAgent = 'Mozilla/5.0 (X11; Linux i686; rv:20.0) Gecko/20100101 Firefox/20.0';

static $host = 'q16.3g.qq.com';

static $login = 'http://pt.3g.qq.com/s?aid=nLogin3gqq&auto=1&g_f=1796';

static $data;


static public function login($qq, $pass, $debug=false){
$post = self::_login();
$form = $post['form'];
$post['qq'] = $qq;
$post['pwd'] = $pass;

self::postUrl($form, self::$login, $post);

if(preg_match('~title="登录成功"~', self::$data)){
preg_match('~sid=(.*?)\&~', self::$data, $sid);
return self::loging($qq, $sid[1], $debug);
}

if(preg_match('~密码不正确~', self::$data)){
return array('code' =>'error','msg'=>'密码错误');
}

if(preg_match('~验证码~', self::$data)){
return array('code' =>'image','msg'=>'需要输入验证码');
}

return array('code' =>'error','msg'=>'登录失败','data'=> self::$data);
}

static public function loging($qq, $sid, $debug=false){

$url = 'http://q16.3g.qq.com/g/s?aid=nqqchatMain&sid='.$sid.'&myqq'.$qq;
$addon = '&g_f=1657&g_ut=2&gutswicher=2';

self::getUrl($url . $addon);

if(preg_match('~验证码~', self::$data)){
return array('code' =>'image','msg'=>'需要输入验证码');
}

if(preg_match('~手动刷新~', self::$data)){
if(!$debug){
self::$data = null;
}
return array('code' => 'ok', 'sid' => $sid,'data'=> self::$data);
}

//正在跳转
if(preg_match('~id="forward"~', self::$data)){

preg_match('~ontimer="(.*?)"~', self::$data, $login);
$login = str_replace('&', '&', $login[1]) . $addon;

self::getUrl($login);

if(preg_match('~验证码~', self::$data)){
return array('code' =>'image','msg'=>'需要输入验证码');
}

if(preg_match('~手动刷新~', self::$data)){
if(!$debug){
self::$data = null;
}
return array('code' => 'ok', 'sid' => $sid, 'data'=> self::$data);
}
}

return array('code' =>'error','msg'=>'登录失败','data'=> self::$data);
}

static protected function _login(){

$data = file_get_contents(self::$login);

preg_match_all('~go href="(.*?)"~', $data, $url);
if(!isset($url[1][2])){
throw new Exception('login url not found');
}

preg_match_all('~postfield name="(\w+)" value="(.*?)"~', $data, $matches);
$index = array_search('bid_code', $matches[1]);
if(!$index){
throw new Exception('bid_code not found');
}

$aid = array_search('aid', $matches[1]);
$query = array();
for($i=$index;$i<$aid;$i++){
$query[$matches[1][$i]] = $matches[2][$i];
}

preg_match_all('~go href="(.*?)"~', $data, $action);
if(!isset($action[1][1])){
throw new Exception('form action not found');
}
$query['form'] = $action[1][1];
return $query;
}

public static function getUrl($url, $referer=null){
$ch = curl_init();
// 2. 设置选项,包括URL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
if($referer == null){
curl_setopt($ch, CURLOPT_REFERER, $url);
}
// 3. 执行并获取HTML文档内容
self::$data = curl_exec($ch);
// 4. 释放curl句柄
curl_close($ch);
return self::$data;
}


public static function postUrl($url, $referer, $data){
$ch = curl_init();
// 2. 设置选项,包括URL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
if($referer == null){
curl_setopt($ch, CURLOPT_REFERER, $url);
}
// 3. 执行并获取HTML文档内容
self::$data = curl_exec($ch);
// 4. 释放curl句柄
curl_close($ch);
return self::$data;
}
}
?>

...全文
701 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
sjqzone 2013-06-19
  • 打赏
  • 举报
回复

20,359

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧