laravel-shine / jwt
简单的PHP JSON Web Token
1.0.1
2023-05-11 05:29 UTC
Requires
- php: ^7.0 || ^8.0
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-11 08:27:14 UTC
README
简单的PHP JSON Web Token
要求
- PHP > 7.0
- OpenSSL
功能
基本用法
encode(array payload, string $key, string $algorithm)
try { $token = JWT::encode(['sub' => '1234567890', 'name' => 'John Smith'], $key256bit, 'HS256'); } catch (\Exception $e) { // encode error }
decode(string $token, string $key)
try { $payload = JWT::decode($token, $key256bit); // $payload->sub == '1234567890' } catch (\Exception $e) { // $e->getCode() }