PHPackages                             96qbhy/simple-jwt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. 96qbhy/simple-jwt

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

96qbhy/simple-jwt
=================

简单的 jwt 实现

v1.5(2y ago)21247.1k—2.9%10[1 issues](https://github.com/qbhy/simple-jwt/issues)10Apache-2.0PHPPHP &gt;=8.1CI failing

Since May 28Pushed 2y ago1 watchersCompare

[ Source](https://github.com/qbhy/simple-jwt)[ Packagist](https://packagist.org/packages/96qbhy/simple-jwt)[ RSS](/packages/96qbhy-simple-jwt/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (6)Versions (21)Used By (10)

simple-jwt
==========

[](#simple-jwt)

超简单的 jwt 实现。支持 Laravel、Hyperf 以及支持 composer 的其他框架

如何安装 ？
------

[](#如何安装-)

```
composer require 96qbhy/simple-jwt
```

如何使用 ？
------

[](#如何使用-)

```
require 'vendor/autoload.php';

use Qbhy\SimpleJwt\JWTManager;
use Qbhy\SimpleJwt\JWT;
use Qbhy\SimpleJwt\Encoders;
use Qbhy\SimpleJwt\EncryptAdapters;
use Qbhy\SimpleJwt\Exceptions;

$secret = '96qbhy/simple-jwt';

$headers = ['ver' => 0.1,];

$payload = [
    'user_id' => 'qbhy@gmail.com',
    'tester'  => 'qbhy',
];

// 可以使用自己实现的 encrypter 进行签名和校验，请继承自 AbstractEncrypter 抽象类
$encrypter = new EncryptAdapters\Md5Encrypter($secret);

// 可以使用自己实现的 encoder 进行编码，请实现 Encoder 接口
$encoder = new Encoders\Base64Encoder();
$cache = function(JWTManager $JWTManager){
return new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir());
};

// 实例化 jwt manager
$jwtManager = new JWTManager(compact('secret', 'encode','cache'));

// 设置 token 有效时间，单位 秒
$jwtManager->setTtl(60);
// 设置 token 过期后多久时间内允许刷新，单位 秒
$jwtManager->setRefreshTtl(120);

// 通过 jwt manager 实例化 jwt ，标准 jwt
$jwt0 = $jwtManager->make($payload, $headers);

// 生成 token，当然你也可以使用链式调用，例如:  $jwtManager->make($payload, $headers)->token()
$token = $jwt0->token();
print_r($token);

try {
// 通过 token 得到 jwt 对象
    $jwt1 = $jwtManager->parse($token);

    // 单纯解析，只判断签名是否正确，不判断时效性和黑名单
//    $jwt1 = $jwtManager->justParse($token);
} catch (Exceptions\TokenExpiredException $tokenExpiredException) {
    // 如果已经过期了，也可以尝试刷新此 jwt ,第二个参数如果为 true 将忽略 refresh ttl 检查
    $jwt1 = $jwtManager->refresh($tokenExpiredException->getJwt(), true);
}

// 得到 payload
$jwt1->getPayload();

// 得到 headers
$jwt1->getHeaders();

print_r($jwt1);

// 自己实例化 jwt ，完全纯净的 jwt ，无多余 payload
$jwt2 = new JWT($jwtManager, $headers, $payload);
```

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 87.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~106 days

Recently: every ~264 days

Total

20

Last Release

943d ago

Major Versions

0.0.5 → v1.0.02020-05-22

PHP version history (2 changes)0.0.2.x-devPHP &gt;=7.1

v1.5PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/24204533?v=4)[桥边红药](/maintainers/qbhy)[@qbhy](https://github.com/qbhy)

---

Top Contributors

[![qbhy](https://avatars.githubusercontent.com/u/24204533?v=4)](https://github.com/qbhy "qbhy (50 commits)")[![qbhy0715](https://avatars.githubusercontent.com/u/16954340?v=4)](https://github.com/qbhy0715 "qbhy0715 (4 commits)")[![haozing](https://avatars.githubusercontent.com/u/14840035?v=4)](https://github.com/haozing "haozing (1 commits)")[![ljyljy0211](https://avatars.githubusercontent.com/u/1272007?v=4)](https://github.com/ljyljy0211 "ljyljy0211 (1 commits)")[![lphkxd](https://avatars.githubusercontent.com/u/16346895?v=4)](https://github.com/lphkxd "lphkxd (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/96qbhy-simple-jwt/health.svg)

```
[![Health](https://phpackages.com/badges/96qbhy-simple-jwt/health.svg)](https://phpackages.com/packages/96qbhy-simple-jwt)
```

###  Alternatives

[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.1k17.8k](/packages/prestashop-prestashop)[metamodels/core

MetaModels core

10156.4k68](/packages/metamodels-core)[contao-community-alliance/dc-general

Universal data container for Contao

1680.8k92](/packages/contao-community-alliance-dc-general)[alchemy/phpexiftool

Exiftool driver for PHP

40191.5k4](/packages/alchemy-phpexiftool)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
