QQ空间自动登录

自动登录

define('ROOT_PATH',__DIR__);
include_once(ROOT_PATH.'/lib/Http.class.php');

$config=array(
    'username'=>'******',
    'password'=>'******'
);
//获取login_sig
$url="http://ui.ptlogin2.qq.com/cgi-bin/login";
$data=array(
    "hide_title_bar"=>"1",
    "low_login"=>"0",
    "qlogin_auto_login"=>"0",
    "no_verifyimg"=>"1",
    "link_target"=>"blank",
    "appid"=>"636014201",
    "target"=>"self",
    "s_url"=>"http://qzone.qq.com",
);
$resp=Http::httpGet($url,$data);
$matches=array();
$pattern="/"
        .preg_quote('g_login_sig=encodeURIComponent("')
        ."(\S+)"
        .preg_quote('")')
        ."/";
preg_match($pattern,$resp['body'],$matches);
$login_sig=$matches[1];

//获取verifycode、pt_verifysession_v1、uin
$url="http://check.ptlogin2.qq.com/check";
$data=array(
    'uin'=>$config['username'],
    'appid'=>'636014201',
    'js_ver'=>'10100',
    'js_type'=>'0',
    'login_sig'=>'0',
    'u1'=>'http://qzone.qq.com',
    'r'=>'0.'.time(),
);
$resp=Http::httpGet($url,$data);
$matches=array();
preg_match("/ptui_checkVC\((.+)\)/", $resp['body'],$matches);
$res=explode(',',$matches[1]);
$verifycode=trim(trim($res[1]),"'");
$uin=hex2str(trim(trim($res[2]),"'"));
$pt_verifysession_v1=trim(trim($res[3]),"'");

$url="http://ptlogin2.qq.com/login";
$data=array(
    "u"=>$config['username'],
    "p"=>getP(),
    "verifycode"=>$verifycode,
    "aid"=>"636014201",
    "u1"=>"http://qzone.qq.com",
    "h"=>"1",
    "ptredirect"=>"0",
    "ptlang"=>"2052",
    "from_ui"=>"1",
    "dumy"=>"",
    "fp"=>"loginerroralert",
    "action"=>"1-1-10000",
    "mibao_css"=>"",
    "t"=>"1",
    "g"=>"1",
    "js_type"=>"0",
    "js_ver"=>"10100",
    //跟g_login_sig有关
    "login_sig"=>$login_sig,
    "pt_uistyle"=>"0",
    "pt_vcode_v1"=>"0",
    "pt_verifysession_v1"=>$pt_verifysession_v1,
);
$resp=Http::httpGet($url,$data);
// print_r($resp);exit();

//处理密码参数
function getP(){
    global $config,$uin,$verifycode;
    $j=hex2bin(strtoupper(md5($config['password'])));
    $h=strtoupper(md5($j.$uin));
    $p=strtoupper(md5($h.strtoupper($verifycode)));
    return $p;
}
//转换"\x00\x2f……"成php字符串
function hex2str($hexstr){
    $res=explode('\x', $hexstr);
    $str="";
    foreach($res as $key=>$val){
        if(empty($val))continue;
        $str.=chr(hexdec($val));
    }   
    return $str;
}

你可能感兴趣的:(QQ空间自动登录)