Hash 密码

Hash 用于密码加密与验证,此服务必须安装 kain/hyperf-extra,需要添加配置 config/autoload/hashing.php

  1. return [
  2. /*
  3. |--------------------------------------------------------------------------
  4. | Default Hash Driver
  5. |--------------------------------------------------------------------------
  6. |
  7. | This option controls the default hash driver that will be used to hash
  8. | passwords for your application. By default, the bcrypt algorithm is
  9. | used; however, you remain free to modify this option if you wish.
  10. |
  11. | Supported: "bcrypt", "argon", "argon2id"
  12. |
  13. */
  14. 'driver' => 'argon2id',
  15. /*
  16. |--------------------------------------------------------------------------
  17. | Bcrypt Options
  18. |--------------------------------------------------------------------------
  19. |
  20. | Here you may specify the configuration options that should be used when
  21. | passwords are hashed using the Bcrypt algorithm. This will allow you
  22. | to control the amount of time it takes to hash the given password.
  23. |
  24. */
  25. 'bcrypt' => [
  26. 'rounds' => env('BCRYPT_ROUNDS', 10),
  27. ],
  28. /*
  29. |--------------------------------------------------------------------------
  30. | Argon Options
  31. |--------------------------------------------------------------------------
  32. |
  33. | Here you may specify the configuration options that should be used when
  34. | passwords are hashed using the Argon algorithm. These will allow you
  35. | to control the amount of time it takes to hash the given password.
  36. |
  37. */
  38. 'argon' => [
  39. 'memory' => 1024,
  40. 'threads' => 2,
  41. 'time' => 2,
  42. ],
  43. ];
  • driver bcrypt|argon|argon2id 加密算法
  • bcrypt array bcrypt 的配置
  • argon array argon2i 与 argon2id 的配置

config/autoload/dependencies.php 内完成关系配置

  1. return [
  2. Hyperf\Extra\Hash\HashInterface::class => Hyperf\Extra\Hash\HashFactory::class
  3. ];

即可注入使用

  1. use Hyperf\Extra\Hash\HashInterface;
  2. class IndexController
  3. {
  4. public function index(HashInterface $hash)
  5. {
  6. return [
  7. 'hash' => $hash->create('test')
  8. ];
  9. }
  10. }

也可以使用注解方式

  1. use Hyperf\Di\Annotation\Inject;
  2. use Hyperf\Extra\Hash\HashInterface;
  3. class IndexController
  4. {
  5. /**
  6. * @Inject()
  7. * @var HashInterface
  8. */
  9. private HashInterface $hash;
  10. public function index()
  11. {
  12. return [
  13. 'hash' => $this->hash->create('test')
  14. ];
  15. }
  16. }

加密密码

  • create($password, $options = [])

    • password string 密码
    • options array 加密参数
  1. use Hyperf\Di\Annotation\Inject;
  2. use Hyperf\Extra\Hash\HashInterface;
  3. class IndexController
  4. {
  5. /**
  6. * @Inject()
  7. * @var HashInterface
  8. */
  9. private HashInterface $hash;
  10. public function index()
  11. {
  12. $hashPassword = $this->hash->create('test');
  13. // $argon2id$v=19$m=65536,t=4,p=1$Z09laTVhVWRnN1E0RzNqUg$XmHfnX0Kol3EOO5WnVTAWSnkstkDsEGfCCSbUWGgUMU
  14. }
  15. }

验证密码

  • check($password, $hashPassword)

    • password string 密码
    • hashPassword string 密码散列值
  1. use Hyperf\Di\Annotation\Inject;
  2. use Hyperf\Extra\Hash\HashInterface;
  3. class IndexController
  4. {
  5. /**
  6. * @Inject()
  7. * @var HashInterface
  8. */
  9. private HashInterface $hash;
  10. public function index()
  11. {
  12. $hashPassword = '$argon2id$v=19$m=65536,t=4,p=1$Z09laTVhVWRnN1E0RzNqUg$XmHfnX0Kol3EOO5WnVTAWSnkstkDsEGfCCSbUWGgUMU';
  13. $this->hash->check('test', $hashPassword);
  14. // true
  15. }
  16. }

Cipher 数据加密

Cipher 可以将字符串或数组进行加密解密的服务,此服务必须安装 kain/hyperf-extra,需要配置 config/config.php

  1. return [
  2. 'app_name' => env('APP_NAME', 'skeleton'),
  3. 'app_key' => env('APP_KEY', '123456'),
  4. ];
  • app_name string Cipher 偏移量
  • app_key string Cipher 密钥

