<?php
	//post访问网页，1post地址，2post数据,3cookie
	function post2 ($str1,$str2,$cookie){
		$ch=@curl_init();
		@curl_setopt($ch,CURLOPT_URL,$str1);
		@curl_setopt($ch,CURLOPT_HEADER,1);
		@curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
		@curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie);
		@curl_setopt($ch,CURLOPT_POST,1);
		@curl_setopt($ch,CURLOPT_POSTFIELDS,$str2);
		$data=@curl_exec($ch);
		@curl_close($ch);
		return $data;
	}
	//取出中间文本,1全文本，2左边文本，3右边文本，返回取出的文本
	function text_midtext2 ($str,$left,$right){
		$a = explode($left,$str);
		$sz2 = $a[1];
		$sz1 = explode($right,$sz2);
		return $sz1[0];
	}


Class cron{
	/*Class-初始化*/
    function __construct(){
		$this -> dotime = time ();
    }

	/*Class-取QQ等级*/
	function qdj ($data){
		return text_midtext2 ($data,'<img src="http://3gimg.qq.com/3gqq/lv/','.png" alt="');
	}

	/*Class-登陆QQ取等级*/
	function login_qdj ($data,$sid){
		/*取等级获取地址*/
		$a = explode('<a href="http://',$data);
		$sz2 = $a[1];
		$sz1 = explode('g/s?sid=',$sz2);
		$q = $sz1[0];
		$url = "http://".$q."g/s?sid=".$sid."&aid=nqqchatMain&on=1&dbg=slow_chgStat";
		$data = file_get_contents ($url);
		/*采集等级*/
		$a = explode('.png" alt="',$data);
		$sz2 = $a[1];
		$sz1 = explode('"',$sz2);
		$dj = $sz1[0];
		/*处理等级*/
		if ($dj == Null){
			$dj = 'No Get';
		}
		return $dj;
	}

	/*Class-更新挂Q时长*/
	function economize_time ($time){
		$row = mysql_fetch_array(mysql_query ("SELECT * FROM `storage` WHERE `type`='landing'"));
		$row['value'] += $time * 10;
		mysql_query ("UPDATE `storage` SET `value`='{$row['value']}' WHERE `type`='landing'");
	}

	/*Class-QQ消息自动回复*/
	function hf ($qquser,$qqsid){

		$text = file_get_contents ('http://q32.3g.qq.com/g/s?aid=nqqchatMain&sid='.$qqsid.'&myqq='.$qquser);

		if (strpos (text_midtext2 ($text,'<img  src="','" alt="聊天"/>('),'qbar/qbar_qqui_QQMsg.gif') != false){
			$text = text_midtext2 ($text,'<p><a  href="','"><img  src="');
			$text = str_replace(';','&',$text);
			$text = file_get_contents ($text);
			$qq = text_midtext2 ($text,'<postfield name="u" value="','"/>');

			$r = rand (1,100);
			if ($r < 5){
				$text = '我正在“暗月挂Q网（aygq.cc）”挂Q，暂时无法回复您！/:)';
			}else{
				$text = '我正在暗月挂Q网挂Q（百度搜索“暗月挂Q网”，一起来体验挂Q的乐趣吧！），暂时无法回复您！/:)';
			}
			$text = post2 ('http://q32.3g.qq.com/g/s?sid='.$qqsid,'msg='.@urlencode ($text).'&u='.$qq.'&saveURL=0&do=send&on=1&saveURL=0&aid=%E5%8F%91%E9%80%81&num=1689818364&do=sendsms');
			if (strpos ($text,'消息发送成功') != false){
				return true;
			}else{
				return false;
			}

		}else{
			return false;
		}
	}

	/*Class-获取处理耗用时间*/
	function hi_time (){
		$endtime = time ();
		$return = $endtime - $this->dotime;
		return $return;
	}

	/*Class-登陆3GQQ*/
	function Login_3G ($qq,$sid){

		$data = file_get_contents ('http://q16.3g.qq.com/g/s?aid=nqqchatMain&sid='.$sid);
		if (strstr ($data,'正在跳转')){
			$data = file_get_contents ('http://pt.3g.qq.com/s?aid=nLogin3gqqbysid&3gqqsid='.$sid);
		}

		$dj = $this -> qdj ($data);
		if ($dj!=Null){
			file_get_contents ("http://q32.3g.qq.com/g/s?sid=$sid&s=10&aid=chgStatus");
			mysql_query ("UPDATE `qqlist` SET `dj`='$dj' WHERE `qq`='$qq'");
			return true;
		}else{
			return false;
		}
	/*
		$state = file_get_contents ("http://q32.3g.qq.com/g/s?sid=$sid&s=10&aid=chgStatus");
		if (($data != Null) and (!strpos ($data,'为了保护您的账户安全')) and (!strpos ($data,'登录失败')) and (strpos ($state,'成功'))){

			$qqdj = $this -> qdj ($data);
			if ($qqdj != 'No Get'){
				mysql_query ("UPDATE `qqlist` SET `dj`='$qqdj' WHERE `qq`='$qq'");
			}

			return true;
		}else{
			return false;
		}
	*/
	}

	/*Class-登陆手机QQ*/
	function Login_Cellphone ($qq,$pw){
		$ME = new AYGQ_MQQ($qq,$pw);
		if ($ME -> Login ($hexadecimal,$error)){
			return true;
		}else{
			return false;
		}
	}
}