新浪微博、腾讯微博、QQ、人人网、开心网、网易微博、豆瓣、百度、Google、微软、Instagram、Facebook、360、GitHub等平台的账号登录及api操作,使用oauth 2.0
官方提供的sdk都太过庞大,这是我自己简化的,提供简单的账号登录、获取个人信息、发布微博等功能,如果需要其他功能可以根据官方的api文档自行添加

2012-12-30:增加示例文件

2012-12-31:增加Facebook

2013-04-02:更新QQ、人人网、开心网、豆瓣、百度、Google、微软、Facebook

2013-05-09:增加GitHub

代码已提交到GIt @ OSC:http://git.oschina.net/piscdong/sns_php,这里将不再更新

源码与演示:源码出处

1. [文件] 新浪微博 ~ 4KB

<?php
/*** PHP Library for weibo.com** @author PiscDong (http://www.piscdong.com/)*/
class sinaPHP
{function __construct($client_id, $client_secret, $access_token=NULL){$this->client_id=$client_id;$this->client_secret=$client_secret;$this->access_token=$access_token;}function login_url($callback_url){$params=array('response_type'=>'code','client_id'=>$this->client_id,'redirect_uri'=>$callback_url);return 'https://api.weibo.com/oauth2/authorize?'.http_build_query($params);}function access_token($callback_url, $code){$params=array('grant_type'=>'authorization_code','code'=>$code,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret,'redirect_uri'=>$callback_url);$url='https://api.weibo.com/oauth2/access_token';return $this->http($url, http_build_query($params), 'POST');}/**function access_token_refresh($refresh_token){}**/function get_uid(){$params=array();$url='https://api.weibo.com/2/account/get_uid.json';return $this->api($url, $params);}function show_user_by_id($uid){$params=array('uid'=>$uid);$url='https://api.weibo.com/2/users/show.json';return $this->api($url, $params);}function statuses_count($ids){$params=array('ids'=>$ids);$url='https://api.weibo.com/2/statuses/count.json';return $this->api($url, $params);}function get_comments_by_sid($id, $count=10, $page=1){$params=array('id'=>$id,'page'=>$page,'count'=>$count);$url='https://api.weibo.com/2/comments/show.json';return $this->api($url, $params);}function repost_timeline($id, $count=10, $page=1){$params=array('id'=>$id,'page'=>$page,'count'=>$count);$url='https://api.weibo.com/2/statuses/repost_timeline.json';return $this->api($url, $params);}function update($img_c, $pic=''){$params=array('status'=>$img_c);if($pic!='' && is_array($pic)){$url='https://api.weibo.com/2/statuses/upload.json';$params['pic']=$pic;}else{$url='https://api.weibo.com/2/statuses/update.json';}return $this->api($url, $params, 'POST');}function user_timeline($uid, $count=10, $page=1){$params=array('uid'=>$uid,'page'=>$page,'count'=>$count);$url='https://api.weibo.com/2/statuses/user_timeline.json';return $this->api($url, $params);}function querymid($id, $type=1, $is_batch=0){$params=array('id'=>$id,'type'=>$type,'is_batch'=>$is_batch);$url='https://api.weibo.com/2/statuses/querymid.json';return $this->api($url, $params);}function api($url, $params, $method='GET'){$params['access_token']=$this->access_token;if($method=='GET'){$result=$this->http($url.'?'.http_build_query($params));}else{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=ltrim($v, '@');$img_c=file_get_contents($url);$url_a=explode('?', basename($url));$img_n=$url_a[0];}$body.=$str_m."\r\n";$body.='Content-Disposition: form-data; name="'.$k.'"; filename="'.$img_n.'"'."\r\n";$body.="Content-Type: image/unknown\r\n\r\n";$body.=$img_c."\r\n";}else{$body.=$str_m."\r\n";$body.='Content-Disposition: form-data; name="'.$k."\"\r\n\r\n";$body.=$v."\r\n";}}$body.=$str_e;$headers[]="Content-Type: multipart/form-data; boundary=".$str_b;$result=$this->http($url, $body, 'POST', $headers);}else{$result=$this->http($url, http_build_query($params), 'POST');}}return $result;}function http($url, $postfields='', $method='GET', $headers=array()){$ci=curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method=='POST'){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!='')curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]="User-Agent: sinaPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response=curl_exec($ci);curl_close($ci);$json_r=array();if($response!='')$json_r=json_decode($response, true);return $json_r;}
}

2. [文件] 腾讯微博 ~ 5KB

<?php
/*** PHP Library for t.qq.com** @author PiscDong (http://www.piscdong.com/)*/
class tqqPHP
{function __construct($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){$params=array('response_type'=>'code','client_id'=>$this->client_id,'redirect_uri'=>$callback_url);return 'https://open.t.qq.com/cgi-bin/oauth2/authorize?'.http_build_query($params);}function access_token($callback_url, $code){$params=array('grant_type'=>'authorization_code','code'=>$code,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret,'redirect_uri'=>$callback_url);$url='https://open.t.qq.com/cgi-bin/oauth2/access_token?'.http_build_query($params);$result_str=$this->http($url);$json_r=array();if($result_str!='')parse_str($result_str, $json_r);return $json_r;}function access_token_refresh($refresh_token){$params=array('grant_type'=>'refresh_token','refresh_token'=>$refresh_token,'client_id'=>$this->client_id);$url='https://open.t.qq.com/cgi-bin/oauth2/access_token?'.http_build_query($params);$result_str=$this->http($url);$json_r=array();if($result_str!='')parse_str($result_str, $json_r);return $json_r;}function me(){$params=array();$url='https://open.t.qq.com/api/user/info';return $this->api($url, $params);}function getgetMyTweet($reqnum=10, $pageflag=0){$params=array('pageflag'=>$pageflag,'reqnum'=>$reqnum);$url='https://open.t.qq.com/api/statuses/broadcast_timeline';return $this->api($url, $params);}function getRecount($ids){$params=array('ids'=>$ids,'flag'=>2);$url='https://open.t.qq.com/api/t/re_count';return $this->api($url, $params);}function getReplay($id, $flag=0, $f=0, $n=10){$params=array('rootid'=>$id,'pageflag'=>$f,'reqnum'=>$n,'flag'=>$flag);$url='https://open.t.qq.com/api/t/re_list';return $this->api($url, $params);}function postOne($img_c, $pic=''){$params=array('content'=>$img_c);if($pic!='' && is_array($pic)){$url='https://open.t.qq.com/api/t/add_pic';$params['pic']=$pic;}else{$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));}else{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=ltrim($v, '@');$img_c=file_get_contents($url);$url_a=explode('?', basename($url));$img_n=$url_a[0];}$body.=$str_m."\r\n";$body.='Content-Disposition: form-data; name="'.$k.'"; filename="'.$img_n.'"'."\r\n";$body.="Content-Type: image/unknown\r\n\r\n";$body.=$img_c."\r\n";}else{$body.=$str_m."\r\n";$body.='Content-Disposition: form-data; name="'.$k."\"\r\n\r\n";$body.=$v."\r\n";}}$body.=$str_e;$headers[]="Content-Type: multipart/form-data; boundary=".$str_b;$result_str=$this->http($url, $body, 'POST', $headers);}else{$result_str=$this->http($url, http_build_query($params), 'POST');}}$json_r=array();if($result_str!='')$json_r=json_decode($result_str, true);return $json_r;}function getIP(){if(isset($_ENV['HTTP_CLIENT_IP'])){$ip=$_ENV['HTTP_CLIENT_IP'];}elseif(isset($_ENV['HTTP_X_FORWARDED_FOR'])){$ip=$_ENV['HTTP_X_FORWARDED_FOR'];}elseif(isset($_ENV['REMOTE_ADDR'])){$ip=$_ENV['REMOTE_ADDR'];}else{$ip=$_SERVER['REMOTE_ADDR'];}if(strstr($ip, ':')){$ipa=explode(':', $ip);foreach($ipa as $v){if(strlen($v)>7)$ip=$v;}}if(strlen($ip)<7)$ip='0.0.0.0';return $ip;}function http($url, $postfields='', $method='GET', $headers=array()){$ci=curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method=='POST'){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!='')curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]="User-Agent: tqqPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response=curl_exec($ci);curl_close($ci);return $response;}
}

3. [文件] QQ ~ 3KB

<?php
/*** PHP Library for qq.com** @author PiscDong (http://www.piscdong.com/)*/
class qqPHP
{function __construct($appid, $appkey, $access_token=NULL){$this->appid=$appid;$this->appkey=$appkey;$this->access_token=$access_token;}function login_url($callback_url, $scope=''){$params=array('client_id'=>$this->appid,'redirect_uri'=>$callback_url,'response_type'=>'code','scope'=>$scope);return 'https://graph.qq.com/oauth2.0/authorize?'.http_build_query($params);}function access_token($callback_url, $code){$params=array('grant_type'=>'authorization_code','client_id'=>$this->appid,'client_secret'=>$this->appkey,'code'=>$code,'state'=>'','redirect_uri'=>$callback_url);$url='https://graph.qq.com/oauth2.0/token?'.http_build_query($params);$result_str=$this->http($url);$json_r=array();if($result_str!='')parse_str($result_str, $json_r);return $json_r;}/**function access_token_refresh($refresh_token){}**/function get_openid(){$params=array('access_token'=>$this->access_token);$url='https://graph.qq.com/oauth2.0/me?'.http_build_query($params);$result_str=$this->http($url);$json_r=array();if($result_str!=''){preg_match('/callback\(\s+(.*?)\s+\)/i', $result_str, $result_a);$json_r=json_decode($result_a[1], true);}return $json_r;}function get_user_info($openid){$params=array('openid'=>$openid);$url='https://graph.qq.com/user/get_user_info';return $this->api($url, $params);}function add_share($openid, $title, $url, $site, $fromurl, $images='', $summary=''){$params=array('openid'=>$openid,'title'=>$title,'url'=>$url,'site'=>$site,'fromurl'=>$fromurl,'images'=>$images,'summary'=>$summary);$url='https://graph.qq.com/share/add_share';return $this->api($url, $params, 'POST');}function api($url, $params, $method='GET'){$params['access_token']=$this->access_token;$params['oauth_consumer_key']=$this->appid;$params['format']='json';if($method=='GET'){$result_str=$this->http($url.'?'.http_build_query($params));}else{$result_str=$this->http($url, http_build_query($params), 'POST');}$result=array();if($result_str!='')$result=json_decode($result_str, true);return $result;}function http($url, $postfields='', $method='GET', $headers=array()){$ci=curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method=='POST'){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!='')curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]="User-Agent: qqPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response=curl_exec($ci);curl_close($ci);return $response;}
}