config/autoload/dependencies.php 内完成关系配置

  1. return [
  2. Hyperf\Extra\Cipher\CipherInterface::class => Hyperf\Extra\Cipher\CipherFactory::class,
  3. ];

即可注入使用

  1. use Hyperf\Extra\Cipher\CipherInterface;
  2. class IndexController
  3. {
  4. public function index(CipherInterface $cipher)
  5. {
  6. $cipher->encrypt('123');
  7. }
  8. }

也可以使用注解方式

  1. use Hyperf\Di\Annotation\Inject;
  2. use Hyperf\Extra\Cipher\CipherInterface;
  3. class IndexController
  4. {
  5. /**
  6. * @Inject()
  7. * @var CipherInterface
  8. */
  9. private CipherInterface $cipher;
  10. public function index()
  11. {
  12. $this->cipher->encrypt('123');
  13. }
  14. }

加密数据

  • encrypt($context)

    • context string|array 数据
    • Return string 密文
  1. use Hyperf\Di\Annotation\Inject;
  2. use Hyperf\Extra\Cipher\CipherInterface;
  3. class IndexController
  4. {
  5. /**
  6. * @Inject()
  7. * @var CipherInterface
  8. */
  9. private CipherInterface $cipher;
  10. public function index()
  11. {
  12. $this->cipher->encrypt(['name' => 'kain']);
  13. // XMqRFrrGduqqY3sEyKiHJQ==
  14. }
  15. }

解密数据

  • decrypt(string $ciphertext, bool $auto_conver = true)

    • ciphertext string 密文
    • auto_conver bool 数据属于数组时是否自动转换
    • Return string|array 明文
  1. use Hyperf\Di\Annotation\Inject;
  2. use Hyperf\Extra\Cipher\CipherInterface;
  3. class IndexController
  4. {
  5. /**
  6. * @Inject()
  7. * @var CipherInterface
  8. */
  9. private CipherInterface $cipher;
  10. public function index()
  11. {
  12. $this->cipher->decrypt('XMqRFrrGduqqY3sEyKiHJQ==');
  13. // array(1) {
  14. // ["name"]=>
  15. // string(4) "kain"
  16. // }
  17. }
  18. }

Token 令牌

Token 是 JSON Web Token 方案的功能服务,此服务必须安装 kain/hyperf-extra,首先更新配置 config/autoload/token.php

  1. return [
  2. 'system' => [
  3. 'issuer' => 'api.kainonly.com',
  4. 'audience' => 'console.kainonly.com',
  5. 'expires' => 3600
  6. ],
  7. ];

当中 system 就是 Token 的 Label 标签,可以自行定义名称

  • issuer string 发行者
  • audience string 听众
  • expires int 有效时间

config/autoload/dependencies.php 内完成关系配置

  1. return [
  2. Hyperf\Extra\Token\TokenInterface::class => Hyperf\Extra\Token\TokenFactory::class,
  3. ];

即可注入使用

  1. use Hyperf\Extra\Token\TokenInterface;
  2. use Hyperf\Utils\Str;
  3. use stdClass;
  4. class IndexController
  5. {
  6. public function index(TokenInterface $token)
  7. {
  8. $token->create('system', Str::random(), Str::random(8), [
  9. 'role' => '*'
  10. ]);
  11. }
  12. }

也可以使用注解方式

  1. use Hyperf\Di\Annotation\Inject;
  2. use Hyperf\Extra\Token\TokenInterface;
  3. use Hyperf\Utils\Str;
  4. use stdClass;
  5. class IndexController
  6. {
  7. /**
  8. * @Inject()
  9. * @var TokenInterface
  10. */
  11. private TokenInterface $token;
  12. public function index()
  13. {
  14. $this->token->create('system', Str::random(), Str::random(8), [
  15. 'role' => '*'
  16. ]);
  17. }
  18. }

