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

新浪微博的登錄  

前提條件是需要實現兩個文件  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);//顯示新浪接口給我們展示的用戶信息的有關資料了



發佈了27 篇原創文章 · 獲贊 1 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章