4. [文件] 人人网 ~ 3KB

<?php
/*** PHP Library for renren.com** @author PiscDong (http://www.piscdong.com/)*/
class renrenPHP
{function __construct($client_id, $client_secret, $access_token=NULL){$this->client_id=$client_id;$this->client_secret=$client_secret;$this->access_token=$access_token;}function login_url($callback_url, $scope=''){$params=array('response_type'=>'code','client_id'=>$this->client_id,'redirect_uri'=>$callback_url,'scope'=>$scope);return 'https://graph.renren.com/oauth/authorize?'.http_build_query($params);}function access_token($callback_url, $code){$params=array('grant_type'=>'authorization_code','code'=>$code,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret,'redirect_uri'=>$callback_url);$url='https://graph.renren.com/oauth/token';return $this->http($url, http_build_query($params), 'POST');}function access_token_refresh($refresh_token){$params=array('grant_type'=>'refresh_token','refresh_token'=>$refresh_token,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret);$url='https://graph.renren.com/oauth/token';return $this->http($url, http_build_query($params), 'POST');}function me(){$params=array();return $this->api('users.getInfo', $params, 'POST');}function setStatus($status){$params=array('status'=>$status);return $this->api('status.set', $params, 'POST');}function getStatus($uid, $count=10, $page=1){$params=array('uid'=>$uid,'page'=>$page,'count'=>$count);return $this->api('status.gets', $params, 'POST');}function addBlog($title, $content){$params=array('title'=>$title,'content'=>$content);return $this->api('blog.addBlog', $params, 'POST');}function getBlog($id, $uid){$params=array('id'=>$id,'uid'=>$uid);return $this->api('blog.get', $params, 'POST');}function getComments($id, $uid, $count=10, $page=1){$params=array('id'=>$id,'uid'=>$uid,'page'=>$page,'count'=>$count);return $this->api('blog.getComments', $params, 'POST');}function api($method_name, $params, $method='GET'){$params['method']=$method_name;$params['v']='1.0';$params['access_token']=$this->access_token;$params['format']='json';ksort($params);$sig_str='';foreach($params as $k=>$v)$sig_str.=$k.'='.$v;$sig_str.=$this->client_secret;$sig=md5($sig_str);$params['sig']=$sig;$url='http://api.renren.com/restserver.do';if($method=='GET'){$result=$this->http($url.'?'.http_build_query($params));}else{$result=$this->http($url, http_build_query($params), 'POST');}return $result;}function http($url, $postfields='', $method='GET', $headers=array()){$ci=curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method=='POST'){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!='')curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]="User-Agent: renrenPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response=curl_exec($ci);curl_close($ci);$json_r=array();if($response!='')$json_r=json_decode($response, true);return $json_r;}
}

5. [文件] 开心网 ~ 3KB

