50onred/php-jwt

一个用于在PHP中编码和解码JSON Web Tokens (JWT)的简单库。应遵循当前规范。

1.0.3 2015-01-14 14:44 UTC

This package is not auto-updated.

Last update: 2024-09-10 15:30:47 UTC


README

Build Status

PHP-JWT

一个用于在PHP中编码和解码JSON Web Tokens (JWT)的简单库。应遵循当前规范

安装

使用composer管理依赖并下载PHP-JWT

composer require firebase/php-jwt

示例

<?php

$key = "example_key";
$token = array(
    "iss" => "http://example.org",
    "aud" => "http://example.com",
    "iat" => 1356999524,
    "nbf" => 1357000000
);

$jwt = JWT::encode($token, $key);
$decoded = JWT::decode($jwt, $key);

print_r($decoded);

/*
 NOTE: This will now be an object instead of an associative array. To get
 an associative array, you will need to cast it as such:
*/

$decoded_array = (array) $decoded;

?>

测试

使用phpunit运行测试

$ pear install PHPUnit
$ phpunit --configuration phpunit.xml.dist
PHPUnit 3.7.10 by Sebastian Bergmann.
.....
Time: 0 seconds, Memory: 2.50Mb
OK (5 tests, 5 assertions)

许可证

3-Clause BSD.