<?php
class tqqPHP
{
function __co
nstruct($client_id, $client_secret, $access_token=NULL, $openid=NULL){
$this->client_id=$client_id;
$this->client_secret=$client_secret;
$this->access_token=$access_token;
$this->openid=$openid;
function login_url($callback_url){
'response_type'=>'code',
return 'https://open.t.qq.com/cgi-bin/oauth2/authorize?'.http_build_query($params);
function access_token($callback_url, $code){
'grant_type'=>'authorization_code',
'code'=>$code,
'client_secret'=>$this->client_secret,
function access_token_refresh($refresh_token){
'grant_type'=>'refresh_token',
'refresh_token'=>$refresh_token,
'client_id'=>$this->client_id
function me(){
$params=array();
$url='https://open.t.qq.com/api/user/info';
function getMyTweet($reqnum=10, $pageflag=0){
'pageflag'=>$pageflag,
'reqnum'=>$reqnum
$url='https://open.t.qq.com/api/statuses/broadcast_timeline';
function getRecount($ids){
'ids'=>$ids,
'flag'=>2
$url='https://open.t.qq.com/api/t/re_count';
function getReplay($id, $flag=0, $f=0, $n=10){
'rootid'=>$id,
'pageflag'=>$f,
'reqnum'=>$n,
'flag'=>$flag
$url='https://open.t.qq.com/api/t/re_list';
function postOne($img_c, $pic=''){
'content'=>$img_c
if($pic!='' && is_array($pic)){
$url='https://open.t.qq.com/api/t/add_pic';
$params['pic']=$pic;
$url='https://open.t.qq.com/api/t/add';
return $this->api($url, $params, 'POST');
function api($url, $params, $method='GET'){
$params['oauth_consumer_key']=$this->client_id;
$params['access_token']=$this->access_token;
$params['openid']=$this->openid;
$params['clientip']=$this->getIP();
$params['oauth_version']='2.a';
$params['format']='json';
$params['scope']='all';
if($method=='GET'){
$result_str=$this->http($url.'?'.http_build_query($params));
if(isset($params['pic'])){
uksort($params, 'strcmp');
$str_b=uniqid('------------------');
$str_m='--'.$str_b;
$str_e=$str_m. '--';
$body='';
foreach($params as $k=>$v){
if($k=='pic'){
if(is_array($v)){
$img_c=$v[2];
$img_n=$v[1];
}elseif($v{0}=='@'){
$url=ltri
m($v, '@');
$img_c=file_get_co
ntents($url);
$url_a=explode('?', ba
sename($url));
$img_n=$url_a[0];
$body.='Content-Disposition: form-data; name="'.$k.'"; filename="'.$img_n.'"'."
$body.="Content-Type: image/unknown
$body.=$img_c."
$body.='Content-Disposition: form-data; name="'.$k.""