<?php
/*** PHP Library for kaixin001.com** @author PiscDong (http://www.piscdong.com/)*/
class kaixinPHP
{function __construct($client_id, $client_secret, $access_token=NULL){$this->client_id=$client_id;$this->client_secret=$client_secret;$this->access_token=$access_token;}function login_url($callback_url, $scope=''){$params=array('response_type'=>'code','client_id'=>$this->client_id,'redirect_uri'=>$callback_url,'scope'=>$scope);return 'http://api.kaixin001.com/oauth2/authorize?'.http_build_query($params);}function access_token($callback_url, $code){$params=array('grant_type'=>'authorization_code','code'=>$code,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret,'redirect_uri'=>$callback_url);$url='https://api.kaixin001.com/oauth2/access_token';return $this->http($url, http_build_query($params), 'POST');}function access_token_refresh($refresh_token){$params=array('grant_type'=>'refresh_token','refresh_token'=>$refresh_token,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret);$url='https://api.kaixin001.com/oauth2/access_token';return $this->http($url, http_build_query($params), 'POST');}function me(){$params=array();$url='https://api.kaixin001.com/users/me.json';return $this->api($url, $params);}function records_add($content, $picurl=''){$params=array('content'=>$content);if($picurl!='')$params['picurl']=$picurl;$url='https://api.kaixin001.com/records/add.json';return $this->api($url, $params, 'POST');}function records_me($num=10, $start=0){$params=array('start'=>$start,'num'=>$num);$url='https://api.kaixin001.com/records/me.json';return $this->api($url, $params);}function comment_list($id, $uid, $num=10, $start=0){$params=array('objtype'=>'records','objid'=>$id,'ouid'=>$uid,'start'=>$start,'num'=>$num);$url='https://api.kaixin001.com/comment/list.json';return $this->api($url, $params);}function forward_list($id, $uid, $num=10, $start=0){$params=array('objtype'=>'records','objid'=>$id,'ouid'=>$uid,'start'=>$start,'num'=>$num);$url='https://api.kaixin001.com/forward/list.json';return $this->api($url, $params);}function like_show($id, $uid, $num=10, $start=0){$params=array('objtype'=>'records','objid'=>$id,'ouid'=>$uid,'start'=>$start,'num'=>$num);$url='https://api.kaixin001.com/like/show.json';return $this->api($url, $params);}function api($url, $params, $method='GET'){$params['access_token']=$this->access_token;if($method=='GET'){$result=$this->http($url.'?'.http_build_query($params));}else{$result=$this->http($url, http_build_query($params), 'POST');}return $result;}function http($url, $postfields='', $method='GET', $headers=array()){$ci=curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method=='POST'){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!='')curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]="User-Agent: kaixinPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response=curl_exec($ci);curl_close($ci);$json_r=array();if($response!='')$json_r=json_decode($response, true);return $json_r;}
}

6. [文件] 网易微博 ~ 3KB

<?php
/*** PHP Library for t.163.com** @author PiscDong (http://www.piscdong.com/)*/
class t163PHP
{function __construct($client_id, $client_secret, $access_token=NULL){$this->client_id=$client_id;$this->client_secret=$client_secret;$this->access_token=$access_token;}function login_url($callback_url){$params=array('response_type'=>'code','client_id'=>$this->client_id,'redirect_uri'=>$callback_url);return 'https://api.t.163.com/oauth2/authorize?'.http_build_query($params);}function access_token($callback_url, $code){$params=array('grant_type'=>'authorization_code','code'=>$code,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret,'redirect_uri'=>$callback_url);$url='https://api.t.163.com/oauth2/access_token';return $this->http($url, http_build_query($params), 'POST');}function access_token_refresh($refresh_token){$params=array('grant_type'=>'refresh_token','refresh_token'=>$refresh_token,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret);$url='https://api.t.163.com/oauth2/access_token';return $this->http($url, http_build_query($params), 'POST');}function me(){$params=array();$url='https://api.t.163.com/users/show.json';return $this->api($url, $params);}function user_timeline($id, $count=10){$params=array('user_id'=>$id,'count'=>$count);$url='https://api.t.163.com/statuses/user_timeline.json';return $this->api($url, $params);}function update($status){$params=array('status'=>$status);$url='https://api.t.163.com/statuses/update.json';return $this->api($url, $params, 'POST');}function api($url, $params, $method='GET'){$params['access_token']=$this->access_token;if($method=='GET'){$result=$this->http($url.'?'.http_build_query($params));}else{$result=$this->http($url, http_build_query($params), 'POST');}return $result;}function http($url, $postfields='', $method='GET', $headers=array()){$ci=curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method=='POST'){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!='')curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]="User-Agent: t163PHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response=curl_exec($ci);curl_close($ci);$json_r=array();if($response!='')$json_r=json_decode($response, true);return $json_r;}
}

7. [文件] 豆瓣 ~ 3KB

<?php
/*** PHP Library for douban.com** @author PiscDong (http://www.piscdong.com/)*/
class doubanPHP
{function __construct($client_id, $client_secret, $access_token=NULL){$this->client_id=$client_id;$this->client_secret=$client_secret;$this->access_token=$access_token;}function login_url($callback_url, $scope=''){$params=array('response_type'=>'code','client_id'=>$this->client_id,'redirect_uri'=>$callback_url,'scope'=>$scope,'state'=>md5(time()));return 'https://www.douban.com/service/auth2/auth?'.http_build_query($params);}function access_token($callback_url, $code){$params=array('grant_type'=>'authorization_code','code'=>$code,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret,'redirect_uri'=>$callback_url);$url='https://www.douban.com/service/auth2/token';return $this->http($url, http_build_query($params), 'POST');}function access_token_refresh($callback_url, $refresh_token){$params=array('grant_type'=>'refresh_token','refresh_token'=>$refresh_token,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret,'redirect_uri'=>$callback_url);$url='https://www.douban.com/service/auth2/token';return $this->http($url, http_build_query($params), 'POST');}function me(){$params=array();$url='https://api.douban.com/v2/user/~me';return $this->api($url, $params);}function share($text, $title, $url, $description='', $pic=''){$params=array('text'=>$text,'rec_title'=>$title,'rec_url'=>$url,'rec_desc'=>$description,'rec_image'=>$pic);$url='https://api.douban.com/shuo/v2/statuses/';return $this->api($url, $params, 'POST');}function api($url, $params, $method='GET'){$headers[]="Authorization: Bearer ".$this->access_token;if($method=='GET'){$result=$this->http($url.'?'.http_build_query($params), '', 'GET', $headers);}else{$result=$this->http($url, http_build_query($params), 'POST', $headers);}return $result;}function http($url, $postfields='', $method='GET', $headers=array()){$ci=curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method=='POST'){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!='')curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]="User-Agent: doubanPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response=curl_exec($ci);curl_close($ci);$json_r=array();if($response!='')$json_r=json_decode($response, true);return $json_r;}
}

