您的位置:首页 > 编程语言 > PHP开发

php的第三方登录----新浪微博

2017-03-22 21:10 337 查看
新浪微博的登录  

前提条件是需要实现两个文件  saetv2.ex.class.PHP  和 同级目录的config.php

saetv2.ex.class.php代码 百度一下 自己下载就行

config.php需要自己配置

[php]
view plain
copy

define( "WB_AKEY" , '********' );//这个在新浪申请 填上即可  
define( "WB_SKEY" ,'*************' );//这个在新浪申请 填上即可  
define( "WB_CALLBACK_URL" , '************' );//申请的时候 填写的回调地址  

[php]
view plain
copy

<button onclick="xinlang()" class="u-btn btn-wb">使用微博帐号登录</button>  

[javascript]
view plain
copy

function xinlang(){  
          window.location.href = "<{$web_url}>/index.php/login/xinlang";  
      }  

[php]
view plain
copy

/* 
     * 这个是用新浪登录 
     */  
    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);  
    }  

[php]
view plain
copy

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获取用户等基本信息  

然后 我们就可以用

[php]
view plain
copy

var_dump($user_message);//显示新浪接口给我们展示的用户信息的有关资料了 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: