<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                Thinkphp 整合UCenter ==== 整體構思: 服務器環境為apache, 根據apache的vhost在本地虛擬出兩個域名: `tpuc.la` 和 `tpuc2.la`, tpuc.la登錄, tpuc2.la可以得到對應的登錄信息就說明成功了 本文只是一個最簡單的demo, 如果需要更多的功能, 請到官網查看api接口 項目源代碼: https://github.com/xsu1991/ucenter_thinkphp3.2.3/ 同步登錄流程: 在tpuc.la登錄退出之后, 會回調UCenter`應用列表`里面的應用的`syslogin`, `syslogout`函數, 進行寫cookie或者清除cookie, 或者其他的 操作(可自定義) # UCenter ##安裝UCenter 下載請到ucenter的官網下載: http://www.comsenz.com/downloads/install/ucenter 安裝到你的電腦上面 ## 安裝應用 clone 例子 在apache的www目錄下新建tpuc和tpuc2兩個目錄, 分別把代碼克隆到里面 ## 配置域名環境 ### 配置vhost 打開apache的`vhost.conf`, 在結尾處加上 ```con <VirtualHost _default_:80> DocumentRoot "F:\www\tpuc" ServerName www.tpuc.la ServerAlias tpuc.la SetEnv APPLICATION_ENV "tpuc" <Directory "F:\www\tpuc"> Options +Indexes +FollowSymLinks +ExecCGI AllowOverride All Order allow,deny Allow from all Require all granted </Directory> </VirtualHost> <VirtualHost _default_:80> DocumentRoot "F:\www\tpuc2" ServerName www.tpuc2.la ServerAlias tpuc2.la SetEnv APPLICATION_ENV "tpuc2" <Directory "F:\www\tpuc2"> Options +Indexes +FollowSymLinks +ExecCGI AllowOverride All Order allow,deny Allow from all Require all granted </Directory> </VirtualHost> ``` 重啟apache ### 配置hosts文件 打開系統的`hosts`文件, 在文件末尾處, 加入 ``` 127.0.0.1 www.tpuc.la 127.0.0.1 tpuc.la 127.0.0.1 www.tpuc2.la 127.0.0.1 tpuc2.la ``` ## 配置UCenter ### 增加測試用戶 在用戶管理里面先增加2,3個用戶, 待之后測試 ### 增加測試應用 選中`應用管理` -> `添加新應用` 需要配置 test1: ``` 應用類型 -> 其它 應用名稱 -> 我取為test1, 名稱自取 用用的主URL -> http://tpuc.la/index.php/Ucenter/Api 通信密鑰 -> 隨便輸入字母數字 是否開啟同步登錄 -> 是 是否接受通知 -> 是 ``` 點擊提交, 然后把最下面的 `應用的 UCenter 配置信息`全部復制到tpuc的Ucenter模塊 > Conf文件夾 > config.php, 覆蓋對應的配置文件 ![20160927180730](https://raw.githubusercontent.com/xsu1991/ucenter_thinkphp3.2.3/master/pic/20160927180730.jpg) 覆蓋這里的 ![20160927180932](https://raw.githubusercontent.com/xsu1991/ucenter_thinkphp3.2.3/master/pic/20160927180932.jpg) test2: ``` 應用類型 -> 其它 應用名稱 -> 我取為test2, 名稱自取 用用的主URL -> http://tpuc2.la/index.php/Ucenter/Api 通信密鑰 -> 隨便輸入字母數字 是否開啟同步登錄 -> 是 是否接受通知 -> 是 ``` 覆蓋同上 保存之后, 返回到應用管理, 確保都通信成功 ![20160927172619](https://raw.githubusercontent.com/xsu1991/ucenter_thinkphp3.2.3/master/pic/20160927172619.jpg) # 修改 如果你需要修改來自己使用, 其實只需要修改下面框住的3個文件就可以了, 其他的文件都可以不動 ![sp161024_145018](https://raw.githubusercontent.com/xsu1991/ucenter_thinkphp3.2.3/master/pic/sp161024_145018.jpg) ## config.php 是從ucenter上面復制下來的配置 ## ApiService 里面的內容大致如下, 我已經實現了一種登錄和注冊, 可以不動 ```php class ApiService{ // todo login_handler public function login($get, $post){ $uid = intval($get['uid']); $username = $get['username']; cookie('auth', _uc_authcode($uid . "\t" . $username, 'ENCODE'), array('prefix' => 'ucenter_')); } // todo logout_handler public function logout(){ cookie('auth', null, array('prefix' => 'ucenter_')); } } ``` 其實就是登錄和注冊之后的操作, 我選擇的是寫入cookie, 你可以根據自己的實際需求來操作 ## UcenterService 就是對外提供的接口的, 如果里面的功能滿足你的需求也可以不動 我大概實現了, 3個方法, 具體看代碼 `login`, `logout`, `get_cookie_info` # 測試 我主要寫在了admin模塊的index控制器里面 有3個主要的方法, `syslongin`, `syslogout`, `get_cookie_info` 在瀏覽器的地址欄輸入, 把xxx補充為剛才新添加的用戶的username和password http://tpuc.la/index.php?m=Admin&c=Index&a=syslogin&username=xxx&password=xxx ![sp161024_150420](https://raw.githubusercontent.com/xsu1991/ucenter_thinkphp3.2.3/master/pic/sp161024_150420.jpg) 會有`登錄成功`的顯示 ![sp161024_150532](https://raw.githubusercontent.com/xsu1991/ucenter_thinkphp3.2.3/master/pic/sp161024_150532.jpg) ![sp161024_150551](https://raw.githubusercontent.com/xsu1991/ucenter_thinkphp3.2.3/master/pic/sp161024_150551.jpg) # 案例 Ucenter帶來的好處, 我就不多說了, 這里說一下我公司的案例吧, 統一的登錄和退出界面`account.xxx.com` 其他的應用app1.xxx.com需要登錄和退出的時候直接重定向到account登錄和退出, 其他的應用就不需要做登錄, 退出, 注冊, 一個帳號全站通用
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看