8. [文件] 百度 ~ 2KB

<?php
/*** PHP Library for baidu.com** @author PiscDong (http://www.piscdong.com/)*/
class baiduPHP
{function __construct($client_id, $client_secret, $access_token=NULL){$this->client_id=$client_id;$this->client_secret=$client_secret;$this->access_token=$access_token;}function login_url($callback_url, $scope=''){$params=array('response_type'=>'code','client_id'=>$this->client_id,'redirect_uri'=>$callback_url,'scope'=>$scope,'state'=>md5(time()),'display'=>'page');return 'https://openapi.baidu.com/oauth/2.0/authorize?'.http_build_query($params);}function access_token($callback_url, $code){$params=array('grant_type'=>'authorization_code','code'=>$code,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret,'redirect_uri'=>$callback_url);$url='https://openapi.baidu.com/oauth/2.0/token';return $this->http($url, http_build_query($params), 'POST');}function access_token_refresh($refresh_token){$params=array('grant_type'=>'refresh_token','refresh_token'=>$refresh_token,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret);$url='https://openapi.baidu.com/oauth/2.0/token';return $this->http($url, http_build_query($params), 'POST');}function user(){$params=array();$url='https://openapi.baidu.com/rest/2.0/passport/users/getLoggedInUser';return $this->api($url, $params);}function api($url, $params, $method='GET'){$params['access_token']=$this->access_token;if($method=='GET'){$result=$this->http($url.'?'.http_build_query($params));}else{$result=$this->http($url, http_build_query($params), 'POST');}return $result;}function http($url, $postfields='', $method='GET', $headers=array()){$ci=curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method=='POST'){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!='')curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]="User-Agent: baiduPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response=curl_exec($ci);curl_close($ci);$json_r=array();if($response!='')$json_r=json_decode($response, true);return $json_r;}
}

9. [文件] Google ~ 2KB

<?php
/*** PHP Library for google.com** @author PiscDong (http://www.piscdong.com/)*/
class googlePHP
{function __construct($client_id, $client_secret, $access_token=NULL){$this->client_id=$client_id;$this->client_secret=$client_secret;$this->access_token=$access_token;}function login_url($callback_url, $scope=''){$params=array('response_type'=>'code','client_id'=>$this->client_id,'redirect_uri'=>$callback_url,'scope'=>$scope,'state'=>'profile','access_type'=>'offline');return 'https://accounts.google.com/o/oauth2/auth?'.http_build_query($params);}function access_token($callback_url, $code){$params=array('grant_type'=>'authorization_code','code'=>$code,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret,'redirect_uri'=>$callback_url);$url='https://accounts.google.com/o/oauth2/token';$result=$this->http($url, http_build_query($params), 'POST');return $result;}function access_token_refresh($refresh_token){$params=array('grant_type'=>'refresh_token','refresh_token'=>$refresh_token,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret);$url='https://accounts.google.com/o/oauth2/token';$result=$this->http($url, http_build_query($params), 'POST');return $result;}function me(){$params=array();$url='https://www.googleapis.com/oauth2/v1/userinfo';return $this->api($url, $params);}function api($url, $params, $method='GET'){$headers[]="Authorization: Bearer ".$this->access_token;if($method=='GET'){$result=$this->http($url.'?'.http_build_query($params), '', 'GET', $headers);}else{$result=$this->http($url, http_build_query($params), 'POST', $headers);}return $result;}function http($url, $postfields='', $method='GET', $headers=array()){$ci=curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method=='POST'){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!='')curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]="User-Agent: google(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response=curl_exec($ci);curl_close($ci);$json_r=array();if($response!='')$json_r=json_decode($response, true);return $json_r;}
}

10. [文件] 微软 ~ 2KB

