ezijing / ezijing-sso
清控紫荆sso工具包
V2.0.11
2022-09-21 07:37 UTC
Requires
- php: >=7.2
- ext-json: *
- ext-swoole: >=4.5
- hyperf/config: 2.2.*
- hyperf/constants: 2.2.*
- hyperf/di: 2.2.*
- hyperf/framework: 2.2.*
- hyperf/guzzle: 2.2.*
- hyperf/redis: 2.2.*
- hyperf/utils: 2.2.*
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- hyperf/devtool: ~2.2.0
- hyperf/ide-helper: ~2.2.0
- hyperf/testing: ~2.2.0
- mockery/mockery: ^1.0
- phpstan/phpstan: ^0.12
- swoole/ide-helper: ^4.5
Suggests
- ext-json: Required to use JSON.
- ext-openssl: Required to use HTTPS.
- ext-pdo: Required to use MySQL Client.
- ext-pdo_mysql: Required to use MySQL Client.
- ext-redis: Required to use Redis Client.
README
Table of Contents generated with DocToc
清控紫荆sso api插件
安装
1、下载插件包
> composer require ezijing/ezijing-sso -vvvv
2、发布配置
> php bin/hyperf.php vendor:publish ezijing/ezijing-sso -vvv
<?php declare(strict_types=1); return [ // 版本 V1, V2 'default_version' => env('SSO_VERSION', 'V1'), // 新版sso地址 'newsso_host' => env('SSO_NEWSSO_API_HOST', ''), // 新版sso V2地址 'usercenter_host' => env('SSO_USERCENTER_HOST', ''), // 用户中心地址 'usercenter_api_host' => env('SSO_USERCENTER_API_HOST', ''), // 接口签名使用的盐值 'salt' => env('SSO_SALT', ''), 'V1' => [ // 新版sso api 'newsso_api' => [ 'LOGIN' => '/rest/login', 'LOGOUT' => '/rest/logout', 'USERINFO' => '/account/get-user-info', ], // 用户中心api 'usercenter_api' => [ 'SEARCH_USER' => '/user/multi-get-user-info', 'CREATE_USER' => '/user/multi-create-user', 'CREATE_USER_SINGLE' => '/user/create-user', 'UPDATE_USER' => '/user/change-info', 'CHANGE_PWD_BY_COOKIE' => '/user/change-pwd-by-cookie', 'EXACT_SEARCH_USER' => '/user/exact-search-user', 'SEARCH_SERVER_USER' => '/user/search-user', 'SEARCH_SERVER_USER_MULTI' => '/user/multi-get-user-info', ], ], 'V2' => [ // 新版sso api 'newsso_api' => [ 'LOGIN' => '/v2/frontend/user/login', 'LOGOUT' => '/v2/frontend/user/logout', 'USERINFO' => '/v2/frontend/user/get-user-info', ], // 用户中心api 'usercenter_api' => [ 'SEARCH_USER' => '/v2/server/user/multi-get-user-info', 'CREATE_USER' => '/v2/server/user/multi-create-user', 'CREATE_USER_SINGLE' => '/v2/server/user/create-user', 'UPDATE_USER' => '/v2/server/user/change-info', 'CHANGE_PWD_BY_COOKIE' => '/v2/frontend/user/change-pwd-by-cookie', 'EXACT_SEARCH_USER' => '/v2/server/user/search-user', 'SEARCH_SERVER_USER' => '/v2/server/user/search-user', 'SEARCH_SERVER_USER_MULTI' => '/v2/server/user/multi-get-user-info', ], ], ]; ?>
使用ssoApi
1、用户登录
<?php $ssoApi = make(\Ezijing\EzijingSso\Core\Sso::class); $ssoApi->withVersion('V2')->login('username', 'password'); ?>
2、登出
<?php $ssoApi = make(\Ezijing\EzijingSso\Core\Sso::class); $ssoApi->withVersion('V2')->logout('TGC') ?>
3、通过TGC获取用户信息
<?php $ssoApi = make(\Ezijing\EzijingSso\Core\Sso::class); $user = $ssoApi->withVersion('V2')->getUserInfoByTgc('TGC'); ?>
4、创建单个用户信息
<?php $ssoApi = make(\Ezijing\EzijingSso\Core\Sso::class); $data = [ 'username' => '小明', 'nickname' => '小明', 'email' => 'xiaoming@ezijing.com', 'mobile' => '323232323', 'password' => '123456', 'country_code' => '86' ]; $user = $ssoApi->withVersion('V2')->createUser($data); ?>
5、精确检索用户
<?php $ssoApi = make(\Ezijing\EzijingSso\Core\Sso::class); $data = [ 'username' => '小明', ]; $ssoApi->withVersion('V2')->exactSearchUser($data); ?>
6、根据id(精确),用户名(模糊),邮箱(精确),手机号(精确),昵称(模糊)检索用户
<?php $ssoApi = make(\Ezijing\EzijingSso\Core\Sso::class); $data = [ 'username' => '小明', ]; $ssoApi->withVersion('V2')->search($data); ?>
7、通过用户的ssoId精确检索用户信息
<?php $ssoApi = make(\Ezijing\EzijingSso\Core\Sso::class); $ssoApi->withVersion('V2')->exactSearchOneUserById('1'); ?>
缓存
1、通过TGC缓存用户信息
<?php $ssoCached = make(\Ezijing\EzijingSso\Core\SsoCached::class); $ssoCached ->withVersion('V2') ->withTgc('TGC') ->setUser([ 'id' => 1, 'username' => '小明' ]); ?>
2、通过ssoId缓存用户信息
<?php $ssoCached = make(\Ezijing\EzijingSso\Core\SsoCached::class); $ssoCached ->withVersion('V2') ->withSsoId('1') ->setUser([ 'id' => 1, 'username' => '小明' ]); ?> ?>
3、通过TGC获取缓存的用户信息
<?php $ssoCached = make(\Ezijing\EzijingSso\Core\SsoCached::class); $user = $ssoCached ->withVersion('V2') ->withTgc('TGC') ->getUser(); ?>
4、 通过ssoId获取缓存的用户信息
<?php $ssoCached = make(\Ezijing\EzijingSso\Core\SsoCached::class); $user = $ssoCached ->withVersion('V2') ->withSsoId('1') ->getUser(); ?>
5、通过TGC删除用户缓存
<?php $ssoCached = make(\Ezijing\EzijingSso\Core\SsoCached::class); $ssoCached ->withVersion('V2') ->withTgc('TGC') ->clearUserCached(); ?>
6、通过ssoId删除用户缓存
$ssoCached = make(\Ezijing\EzijingSso\Core\SsoCached::class); $ssoCached ->withVersion('V2') ->withSsoId('1') ->clearUserCached();