| 1 | package Mojo::Webqq::Model::Ext; | ||
| 2 | BEGIN{ | ||
| 3 | eval{ | ||
| 4 | require Webqq::Encryption; | ||
| 5 | }; | ||
| 6 | unless($@){ | ||
| 7 | $Mojo::Webqq::Model::Ext::has_webqq_encryption = 1; | ||
| 8 | } | ||
| 9 | } | ||
| 10 | our $_retcode; | ||
| 11 | our $_verifycode; | ||
| 12 | our $_md5_salt; | ||
| 13 | our $_verifysession; | ||
| 14 | our $_is_rand_salt; | ||
| 15 | our $_api_check_sig; | ||
| 16 | |||
| 17 | sub model_ext_authorize{ | ||
| 18 | my $self = shift; | ||
| 19 | if(not $Mojo::Webqq::Model::Ext::has_webqq_encryption){ | ||
| 20 | $self->warn("未安装 Webqq::Encryption 模块,无法获取扩展信息,安装方法参见: https://metacpan.org/pod/distribution/Webqq-Encryption/lib/Webqq/Encryption.pod"); | ||
| 21 | $self->model_ext(0); | ||
| 22 | return; | ||
| 23 | } | ||
| 24 | |||
| 25 | if($self->login_type eq 'login' and $self->account !~ /^\d+$/){ | ||
| 26 | $self->error("使用账号密码登录方式,account参数不是有效的QQ号码"); | ||
| 27 | $self->stop(); | ||
| 28 | } | ||
| 29 | if($self->pwd){ | ||
| 30 | $self->info("开始账号密码方式登录...") if $self->login_type eq 'login'; | ||
| 31 | $self->info("尝取扩展信息授权...") if $self->login_type eq 'qrlogin'; | ||
| 32 | my $ret = $self->_model_ext_prepare() && $self->_model_ext_check() && $self->_model_ext_login() && $self->_model_ext_check_sig(); | ||
| 33 | if($ret){ | ||
| 34 | $self->model_ext($ret); | ||
| 35 | #$self->info("账号密码方式登录成功"); | ||
| 36 | return 1; | ||
| 37 | } | ||
| 38 | else{ | ||
| 39 | #$self->info("账号密码方式失败"); | ||
| 40 | return 0; | ||
| 41 | } | ||
| 42 | } | ||
| 43 | else{ | ||
| 44 | $self->warn("未设置有效的登录密码,无法进行登录"); | ||
| 45 | return 0; | ||
| 46 | } | ||
| 47 | return 1; | ||
| 48 | } | ||
| 49 | sub _model_ext_prepare { | ||
| 50 | my $self = shift; | ||
| 51 | $self->debug("账号登录中(prepare)..."); | ||
| 52 | my(undef,$ua,$tx) = $self->http_get('https://xui.ptlogin2.qq.com/cgi-bin/xlogin?appid=715030901&daid=73&pt_no_auth=1&s_url=http%3A%2F%2Fqun.qq.com%2F',{Referer=>'http://qun.qq.com/',ua_debug_res_body=>0, blocking=> 1}); | ||
| 53 | return $tx->res->code == 200?1:0; | ||
| 54 | } | ||
| 55 | |||
| 56 | sub _model_ext_check { | ||
| 57 | my $self = shift; | ||
| 58 | $self->debug("账号登录中(check)..."); | ||
| 59 | my $content = $self->http_get( | ||
| 60 | $self->gen_url('https://ssl.ptlogin2.qq.com/check', | ||
| 61 | ( | ||
| 62 | regmaster => '', | ||
| 63 | pt_tea => 2, | ||
| 64 | pt_vcode => 1, | ||
| 65 | uin => ($self->login_type eq 'login'?$self->account:$self->uid), | ||
| 66 | appid => 715030901, | ||
| 67 | js_ver => 10233, | ||
| 68 | js_type => 1, | ||
| 69 | login_sig => $self->search_cookie("pt_login_sig"), | ||
| 70 | u1 => 'http%3A%2F%2Fqun.qq.com%2F', | ||
| 71 | r => rand(), | ||
| 72 | pt_uistyle=> 40, | ||
| 73 | pt_jstoken=> 485008785 | ||
| 74 | ) | ||
| 75 | ), | ||
| 76 | {blocking=>1,Referer => 'https://xui.ptlogin2.qq.com/cgi-bin/xlogin?appid=715030901&daid=73&pt_no_auth=1&s_url=http%3A%2F%2Fqun.qq.com%2F'}, | ||
| 77 | ); | ||
| 78 | my($retcode,$verifycode,$md5_salt,$verifysession,$is_rand_salt) = $content =~/'([^']*)'/g; | ||
| 79 | |||
| 80 | if($retcode == 0 ){ | ||
| 81 | $_retcode = $retcode; | ||
| 82 | $_verifycode = $verifycode; | ||
| 83 | $_md5_salt = $md5_salt; | ||
| 84 | $_verifysession = $verifysession; | ||
| 85 | $_is_rand_salt = $is_rand_salt; | ||
| 86 | } | ||
| 87 | else{ | ||
| 88 | $self->error("账号登录失败: 可能因为登录环境变化引起,解决方法参见:https://github.com/sjdy521/Mojo-Webqq/issues/183"); | ||
| 89 | } | ||
| 90 | return $retcode == 0? 1 : 0; | ||
| 91 | } | ||
| 92 | |||
| 93 | sub _model_ext_login{ | ||
| 94 | my $self = shift; | ||
| 95 | $self->debug("账号登录中(login)..."); | ||
| 96 | my $content = $self->http_get( | ||
| 97 | $self->gen_url('https://ssl.ptlogin2.qq.com/login', | ||
| 98 | ( | ||
| 99 | u => ($self->login_type eq 'login'?$self->account:$self->uid), | ||
| 100 | verifycode => $_verifycode, | ||
| 101 | pt_vcode_v1 => 0, | ||
| 102 | pt_verifysession_v1 => ,$_verifysession // $self->search_cookie('verifysession'), | ||
| 103 | p => Webqq::Encryption::pwd_encrypt($self->pwd,$_md5_salt,$_verifycode,1), | ||
| 104 | pt_randsalt => $_is_rand_salt || 0,, | ||
| 105 | pt_jstoken => 485008785, | ||
| 106 | u1 => 'http%3A%2F%2Fqun.qq.com%2F', | ||
| 107 | ptredirect => 1, | ||
| 108 | h => 1, | ||
| 109 | t => 1, | ||
| 110 | g => 1, | ||
| 111 | from_ui => 1, | ||
| 112 | ptlang => 2052, | ||
| 113 | action => '1-14-1515074375763', | ||
| 114 | js_ver => 10233, | ||
| 115 | js_type => 1, | ||
| 116 | login_sig => $self->search_cookie("pt_login_sig"), | ||
| 117 | pt_uistyle => 40, | ||
| 118 | aid => 715030901, | ||
| 119 | daid => 73, | ||
| 120 | has_onekey => 1, | ||
| 121 | ) | ||
| 122 | ) . '&', | ||
| 123 | { | ||
| 124 | Referer => 'https://xui.ptlogin2.qq.com/cgi-bin/xlogin?appid=715030901&daid=73&pt_no_auth=1&s_url=http%3A%2F%2Fqun.qq.com%2F', | ||
| 125 | blocking => 1, | ||
| 126 | }, | ||
| 127 | ); | ||
| 128 | |||
| 129 | my($retcode,undef,$api_check_sig,undef,$info,$nick) = $content =~/'([^']*)'/g; | ||
| 130 | if($retcode != 0){ | ||
| 131 | $self->warn("账号登录失败: $info"); | ||
| 132 | } | ||
| 133 | else{ | ||
| 134 | $_api_check_sig = $api_check_sig; | ||
| 135 | } | ||
| 136 | return $retcode == 0?1:0; | ||
| 137 | } | ||
| 138 | |||
| 139 | sub _model_ext_check_sig { | ||
| 140 | my $self = shift; | ||
| 141 | $self->debug("账号登录中(check_sig)..."); | ||
| 142 | my(undef,$ua,$tx) = $self->http_get($_api_check_sig,{ua_debug_res_body=>0}); | ||
| 143 | return $tx->res->code == 200?1:0; | ||
| 144 | } | ||
| 145 | |||
| 146 | 1; |