<?php
/*** PHP Library for live.com** @author PiscDong (http://www.piscdong.com/)*/
class livePHP
{function __construct($client_id, $client_secret, $access_token=NULL){$this->client_id=$client_id;$this->client_secret=$client_secret;$this->access_token=$access_token;}function login_url($callback_url, $scope=''){$params=array('response_type'=>'code','client_id'=>$this->client_id,'redirect_uri'=>$callback_url,'scope'=>$scope);return 'https://login.live.com/oauth20_authorize.srf?'.http_build_query($params);}function access_token($callback_url, $code){$params=array('grant_type'=>'authorization_code','code'=>$code,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret,'redirect_uri'=>$callback_url);$url='https://login.live.com/oauth20_token.srf';return $this->http($url, http_build_query($params), 'POST');}function access_token_refresh($refresh_token){$params=array('grant_type'=>'refresh_token','refresh_token'=>$refresh_token,'client_secret'=>$this->client_secret,'client_id'=>$this->client_id);$url='https://login.live.com/oauth20_token.srf';return $this->http($url, http_build_query($params), 'POST');}function me(){$params=array();$url='https://apis.live.net/v5.0/me';return $this->api($url, $params);}function api($url, $params, $method='GET'){$params['access_token']=$this->access_token;if($method=='GET'){$result=$this->http($url.'?'.http_build_query($params));}else{$result=$this->http($url, http_build_query($params), 'POST');}return $result;}function http($url, $postfields='', $method='GET', $headers=array()){$ci=curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method=='POST'){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!='')curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]="User-Agent: livePHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response=curl_exec($ci);curl_close($ci);$json_r=array();if($response!='')$json_r=json_decode($response, true);return $json_r;}
}

11. [文件] Instagram ~ 2KB

<?php
/*** PHP Library for instagram.com** @author PiscDong (http://www.piscdong.com/)*/
class instagramPHP
{function __construct($client_id, $client_secret, $access_token=NULL){$this->client_id=$client_id;$this->client_secret=$client_secret;$this->access_token=$access_token;}function login_url($callback_url){$params=array('response_type'=>'code','client_id'=>$this->client_id,'redirect_uri'=>$callback_url);return 'https://api.instagram.com/oauth/authorize/?'.http_build_query($params);}function access_token($callback_url, $code){$params=array('grant_type'=>'authorization_code','code'=>$code,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret,'redirect_uri'=>$callback_url);$url='https://api.instagram.com/oauth/access_token';return $this->http($url, http_build_query($params), 'POST');}/**function access_token_refresh($refresh_token){}**/function user($id){$params=array();$url='https://api.instagram.com/v1/users/'.$id.'/';return $this->api($url, $params);}function user_media($id, $count=10, $max_id=''){$params=array('count'=>$count);if($max_id!='')$params['max_id']=$max_id;$url='https://api.instagram.com/v1/users/'.$id.'/media/recent/';return $this->api($url, $params);}function api($url, $params, $method='GET'){$params['access_token']=$this->access_token;if($method=='GET'){$result=$this->http($url.'?'.http_build_query($params));}else{$result=$this->http($url, http_build_query($params), 'POST');}return $result;}function http($url, $postfields='', $method='GET', $headers=array()){$ci=curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method=='POST'){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!='')curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]="User-Agent: instagramPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response=curl_exec($ci);curl_close($ci);$json_r=array();if($response!='')$json_r=json_decode($response, true);return $json_r;}
}

12. [文件] Facebook ~ 2KB

<?php
/*** PHP Library for facebook.com** @author PiscDong (http://www.piscdong.com/)*/
class facebookPHP
{function __construct($client_id, $client_secret, $access_token=NULL){$this->client_id=$client_id;$this->client_secret=$client_secret;$this->access_token=$access_token;}function login_url($callback_url, $scope=''){$params=array('response_type'=>'code','client_id'=>$this->client_id,'redirect_uri'=>$callback_url,'scope'=>$scope);return 'https://graph.facebook.com/oauth/authorize?'.http_build_query($params);}function access_token($callback_url, $code){$params=array('grant_type'=>'authorization_code','code'=>$code,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret,'redirect_uri'=>$callback_url);$url='https://graph.facebook.com/oauth/access_token';return $this->http($url, http_build_query($params), 'POST');}/**function access_token_refresh($refresh_token){}**/function me(){$params=array();$url='https://graph.facebook.com/me';return $this->api($url, $params);}function my_feed($count=10, $page=1){$params=array('page'=>$page,'count'=>$count);$url='https://graph.facebook.com/me/feed';return $this->api($url, $params);}function update($content){$params=array('message'=>$content);$url='https://graph.facebook.com/me/feed/';return $this->api($url, $params, 'POST');}function api($url, $params, $method='GET'){$params['access_token']=$this->access_token;if($method=='GET'){$result=$this->http($url.'?'.http_build_query($params));}else{$result=$this->http($url, http_build_query($params), 'POST');}return $result;}function http($url, $postfields='', $method='GET', $headers=array()){$ci=curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method=='POST'){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!='')curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]="User-Agent: facebookPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response=curl_exec($ci);curl_close($ci);$json_r=array();if($response!='')$json_r=json_decode($response, true);return $json_r;}
}

13. [文件] 360 ~ 2KB

