简单的PHP JSON Web Token

1.0.1 2023-05-11 05:29 UTC

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()
}

异常

decode()