生成令牌

  • create(string $scene, string $jti, string $ack, array $symbol = []): Plain

    • scene string 场景标签
    • jti string Token ID
    • ack string Token 确认码
    • symbol array 标识组
    • Return Lcobucci\JWT\Token\Plain
  1. use Hyperf\Di\Annotation\Inject;
  2. use Hyperf\Extra\Token\TokenInterface;
  3. use Hyperf\Utils\Str;
  4. use stdClass;
  5. class IndexController
  6. {
  7. /**
  8. * @Inject()
  9. * @var TokenInterface
  10. */
  11. private TokenInterface $token;
  12. public function index()
  13. {
  14. $symbol = new stdClass();
  15. $symbol->role = '*';
  16. $token = $this->token->create('system', Str::random(), Str::random(8), [
  17. 'role' => '*'
  18. ]);
  19. var_dump($token->toString());
  20. }
  21. }

获取令牌对象

  • get(string $jwt): Plain

    • jwt string 字符串令牌
    • Return Lcobucci\JWT\Token\Plain
  1. use Hyperf\Di\Annotation\Inject;
  2. use Hyperf\Extra\Token\TokenInterface;
  3. class IndexController
  4. {
  5. /**
  6. * @Inject()
  7. * @var TokenInterface
  8. */
  9. private TokenInterface $token;
  10. public function index()
  11. {
  12. $tokenString = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6InNMYW1vdkRMcFpMaTBKMzIifQ.eyJpc3MiOiJhcGkua2Fpbm9ubHkuY29tIiwiYXVkIjoiY29uc29sZS5rYWlub25seS5jb20iLCJqdGkiOiJzTGFtb3ZETHBaTGkwSjMyIiwiYWNrIjoiZlUxeUN6U2ciLCJzeW1ib2wiOnsicm9sZSI6IioifSwiZXhwIjoxNTg1MzY1MDUzfQ.zkamZXgUaqOTZEn8JBBo-8k3oZAzuU7zWH-ZtNJjagA';
  13. $token = $this->token->get($tokenString);
  14. assert($token instanceof Plain);
  15. var_dump($token);
  16. }
  17. }

验证令牌有效性

  • verify(string $scene, string $jwt): stdClass

    • scene string 场景标签
    • jwt string 字符串令牌
    • Return stdClass

      • expired bool 是否过期
      • token \Lcobucci\JWT\Token 令牌对象
  1. use Hyperf\Di\Annotation\Inject;
  2. use Hyperf\Extra\Token\TokenInterface;
  3. class IndexController
  4. {
  5. /**
  6. * @Inject()
  7. * @var TokenInterface
  8. */
  9. private TokenInterface $token;
  10. public function index()
  11. {
  12. $tokenString = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6InNMYW1vdkRMcFpMaTBKMzIifQ.eyJpc3MiOiJhcGkua2Fpbm9ubHkuY29tIiwiYXVkIjoiY29uc29sZS5rYWlub25seS5jb20iLCJqdGkiOiJzTGFtb3ZETHBaTGkwSjMyIiwiYWNrIjoiZlUxeUN6U2ciLCJzeW1ib2wiOnsicm9sZSI6IioifSwiZXhwIjoxNTg1MzY1MDUzfQ.zkamZXgUaqOTZEn8JBBo-8k3oZAzuU7zWH-ZtNJjagA';
  13. $result = $this->token->verify('system', $tokenString);
  14. var_dump($result);
  15. }
  16. }

Utils 工具集

Utils 常用工具集合,此服务必须安装 kain/hyperf-extra,在 config/autoload/dependencies.php 内完成关系配置

  1. return [
  2. Hyperf\Extra\Utils\UtilsInterface::class => Hyperf\Extra\Utils\UtilsFactory::class,
  3. ];

设置 Cookie

  • cookie(string $name, string $value, array $options = []): Cookie

    • name string Cookie 名称
    • value string
    • options array 配置

配置将以 config/autoload/cookie.php 作为基础

  1. return [
  2. 'expire' => (int)env('COOKIE_EXPIRE', 0),
  3. 'path' => env('COOKIE_PATH', '/'),
  4. 'domain' => env('COOKIE_DOMAIN', ''),
  5. 'secure' => (bool)env('COOKIE_SECURE', false),
  6. 'httponly' => (bool)env('COOKIE_HTTPONLY', false),
  7. 'raw' => true,
  8. 'samesite' => env('COOKIE_SAMESITE', null),
  9. ];