<?php
/*** PHP Library for 360.cn** @author PiscDong (http://www.piscdong.com/)*/
class o360PHP
{function __construct($client_id, $client_secret, $access_token=NULL){$this->client_id=$client_id;$this->client_secret=$client_secret;$this->access_token=$access_token;}function login_url($callback_url){$params=array('response_type'=>'code','client_id'=>$this->client_id,'redirect_uri'=>$callback_url);return 'https://openapi.360.cn/oauth2/authorize?'.http_build_query($params);}function access_token($callback_url, $code){$params=array('grant_type'=>'authorization_code','code'=>$code,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret,'redirect_uri'=>$callback_url);$url='https://openapi.360.cn/oauth2/access_token';return $this->http($url, http_build_query($params), 'POST');}function access_token_refresh($refresh_token){$params=array('grant_type'=>'refresh_token','refresh_token'=>$refresh_token,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret);$url='https://openapi.360.cn/oauth2/access_token';return $this->http($url, http_build_query($params), 'POST');}function me(){$params=array();$url='https://openapi.360.cn/user/me.json';return $this->api($url, $params);}function api($url, $params, $method='GET'){$params['access_token']=$this->access_token;if($method=='GET'){$result=$this->http($url.'?'.http_build_query($params));}else{$result=$this->http($url, http_build_query($params), 'POST');}return $result;}function http($url, $postfields='', $method='GET', $headers=array()){$ci=curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method=='POST'){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!='')curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]="User-Agent: o360PHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response=curl_exec($ci);curl_close($ci);$json_r=array();if($response!='')$json_r=json_decode($response, true);return $json_r;}
}

14. [文件] github.php ~ 2KB

<?php
/*** PHP Library for github.com** @author PiscDong (http://www.piscdong.com/)*/
class githubPHP
{function __construct($client_id, $client_secret, $access_token=NULL){$this->client_id=$client_id;$this->client_secret=$client_secret;$this->access_token=$access_token;}function login_url($callback_url, $scope=''){$params=array('client_id'=>$this->client_id,'redirect_uri'=>$callback_url,'scope'=>$scope);return 'https://github.com/login/oauth/authorize?'.http_build_query($params);}function access_token($callback_url, $code){$params=array('code'=>$code,'client_id'=>$this->client_id,'client_secret'=>$this->client_secret,'redirect_uri'=>$callback_url);$url='https://github.com/login/oauth/access_token';$result_str=$this->http($url, http_build_query($params), 'POST');$json_r=array();if($result_str!='')parse_str($result_str, $json_r);return $json_r;}/**function access_token_refresh($refresh_token){}**/function me(){$params=array();$url='https://api.github.com/user';return $this->api($url, $params);}function api($url, $params, $method='GET'){$params['access_token']=$this->access_token;if($method=='GET'){$result_str=$this->http($url.'?'.http_build_query($params));}else{$result_str=$this->http($url, http_build_query($params), 'POST');}$result=array();if($result_str!='')$result=json_decode($result_str, true);return $result;}function http($url, $postfields='', $method='GET', $headers=array()){$ci=curl_init();curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);curl_setopt($ci, CURLOPT_TIMEOUT, 30);if($method=='POST'){curl_setopt($ci, CURLOPT_POST, TRUE);if($postfields!='')curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);}$headers[]="User-Agent: githubPHP(piscdong.com)";curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);curl_setopt($ci, CURLOPT_URL, $url);$response=curl_exec($ci);curl_close($ci);return $response;}
}

15. [代码]示例文件,以新浪微博为例,其他平台方法类似

/*** 示例文件,以新浪微博为例,其他平台方法类似*///生成登录链接
require_once('sina.php');
$app_key=''; //新浪微博应用App Key
$app_secret=''; //新浪微博应用App Secret
$callback_url='http://yoururl/sina_callback.php'; //回调网址,请根据自己的实际情况修改$sina=new sinaPHP($app_key, $app_secret);
$login_url=$sina->login_url($callback_url); //生成登录链接,部分平台需要权限,格式请参考各平台api文档
echo '<a href="'.$login_url.'">点击进入授权页面</a>';//授权回调页面,即生成登录链接时的$callback_url
require_once('sina.php');
$app_key=''; //新浪微博应用App Key
$app_secret=''; //新浪微博应用App Secret
$callback_url='http://yoururl/sina_callback.php'; //回调网址,必须和生成登录链接时相同if(isset($_GET['code']) && $_GET['code']!=''){$sina=new sinaPHP($app_key, $app_secret);$result=$sina->access_token($callback_url, $_GET['code']); //获取access token/*** $result['access_token'],用户access token* $result['expires_in'],access token的有效期,单位:秒* 部分平台会有$result['refresh_token'],refresh token,access token到期后使用refresh token生成新的access token* 腾讯微博还需要保存$_GET['openid']*/
}//用户登录授权后操作api
require_once('sina.php');
$app_key=''; //新浪微博应用App Key
$app_secret=''; //新浪微博应用App Secret
$access_token=''; //授权回调页面生成的用户access token$sina=new sinaPHP($app_key, $app_secret, $access_token); //腾讯微博还需要openid,授权回调页面保存的$_GET['openid']$sina_uid=$sina->get_uid(); //登录用户uid
//其他功能请参考sina.php自行使用,或者根据api文档自行添加
//其他平台的使用方法和新浪微博类似,各种api的返回数据格式各有不同,请自行参考各平台的api文档//支持refresh token的平台在access token到期后请使用access_token_refresh()生成新的access token

