UCClient for Laravel5
本项目基于 wehnhew/laravel4-ucenter 做了一点儿微小的升级,感谢 wehnhew !
安装
composer require mycontroller/ucclient
配置
在 /config/app.php
文件中找到 providers
键,
'providers' => [
...
MyController\UCClient\UCenterService\UCenterServiceProvider::class,
...
];
在 /config/app.php
文件中找到 aliases
键,
'aliases' => [
...
'UCClient' => MyController\UCClient\Facades\UCClientFacade::class,
...
];
如果想自定义配置, 可以运行以下命令将配置文件复制到 /config/uc-client.php
, 之后就可以方便的自定义了
php artisan config:publish
使用
例如:获取用户名为wen的信息
$result = UCClient::execute('uc_get_user',['wen']);
dd($result);
关于SSO登录注销
您需要自己实现 UCenterSSOContract 接口, 并将 UCenterSSOContract的具体实现类 绑定至 UCenterSSOContract 接口。
例如可以实现:
<?php
namespace App;
use MyController\UCClient\Contracts\UCenterSSOContract;
class MyUCenterSSO implements UCenterSSOContract
{
public function synLogin($uid, $username = '')
{
/** 同步登录代码 **/
}
public function synLogout()
{
/** 同步注销代码 **/
}
}
然后在 App\Providers\AppServiceProvider 的 register方法 里增加:
$this->app->bind(
\MyController\UCClient\Contracts\UCenterSSOContract::class,
\App\MyUCenterSSO::class
);
避免开启了 barryvdh/laravel-debugbar 插件后影响 UCenterAPI 的输出结果
您需要自己实现 UCenterAPIExecuteFilterContract 接口, 并将 UCenterAPIExecuteFilterContract的具体实现类 绑定至 UCenterAPIExecuteFilterContract 接口。
例如可以实现:
<?php
namespace App;
use MyController\UCClient\Contracts\UCenterAPIExecuteFilterContract;
class MyUCenterAPIExecuteFilter implements UCenterAPIExecuteFilterContract
{
public function beforeRun()
{
//
}
public function afterRun()
{
//
\Debugbar::disable(); //Runtime 关闭 debugbar
}
}
然后在 App\Providers\AppServiceProvider 的 register方法 里增加:
$this->app->bind(
\MyController\UCClient\Contracts\UCenterAPIExecuteFilterContract::class,
\App\MyUCenterAPIExecuteFilter::class
);
注意, SSO函数 synlogin 和 synlogout 两个方法连接 UCenter 的方式如果开启支持mysql模式, 必须要对 ucenter 做一些相应的修改
在 ucenter 的 /control/admin/app.php 里修改文件, 使 updateapps 通知能传输 authkey 参数
function _add_note_for_app() {
$this->load('note');
$notedata = $this->db->fetch_all("SELECT appid, type, name, url, authkey, ip, viewprourl, apifilename, charset, synlogin, extra, recvnote FROM ".UC_DBTABLEPRE."applications");
$notedata = $this->_format_notedata($notedata);
$notedata['UC_API'] = UC_API;
$_ENV['note']->add('updateapps', '', $this->serialize($notedata, 1));
$_ENV['note']->send();
}
function _format_notedata($notedata) {
$this->base = new base();
$arr = array();
foreach($notedata as $key => $note) {
$note['extra'] = unserialize($note['extra']);
if ($tmp = $this->base->authcode($note['authkey'], 'DECODE', UC_MYKEY)) {
$tmp = $this->base->authcode($tmp, 'ENCODE', $tmp);
$note['authkey'] = $tmp;
}
$arr[$note['appid']] = $note;
}
return $arr;
}
License
MIT