<?php

	#暗月科技丶挂Q部原创代码, 版权所有 (C) 2011-20XX
	
	#最后修订时间: 二〇一四年十一月十六日 14:34:43

	require 'httplib.class.php';

	Class AYGQ_MQQ{


		private $fk,$uin,$pwd,$address;


		function __construct($uin,$pwd){

			$this -> fk = new httplib;

			$this -> uin = $uin;

			$this -> pwd = $pwd;

			$this -> address = '119.147.10.10:14000';//119.147.14.253:14000

			$this -> fk -> open ($this -> address);

		}




		#登录
		function Login (&$hexadecimal,&$error){

			$this -> fk -> post ('VER=1.4&CON=0&CMD=Login&SEQ='.rand(200,999).'&UIN='.$this->uin.'&PS='.strtoupper(md5($this->pwd)).'&M5=1&LG=1&LC=2EC70D1101DB674F&GD=V1A5GPI7WWW7CJ8O&CKE=');

			$this -> fk -> send ();

			parse_str ($this -> fk -> response(),$arr);

			if (strlen ($arr['VC']) > 50){

				$hexadecimal = $arr['VC'];

				return false;

			}else if ($arr['RS']=='0'){

				return true;

			}else{

				$error = $arr['RA'];

				return false;

			}

		}



		#获取验证码图片
	    function GetVerifycode ($hexadecimal){

	    	$len = strlen ($hexadecimal);

			for($i=0;$i<$len;$i+=2){
				$data .=  chr(hexdec($hexadecimal[$i].$hexadecimal[$i+1]));
			}
			return $data;

	    }



	    #提交验证码
		function PostVerifycode ($code,&$hexadecimal){

			$this -> fk -> post ('VER=1.4&CON=1&CMD=VERIFYCODE&SEQ='.rand(200,999).'&UIN='.$this->uin.'&SID=&XP=C4CA4238A0B92382&SC=2&VC='.$code);

			$this -> fk -> send ();

			parse_str ($this -> fk -> response(),$arr);

			if (strlen ($arr['VC']) > 50){

				$hexadecimal = $arr['VC'];

				return false;

			}else if ($arr['RS']=='0'){

				return true;

			}else{

				return false;

			}

	    }



	    #设置在线状态 (在线:10, 离开:30, 隐身:40)
	    function ChangeStat ($stat){

			$this -> fk -> post ('VER=1.4&CON=1&CMD=Change_Stat&SEQ='.rand(200,999).'&UIN='.$this->uin.'&SID=&XP=C4CA4238A0B92382&ST='.$stat);

			$this -> fk -> send ();


	    }








		#获取好友列表(包含: UIN、昵称)
		function SimpleInfo2 (){

			$this -> fk -> post ('VER=1.4&CON=1&CMD=SimpleInfo2&SEQ='.rand(200,999).'&UIN='.$this->uin.'&SID=&XP=C4CA4238A0B92382&UN=0&TO=0');

			$this -> fk -> send ();

			parse_str ($this -> fk -> response(),$arr);

			return array ('UN' => $arr['UN'],'NK' => $arr['NK']);

		}



		#查询统计
		function Query_Stat2 (){

			$this -> fk -> post ('VER=1.4&CON=1&CMD=Query_Stat2&SEQ='.rand(200,999).'&UIN='.$this->uin.'&SID=&XP=C4CA4238A0B92382&CM=2&UN=0');

			$this -> fk -> send ();

			parse_str ($this -> fk -> response(),$arr);

			return array ('FN' => $arr['FN'],'SN' => $arr['SN'],'ST' => $arr['ST'],'UN' => $arr['UN']);

		}







		#获得即时聊天消息并回复，返回回复数量
		function GetMsg ($reply){

			parse_str ($this -> AnYue_Request ($this->address,'VER=1.4&CON=0&CMD=GetMsgEx&SEQ='.rand(1,9000).'&UIN='.$this->uin.'&SID=&XP=29E41F6186ED43F8'),$arr);

			$Msg[1] = explode (',',$arr['UN']);

			$Msg[2] = explode (' ,',$arr['MG']);

			foreach ($Msg[1] as $key => $value){

				if ($value){
					$this -> Cltmsg ($value,$reply);
				}

			}

			return $key;

		}










		#查找好友
		function AddToList ($uin){

			$this -> fk -> post ('VER=1.1&CON=1&CMD=AddToList&SEQ='.rand(200,999).'&UIN='.$this->uin.'&SID=&XP=C4CA4238A0B92382&UN='.$uin);

			$this -> fk -> send ();

			parse_str ($this -> fk -> response(),$arr);

			return array ('CD' => $arr['CD']);

			//CD 为被加QQ的身份验证状态，CD为0表示“允许任何人把我列为好友”，CD为1表示“需要身份证认才能把我列为好友”，CD为3表示“不允许任何人把我列为好友”。如果CD为0那么信息回馈后，用户就直接加为好友了，如果CD为1，那么还要发送一次回应加为好友的响应。

		}






		#请求添加好友
		function Ack_AddToList ($uin){

			$this -> fk -> post ('VER=1.4&CON=1&CMD=Ack_AddToList&SEQ='.rand(200,999).'&UIN='.$this->uin.'&SID=&XP=C4CA4238A0B92382&UN='.$uin);

			$this -> fk -> send ();


		}





		#获取QQ黑名单
		function BlackList (){

			$this -> fk -> post ('VER=1.1&CMD=List&SEQ='.rand(200,999).'&UIN='.$this->uin.'&TN=160&UN=0');

			$this -> fk -> send ();

			parse_str ($this -> fk -> response(),$arr);

			return array ('FN' => $arr['FN'],'SN' => $arr['SN'],'SQ' => $arr['SQ'],'UN' => $arr['UN']);


		}








		#获取好友QQ信息
		function GetInfo ($uin){

			$this -> fk -> post ('VER=1.1&CMD=GetInfo&SEQ='.rand(200,999).'&UIN='.$this->uin.'&LV=2&UN='.$uin);

			$this -> fk -> send ();

			parse_str ($this -> fk -> response(),$arr);

			return array ('AD' => $arr['AD'],'AG' => $arr['AG'],'EM' => $arr['EM'],'FC' => $arr['FC'],'HP' => $arr['HP'],'JB' => $arr['JB'],'LV' => $arr['LV'],'PC' => $arr['PC'],'PH' => $arr['PH'],'PR' => $arr['PR'],'PV' => $arr['PV'],'RN' => $arr['RN'],'SC' => $arr['SC'],'SX' => $arr['SX'],'UN' => $arr['UN'],'NK' => $arr['NK']);

			//AD用户的联系地址，AG为用户年龄，EM为用户MAIL，FC 为用户头像，HP为用户网站，JB为用户职业，PC为用户邮编，PH为用户联系电话，PR为用户简介，PV为用户所以的省，RN为用户真实名称，SC为用户毕业院校，SX为用户性别，UN为用户QQ号，NK为用户QQ昵称。


		}












		//删除指定好友
		function DelFromList ($uin){

			$this -> fk -> post ('VER=1.1&CMD=DelFromList&SEQ='.rand(200,999).'&UIN='.$this->uin.'&UN='.$uin);

			$this -> fk -> send ();

			parse_str ($this -> fk -> response(),$arr);

			print_r ($arr);

		}






		#发送QQ消息
		function Cltmsg ($uin,$msg){

			$msg = str_replace('+',' ',$msg). '%0A%0A%0A%0A%E7%82%B9%E6%AD%A4%E8%BF%9B%E5%85%A5%E5%AE%98%E6%96%B9%E7%BD%91%E7%AB%99%EF%BC%9Ahttp://'.$_SERVER['HTTP_HOST'].'%0A%0APowered%20by%20%E6%9A%97%E6%9C%88%E6%8C%82Q(AYGQ)';
			
			parse_str ($this -> AnYue_Request ($this->address,'VER=1.1&CMD=CLTMSG&SEQ='.rand(200,999).'&UIN='.$this->uin.'&UN='.$uin.'&MG='.$msg),$arr);


		}



		function ChangeStat2 ($code){
			//$this->Login($code);
			$return = $this -> AnYue_Request ($this->address,'VER=1.4&CMD=Change_Stat2&SEQ='.rand (1,9000).'&UIN='.$this->uin.'&ST='.$code);
			if(strpos($return,'&RES=20')){
				return true;
			}else{
				return false;
			}
		}



	    #注销
	    function Logout (){

			$this -> fk -> post ('VER=1.4&CON=1&CMD=Logout&SEQ='.rand(200,999).'&UIN='.$this->uin.'&SID=&XP=C4CA4238A0B92382');

			$this -> fk -> send ();

	    }




		function AnYue_Request ($remote_server,$post_string){
			$ch = curl_init ();
			curl_setopt ($ch,CURLOPT_URL,$remote_server);
			curl_setopt ($ch,CURLOPT_POSTFIELDS,$post_string);
			curl_setopt ($ch,CURLOPT_RETURNTRANSFER,true);
			curl_setopt ($ch,CURLOPT_USERAGENT,'AnYue Client');
			$data = curl_exec ($ch);
			curl_close ($ch);
			return $data;
		}


	}

	// $AYGQ_MQQ = new AYGQ_MQQ('1316146385','');
	
	// var_dump ($AYGQ_MQQ -> Login($hexadecimal,$error));
	
	// echo $hexadecimal,'<hr>',$error;
	
	// var_dump($AYGQ_MQQ -> ChangeStat(10));
	
	//
	
	// $AYGQ_MQQ -> GetMsg(urlencode('内容。。。啦~23320= =-咳咳！*（#&（'));

