<?php

class openShare_Tencent extends openShare{
	public $sHOST='open.t.qq.com/';
	public $sAPI_KEY='d76ba859229a4491bbe3020fa52affd7';
	public $sAPI_Secret='78b5b387e25ca99e9fc951fe660b614f';
	public $sMethod='GET';
	public $sPAGE='';
	public $sPAGE_Callback='';
	public $sAR_KEY=array('oauth_token'=>'','oauth_token_secret'=>'',);
	
	public function getAuth(){
		//-- ------ ### ------ --
		$tmpSTR='';
		$tmpURL_Request='http://'.$this->sHOST.'cgi-bin/request_token';
		
		$tmpAR_Result=array('oauth_token'=>'','oauth_token_secret'=>'',);
		$tmpAR_Config=array(
			'oauth_callback'=>$this->sPAGE_Callback,
			'oauth_consumer_key'=>$this->sAPI_KEY,
			'oauth_nonce'=>md5(microtime().mt_rand()),
			'oauth_signature'=>'',
			'oauth_signature_method'=>'HMAC-SHA1',
			'oauth_timestamp'=>time(),
			'oauth_version'=>'1.0',
			);
		//-- ------ #Signature ------ --
		$tmpSTR=$this->sMethod.$this->sysSPLIT16.
			$this->urlencode_rfc3986($tmpURL_Request).$this->sysSPLIT16.
			$this->urlencode_rfc3986(
			'oauth_callback='.$this->urlencode_rfc3986($tmpAR_Config['oauth_callback']).$this->sysSPLIT16.
			'oauth_consumer_key='.$this->urlencode_rfc3986($tmpAR_Config['oauth_consumer_key']).$this->sysSPLIT16.
			'oauth_nonce='.$this->urlencode_rfc3986($tmpAR_Config['oauth_nonce']).$this->sysSPLIT16.
			'oauth_signature_method='.$this->urlencode_rfc3986($tmpAR_Config['oauth_signature_method']).$this->sysSPLIT16.
			'oauth_timestamp='.$this->urlencode_rfc3986($tmpAR_Config['oauth_timestamp']).$this->sysSPLIT16.
			'oauth_version='.$this->urlencode_rfc3986($tmpAR_Config['oauth_version']));
		$tmpAR_Config['oauth_signature']=base64_encode(hash_hmac('sha1',$tmpSTR,$this->sAPI_Secret.$this->sysSPLIT16,true));
		//-- ------ #REQUEST ------ --
		$tmpSTR=$tmpURL_Request.'?'.
			'oauth_callback='.$this->urlencode_rfc3986($tmpAR_Config['oauth_callback']).$this->sysSPLIT16.
			'oauth_consumer_key='.$this->urlencode_rfc3986($tmpAR_Config['oauth_consumer_key']).$this->sysSPLIT16.
			'oauth_nonce='.$this->urlencode_rfc3986($tmpAR_Config['oauth_nonce']).$this->sysSPLIT16.
			'oauth_signature='.$this->urlencode_rfc3986($tmpAR_Config['oauth_signature']).$this->sysSPLIT16.
			'oauth_signature_method='.$this->urlencode_rfc3986($tmpAR_Config['oauth_signature_method']).$this->sysSPLIT16.
			'oauth_timestamp='.$this->urlencode_rfc3986($tmpAR_Config['oauth_timestamp']).$this->sysSPLIT16.
			'oauth_version='.$this->urlencode_rfc3986($tmpAR_Config['oauth_version']);
		$tmpSTR=$this->readURL($tmpSTR);
		//-- ------ #REQUEST ------ --
		$tmpAR0=explode($this->sysSPLIT16,$tmpSTR);
		if (count($tmpAR0)==3) {
		}else {
			return 1;
		}
		$tmpAR1=explode('=',$tmpAR0[0]);
		if (count($tmpAR1)==2) {
		}else {
			return 1;
		}
		$tmpAR_Result['oauth_token']=$tmpAR1[1];
		$tmpAR1=explode('=',$tmpAR0[1]);
		if (count($tmpAR1)==2) {
		}else {
			return 1;
		}
		$tmpAR_Result['oauth_token_secret']=$tmpAR1[1];
		
		$this->sAR_KEY=$tmpAR_Result;
		return 0;
	}
	public function getLastKey($pToken,$pToken_secret,$pVerifier){
		//-- ------ ### ------ --
		$tmpSTR='';
		$tmpURL_Request='http://'.$this->sHOST.'cgi-bin/access_token';
		$tmpAR_Result=array('oauth_token'=>'','oauth_token_secret'=>'',);
		$tmpAR_Config=array(
			'oauth_consumer_key'=>$this->sAPI_KEY,
			'oauth_nonce'=>md5(microtime().mt_rand()),
			'oauth_signature'=>'',
			'oauth_signature_method'=>'HMAC-SHA1',
			'oauth_timestamp'=>time(),
			'oauth_token'=>$pToken,
			'oauth_verifier'=>$pVerifier,
			'oauth_version'=>'1.0',
			);
		//-- ------ #Signature ------ --
		$tmpSTR=$this->sMethod.$this->sysSPLIT16.
			$this->urlencode_rfc3986($tmpURL_Request).$this->sysSPLIT16.
			$this->urlencode_rfc3986(
			'oauth_consumer_key='.$this->urlencode_rfc3986($tmpAR_Config['oauth_consumer_key']).$this->sysSPLIT16.
			'oauth_nonce='.$this->urlencode_rfc3986($tmpAR_Config['oauth_nonce']).$this->sysSPLIT16.
			'oauth_signature_method='.$this->urlencode_rfc3986($tmpAR_Config['oauth_signature_method']).$this->sysSPLIT16.
			'oauth_timestamp='.$this->urlencode_rfc3986($tmpAR_Config['oauth_timestamp']).$this->sysSPLIT16.
			'oauth_token='.$this->urlencode_rfc3986($tmpAR_Config['oauth_token']).$this->sysSPLIT16.
			'oauth_verifier='.$this->urlencode_rfc3986($tmpAR_Config['oauth_verifier']).$this->sysSPLIT16.
			'oauth_version='.$this->urlencode_rfc3986($tmpAR_Config['oauth_version']));
		$tmpAR_Config['oauth_signature']=base64_encode(hash_hmac('sha1',$tmpSTR,$this->sAPI_Secret.$this->sysSPLIT16.$pToken_secret,true));
		//-- ------ #REQUEST ------ --
		$tmpSTR=$tmpURL_Request.'?'.
			'oauth_consumer_key='.$this->urlencode_rfc3986($tmpAR_Config['oauth_consumer_key']).$this->sysSPLIT16.
			'oauth_nonce='.$this->urlencode_rfc3986($tmpAR_Config['oauth_nonce']).$this->sysSPLIT16.
			'oauth_signature='.$this->urlencode_rfc3986($tmpAR_Config['oauth_signature']).$this->sysSPLIT16.
			'oauth_signature_method='.$this->urlencode_rfc3986($tmpAR_Config['oauth_signature_method']).$this->sysSPLIT16.
			'oauth_timestamp='.$this->urlencode_rfc3986($tmpAR_Config['oauth_timestamp']).$this->sysSPLIT16.
			'oauth_token='.$this->urlencode_rfc3986($tmpAR_Config['oauth_token']).$this->sysSPLIT16.
			'oauth_verifier='.$this->urlencode_rfc3986($tmpAR_Config['oauth_verifier']).$this->sysSPLIT16.
			'oauth_version='.$this->urlencode_rfc3986($tmpAR_Config['oauth_version']);
		$tmpSTR=$this->readURL($tmpSTR);
		//-- ------ #REQUEST ------ --
		$tmpAR0=explode($this->sysSPLIT16,$tmpSTR);
		if (count($tmpAR0)==3) {
		}else {
			return 1;
		}
		$tmpAR1=explode('=',$tmpAR0[0]);
		if (count($tmpAR1)==2) {
		}else {
			return 1;
		}
		$tmpAR_Result['oauth_token']=$tmpAR1[1];
		$tmpAR1=explode('=',$tmpAR0[1]);
		if (count($tmpAR1)==2) {
		}else {
			return 1;
		}
		$tmpAR_Result['oauth_token_secret']=$tmpAR1[1];
		
		$this->sAR_KEY=$tmpAR_Result;
		return 0;
	}
	public function getAuth_URL($pToken,$pToken_secret,$pURL){
		//-- ------ ### ------ --
		$tmpSTR='';
		$tmpURL_Request=$pURL;
		$tmpAR_Result=array('oauth_token'=>'','oauth_token_secret'=>'',);
		$tmpAR_Config=array(
			'oauth_consumer_key'=>$this->sAPI_KEY,
			'oauth_nonce'=>md5(microtime().mt_rand()),
			'oauth_signature'=>'',
			'oauth_signature_method'=>'HMAC-SHA1',
			'oauth_timestamp'=>time(),
			'oauth_token'=>$pToken,
			'oauth_version'=>'1.0',
			);
		//-- ------ #Signature ------ --
		$tmpSTR=$this->sMethod.$this->sysSPLIT16.
			$this->urlencode_rfc3986($tmpURL_Request).$this->sysSPLIT16.
			$this->urlencode_rfc3986(
			'oauth_consumer_key='.$this->urlencode_rfc3986($tmpAR_Config['oauth_consumer_key']).$this->sysSPLIT16.
			'oauth_nonce='.$this->urlencode_rfc3986($tmpAR_Config['oauth_nonce']).$this->sysSPLIT16.
			'oauth_signature_method='.$this->urlencode_rfc3986($tmpAR_Config['oauth_signature_method']).$this->sysSPLIT16.
			'oauth_timestamp='.$this->urlencode_rfc3986($tmpAR_Config['oauth_timestamp']).$this->sysSPLIT16.
			'oauth_token='.$this->urlencode_rfc3986($tmpAR_Config['oauth_token']).$this->sysSPLIT16.
			'oauth_version='.$this->urlencode_rfc3986($tmpAR_Config['oauth_version']));
		$tmpAR_Config['oauth_signature']=base64_encode(hash_hmac('sha1',$tmpSTR,$this->sAPI_Secret.$this->sysSPLIT16.$pToken_secret,true));
		//-- ------ #REQUEST ------ --
		$tmpSTR=$tmpURL_Request.''.
			'oauth_consumer_key='.$this->urlencode_rfc3986($tmpAR_Config['oauth_consumer_key']).$this->sysSPLIT16.
			'oauth_nonce='.$this->urlencode_rfc3986($tmpAR_Config['oauth_nonce']).$this->sysSPLIT16.
			'oauth_signature='.$this->urlencode_rfc3986($tmpAR_Config['oauth_signature']).$this->sysSPLIT16.
			'oauth_signature_method='.$this->urlencode_rfc3986($tmpAR_Config['oauth_signature_method']).$this->sysSPLIT16.
			'oauth_timestamp='.$this->urlencode_rfc3986($tmpAR_Config['oauth_timestamp']).$this->sysSPLIT16.
			'oauth_token='.$this->urlencode_rfc3986($tmpAR_Config['oauth_token']).$this->sysSPLIT16.
			'oauth_version='.$this->urlencode_rfc3986($tmpAR_Config['oauth_version']);

		return $tmpSTR;
	}

	public function getURL_Login(){
		$tmpURL='https://'.$this->sHOST.'cgi-bin/authorize?oauth_token={Nets.Auth}&oauth_callback={Nets.CallbackURL}';
		$tmpURL=str_replace('{Nets.Auth}',$this->sAR_KEY['oauth_token'],$tmpURL);
		$tmpURL=str_replace('{Nets.CallbackURL}',$this->sPAGE_Callback,$tmpURL);
		
		return $tmpURL;
	}
	public function getData_Credentials(){
		$tmpCONTENT='';
		$tmpURL='http://'.$this->sHOST.'api/user/info?format=xml&';
		$tmpURL=$this->getAuth_URL($this->sAR_KEY['oauth_token'],$this->sAR_KEY['oauth_token_secret'],$tmpURL);
		//exit($tmpURL);
		$tmpCONTENT=$this->readURL($tmpURL);
		
		return $tmpCONTENT;
	}
	
	
	
}
?>