新浪微博的登录
前提条件是需要实现两个文件 saetv2.ex.class.PHP 和 同级目录的config.php
saetv2.ex.class.php代码 百度一下 自己下载就行
config.php需要自己配置
- define( "WB_AKEY" , '********' );//这个在新浪申请 填上即可
- define( "WB_SKEY" ,'*************' );//这个在新浪申请 填上即可
- define( "WB_CALLBACK_URL" , '************' );//申请的时候 填写的回调地址
- <button οnclick="xinlang()" class="u-btn btn-wb">使用微博帐号登录</button>
- function xinlang(){
- window.location.href = "<{$web_url}>/index.php/login/xinlang";
- }
- /*
- * 这个是用新浪登录
- */
- public function xinlang(){
- include_once( '/xinlang/config.php' );
- include_once( '/xinlang/saetv2.ex.class.php' );
- $o = new SaeTOAuthV2( WB_AKEY , WB_SKEY );
- $code_url = $o->getAuthorizeURL( WB_CALLBACK_URL );
- header("location:".$code_url);
- }
- include_once( '/xinlang/config.php' );
- include_once( '/xinlang/saetv2.ex.class.php' );
- $o = new SaeTOAuthV2( WB_AKEY , WB_SKEY );
- $keys = array();
- $keys['code'] = $_REQUEST['code'];
- $keys['redirect_uri'] = WB_CALLBACK_URL;
- $token = $o->getAccessToken( 'code', $keys ) ;
- $c = new SaeTClientV2( WB_AKEY , WB_SKEY ,$token["access_token"]);
- $ms = $c->home_timeline(); // done
- $uid_get = $c->get_uid();
- $uid = $token['uid'];
- $user_message = $c->show_user_by_id( $token['uid']);//根据ID获取用户等基本信息
然后 我们就可以用
- var_dump($user_message);//显示新浪接口给我们展示的用户信息的有关资料了