返回携带 Cookie 的请求

  1. use Hyperf\Di\Annotation\Inject;
  2. use Hyperf\Extra\Utils\UtilsInterface;
  3. use Hyperf\HttpServer\Contract\ResponseInterface;
  4. class IndexController
  5. {
  6. /**
  7. * @Inject()
  8. * @var ResponseInterface
  9. */
  10. private ResponseInterface $response;
  11. /**
  12. * @Inject()
  13. * @var UtilsInterface
  14. */
  15. private UtilsInterface $utils;
  16. public function index()
  17. {
  18. $cookie = $this->utils->cookie('name', 'kain');
  19. return $this->response->withCookie($cookie)->json([
  20. 'error' => 0,
  21. 'msg' => 'ok'
  22. ]);
  23. }
  24. }

Helper 助手

Helper 助手函数扩展,此服务必须安装 kain/hyperf-extra

路由绑定

  • AutoController(string $controller, array $options = [])

    • controller string 控制器
    • options array

      • middleware array 中间件
  1. AutoController(App\Controller\System\AclController::class, [
  2. 'middleware' => [
  3. App\Middleware\System\AuthVerify::class,
  4. App\Middleware\System\RbacVerify::class
  5. ]
  6. ]);

例如 AclController 控制器中存在 originLists() lists() add() get() edit() delete()
等公有函数,他们分别被绑定为 /acl/originLists /acl/lists /acl/add /acl/get /acl/edit /acl/delete 的 POST
路由。当然肯定还会存在不想绑定的函数,可以通过配置 config/autoload/curd.php 忽略它们

  1. return [
  2. 'auto' => [
  3. 'ignore' => [
  4. '__construct',
  5. 'addAfterHooks',
  6. 'addBeforeHooks',
  7. 'deleteAfterHooks',
  8. 'deleteBeforeHooks',
  9. 'deletePrepHooks',
  10. 'editAfterHooks',
  11. 'editBeforeHooks',
  12. 'getBeforeHooks',
  13. 'getCustomReturn',
  14. 'listsBeforeHooks',
  15. 'listsCustomReturn',
  16. 'originListsBeforeHooks',
  17. 'originListsCustomReturn'
  18. ]
  19. ]
  20. ];

可以通过数组集合来限定需要运行中间件的路由

  1. AutoController(App\Controller\System\MainController::class, [
  2. 'middleware' => [
  3. App\Middleware\System\AuthVerify::class => [
  4. 'resource', 'information', 'update', 'uploads'
  5. ]
  6. ]
  7. ]);

生成 uuid v4

  • uuid()

    • return UuidInterface
  1. $uuid = uuid();
  2. dump($uuid->toString());
  3. // "a2bcf1d5-2be3-4dc6-8cd4-937835a18a8b"

Stringy 字符串工具

  1. stringy('abc');

CORS 跨站设置

使用 CORS 中间定义跨站的请求策略,你需要在主配置或对应的模块下创建配置 config/autoload/cors.php,例如:

  1. return [
  2. 'allowed_methods' => explode(',', env('CORS_METHODS', '*')),
  3. 'allowed_origins' => explode(',', env('CORS_ORIGINS', '*')),
  4. 'allowed_headers' => explode(',', env('CORS_HEADERS', 'CONTENT-TYPE,X-REQUESTED-WITH')),
  5. 'exposed_headers' => explode(',', env('CORS_EXPOSED_HEADERS', '')),
  6. 'max_age' => (int)env('CORS_MAX_AGE', 0),
  7. 'allowed_credentials' => env('CORS_CREDENTIALS', false),
  8. ];
  • allowed_methods array 允许使用的 HTTP 方法
  • allowed_origins array 允许访问该资源的外域 URI,对于不需要携带身份凭证的请求
  • allowed_headers string 允许携带的首部字段
  • exposed_headers array 允许浏览器访问的头放入白名单
  • max_age int preflight 请求的结果能够被缓存多久
  • allowed_credentials boolean 允许浏览器读取 response 的内容

config/autoload/dependencies.php 内完成关系配置

  1. return [
  2. Hyperf\Extra\Cors\CorsInterface::class => Hyperf\Extra\Cors\CorsFactory::class
  3. ];

加入 /system 的路由组

  1. Router::addGroup('/system', function () {
  2. }, [
  3. 'middleware' => [
  4. Hyperf\Extra\Cors\CorsMiddleware::class
  5. ]
  6. ]);

Auth 鉴权验证