来源:http://www.oschina.net/code/snippet_930167_16877#28044

部分主流sns平台的账号登录及api操作相关推荐

  1. php使用QQ登录API,QQ的账号登录及api操作

    QQ的账号登录及api操作,使用oauth 2.0 官方提供的sdk都太过庞大,这是我自己简化的,提供简单的账号登录.获取个人信息.发布分享等功能,如果需要其他功能可以根据官方的api文档自行添加 q ...

  2. 谷歌账号登录Google API Oauth 2.0简单申请和使用教程

    在点击编辑,修改回调URL 编辑完后可以参照google开发文档开发 https://developers.google.com/accounts/docs/OAuth2?hl=zh-CN 然后按照需 ...

  3. QQ,新浪,SNS等公众平台的登录及api操作

    QQ的写法地址:http://www.oschina.net/code/snippet_930167_19888 Sina的写法地址:http://www.oschina.net/code/snipp ...

  4. php 豆瓣api_豆瓣的账号登录及PHP api操作

    豆瓣 的账号登录及api操作,使用oauth 2.0 官方提供的sdk都太过庞大,这是我自己简化的,提供简单的账号登录.获取个人信息.发布分享等功能,如果需要其他功能可以根据官方的api文档自行添加 ...

  5. php使用qq登录api接口,QQ的账号登录及PHP api操作

    QQ的账号登录及api操作,使用oauth 2.0官方提供的sdk都太过庞大,这是我自己简化的,提供简单的账号登录.获取个人信息.发布分享等功能,如果需要其他功能可以根据官方的api文档自行添加[文件 ...

  6. php新浪微博 登录接口文档,新浪微博的账号登录及PHP api操作

    新浪微博 的账号登录及api操作,使用oauth 2.0 官方提供的sdk都太过庞大,这是我自己简化的,提供简单的账号登录.获取个人信息.发布微博等功能,如果需要其他功能可以根据官方的api文档自行添 ...

  7. QQ的账号登录及PHP api操作

    QQ的账号登录及api操作,使用oauth 2.0     官方提供的sdk都太过庞大,这是我自己简化的,提供简单的账号登录.获取个人信息.发布分享等功能,如果需要其他功能可以根据官方的api文档自行 ...

  8. 「GitLab篇」如何用Git平台账号登录建木CI

    介绍 继上一篇博客「Gitee篇」如何用Git平台账号登录建木CI发布后,得到了很多小伙伴们的关注,我趁热打铁推出了如何用Git平台账号登录建木CI 系列的第二篇 「GitLab篇」如何用Git平台账 ...

  9. 「Gitea篇」如何用Git平台账号登录建木CI

    介绍 这是<如何用Git平台账号登录建木CI>系列文章的第三篇,建木CI立志整合所有第三方Git平台来登录建木CI!此篇我们将整合Gitea平台来登录建木CI. ‍自v2.5.4版本开始, ...

最新文章

  1. 使用hello word写小说
  2. SpringBoot框架:入门篇
  3. ASP.NET MVC和jQuery DataTable整合
  4. Building Shops dp 预处理距离
  5. 无障碍开发(八)之盲人如何使用互联网的8个误区
  6. matlab 时序数据,9 个 MATLAB 数据科学速查表 - MATLAB Simulink
  7. go struct 静态函数_Go语言学习笔记(四)结构体struct 接口Interface 反射reflect...
  8. Handsontable 自定义菜单 自定义命令存放位置
  9. linux随手笔记(Centos为主)
  10. Nginx源码安装(CentOS7)
  11. 迅雷mac版精简安装教程
  12. 软件测试的需求人才越来越多,为什么大家还是不太愿意走软件测试的道路?
  13. My Sixteenth Page - 四数相加 - By Nicolas
  14. 一张图解释DNS域名服务器的作用
  15. winform键盘操控之组合键
  16. 2018 银联Java笔试 题,中国银联2018秋招笔试题
  17. 潘正磊谈微软研发团队管理之道
  18. Java: Tomcat到底是干嘛的?
  19. 【QT Graphics/View】自定义动态矩形框DyRectangle
  20. 2021年美赛准备(学习笔记) 2016年C题优质基金挑战

热门文章

  1. python怎么对文件行排序_使用Python对文本文件进行排序
  2. VMware内虚拟机自适应及最大化窗口调整方式
  3. MFC对话框动态刷新图片(仿照全屏屏保)
  4. 递归调用层数太多_VBA学习笔记46:组合之递归算法(没写后补)
  5. 计算机软件不是出租的主要标的时著作权,著作权中出租权的适用对象有哪些?...
  6. 3-40HDFS读数据流程
  7. 常见HTTP状态(404,500等)
  8. docker公共存储库_Docker入门(2)——镜像结构和私有镜像库
  9. vue工程打包上线样式错乱问题 - bug解决(4种)
  10. Do not use built-in or reserved HTML elements as component id等等vue warn问题