AuthMiddleware 鉴权验证是一个抽象定义中间件,使用时需要根据场景继承定义,例如

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Middleware\System;
  4. use Hyperf\Extra\Auth\AuthMiddleware;
  5. class AuthVerify extends AuthMiddleware
  6. {
  7. protected string $scene = 'system';
  8. }
  • scene string 场景标签

然后在将中间件注册在路由中

AutoController(App\Controller\System\MainController::class, [
    'middleware' => [
        App\Middleware\System\AuthVerify::class => [
            'resource', 'information', 'update', 'uploads'
        ]
    ]
]);

Auth 创建登录后将 Token 字符串存储在 Cookie 中,使用它需要引用该特性与部分依赖,以 app/Controller/System/MainController.php 为例

class MainController extends BaseController
{
    use Auth;
    /**
     * @Inject()
     * @var RefreshToken
     */
    private RefreshToken $refreshToken;
    /**
     * @Inject()
     * @var AdminRedis
     */
    private AdminRedis $adminRedis;

    /**
     * User login
     */
    public function login(): ResponseInterface
    {
        try {
            $this->post = $this->request->post();
            $validator = $this->validation->make($this->post, [
                'username' => 'required|between:4,20',
                'password' => 'required|between:8,18',
            ]);

            if ($validator->fails()) {
                return $this->response->json([
                    'error' => 1,
                    'msg' => $validator->errors()
                ]);
            }

            $data = $this->adminRedis->get($this->post['username']);

            if (empty($data)) {
                return $this->response->json([
                    'error' => 1,
                    'msg' => 'username not exists'
                ]);
            }

            if (!$this->hash->check($body['password'], $data['password'])) {
                return $this->response->json([
                    'error' => 1,
                    'msg' => 'password incorrect'
                ]);
            }

            return $this->create('system', [
                'user' =>  $data['username'],
                'role' => explode(',', $data['role'])
            ]);
        } catch (Exception $e) {
            return $this->response->json([
                'error' => 1,
                'msg' => $e->getMessage()
            ]);
        }
    }

    /**
     * User verify
     */
    public function verify(): ResponseInterface
    {
        try {
            return $this->authVerify('system');
        } catch (Exception $e) {
            return $this->response->json([
                'error' => 1,
                'msg' => $e->getMessage()
            ]);
        }
    }

    /**
     * User logout
     */
    public function logout(): ResponseInterface
    {
        try {
            return $this->destory('system');
        } catch (Exception $e) {
            return $this->response->json([
                'error' => 1,
                'msg' => $e->getMessage()
            ]);
        }
    }
}

设置令牌自动刷新的总时效

  • refreshTokenExpires(): int

    • return int 通过重写自定义,默认 604800,单位< 秒 >

创建登录鉴权

  • create(string $scene, ?stdClass $symbol): Psr\Http\Message\ResponseInterface

    • scene string 场景标签
    • symbol array 标识

验证登录

  • authVerify($scene): Psr\Http\Message\ResponseInterface

    • scene string 场景标签

销毁登录鉴权

  • destory(string $scene): Psr\Http\Message\ResponseInterface

    • scene string 场景标签

RBAC 权限验证

RbacMiddleware 权限验证是一个抽象定义中间件,使用时需要根据场景继承定义,例如

declare(strict_types=1);

namespace App\Middleware\System;

use App\RedisModel\System\AclRedis;
use App\RedisModel\System\RoleRedis;
use Hyperf\Extra\Rbac\RbacMiddleware;

class RbacVerify extends RbacMiddleware
{
    protected string $prefix = 'system';
    protected array $ignore = [
        'valided*'
    ];

    public function __construct(RoleRedis $role, AclRedis $acl)
    {
        parent::__construct($role, $acl);
    }
}
  • prefix string url 前缀
  • ignore array 忽略的函数名
AutoController(App\Controller\System\AclController::class, [
    'middleware' => [
        App\Middleware\System\AuthVerify::class,
        App\Middleware\System\RbacVerify::class
    ]
]);

RedisModel 缓存模型

使用 RedisModel 定义缓存模型,目的是将分散的缓存操作统一定义,例如:设定 Acl 访问控制表的缓存模型

class AclRedis extends RedisModel
{
    protected string $key = 'system:acl';

    /**
     * Clear Cache
     */
    public function clear(): void
    {
        $this->redis->del($this->key);
    }

    /**
     * Get Cache
     * @param string $key
     * @param int $policy
     * @return array
     */
    public function get(string $key, int $policy): array
    {
        if (!$this->redis->exists($this->key)) {
            $this->update();
        }

        $raws = $this->redis->hGet($this->key, $key);
        $data = !empty($raws) ? json_decode($raws, true) : [];

        switch ($policy) {
            case 0:
                return explode(',', $data['read']);
            case 1:
                return [
                    ...explode(',', $data['read']),
                    ...explode(',', $data['write'])
                ];
            default:
                return [];
        }
    }

    /**
     * Refresh Cache
     */
    private function update(): void
    {
        $query = Db::table('acl')
            ->where('status', '=', 1)
            ->get(['key', 'write', 'read']);

        if ($query->isEmpty()) {
            return;
        }

        $lists = [];
        foreach ($query->toArray() as $value) {
            $lists[$value->key] = json_encode([
                'write' => $value->write,
                'read' => $value->read
            ]);
        }
        $this->redis->hMSet($this->key, $lists);
    }
}

当对应的 acl 表数据发生变更时,执行 clear() 来清除缓存

use App\RedisModel\System\AclRedis;
use Hyperf\Di\Annotation\Inject;

class IndexController
{
    /**
     * @Inject()
     * @var AclRedis
     */
    private AclRedis $aclRedis;

    public function index()
    {
        $this->aclRedis->clear();
    }
}

通过缓存模型自定义的获取规则获取对应的数据,例如:查访问键 admin 对应的数据,如缓存不存在则生成缓存并返回数据

use App\RedisModel\System\AdminRedis;
use Hyperf\Di\Annotation\Inject;

class IndexController
{
    /**
     * @Inject()
     * @var AdminRedis
     */
    private AdminRedis $adminRedis;

    public function index()
    {
        $data = $this->adminRedis->get('kain');
    }
}

SMS 短信验证

*手机短信验证码缓存类*

设置手机验证码缓存

  • factory(string $phone, string $code, int $timeout = 120): bool

    • phone string 手机号
    • code string 验证码
    • timeout int 超时时间,默认 60 秒
use Hyperf\Di\Annotation\Inject;
use Hyperf\Support\RedisModel\Sms;

class IndexController
{
    /**
     * @Inject()
     * @var Sms
     */
    private Sms $smsRedis;

    public function index()
    {
        $this->smsRedis->factory('12345678910', '13125');
    }
}

验证手机验证码

  • check(string $phone, string $code, bool $once = false): bool

    • phone string 手机号
    • code string 验证码
    • once bool 验证成功后失效,默认false
use Hyperf\Di\Annotation\Inject;
use Hyperf\Support\RedisModel\Sms;

class IndexController
{
    /**
     * @Inject()
     * @var Sms
     */
    private Sms $smsRedis;

    public function index()
    {
        $this->smsRedis->check('12345678910', '13125');
    }
}

获取验证时间

  • time(string $phone): array

    • phone string 手机号
use Hyperf\Di\Annotation\Inject;
use Hyperf\Support\RedisModel\Sms;

class IndexController
{
    /**
     * @Inject()
     * @var Sms
     */
    private Sms $smsRedis;

    public function index()
    {
        $this->smsRedis->time('12345678910');
    }
}
  • publish_time int 指发布时间
  • timeout int 指有效时间

Refresh Token 缓存

*Refresh Token 是用于自动刷新、验证对应 Token 的缓存模型*

生产 Refresh Token

  • factory(string $jti, string $ack, int $expires): bool

    • jti string JSON Web Token ID
    • ack string Token ID 验证码
    • expires int 有限时间,单位<秒>

Refresh Token 续约

  • renewal(string $jti, int $expires): void

    • jti string JSON Web Token ID
    • expires int 有限时间,单位<秒>

验证 Token 的 Token ID 有效性

  • verify(string $jti, string $ack): bool

    • jti string JSON Web Token ID
    • ack string Token ID 验证码

清除 Token 对应的 Refresh Token

  • clear(string $jti, string $ack): int

    • jti string JSON Web Token ID
    • ack string Token ID 验证码

Lock 锁定

*适用于用户名或IP等验证锁定*

锁定清零

  • remove(string $name): void

    • name string 索引

锁定验证

  • check(string $name, int $limit = 5): bool

    • name string 索引
    • limit int 固定上限
    • Return bool

锁定自增

  • inc(string $name): void

    • name string 索引

锁定延长,延长锁定 15 分钟

  • lock(string $name): void

    • name string 索引