PHPackages                             gdshenrun/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. gdshenrun/simple-jwt

ActiveLibrary

gdshenrun/simple-jwt
====================

简单的 jwt 实现

1.0.1(5y ago)0121Apache-2.0PHPPHP &gt;=7.1

Since Jan 18Pushed 5y ago1 watchersCompare

[ Source](https://github.com/gdshenrun/simple-jwt)[ Packagist](https://packagist.org/packages/gdshenrun/simple-jwt)[ RSS](/packages/gdshenrun-simple-jwt/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (2)Used By (1)

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

[](#simple-jwt)

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

如何安装 ？
------

[](#如何安装-)

```
composer require gdshenrun/simple-jwt
```

如何使用 ？
------

[](#如何使用-)

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

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

$secret = 'gdshenrun/simple-jwt';

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

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

// 可以使用自己实现的 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);
} 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

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

1938d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f06e8c1b2fe018d98d17d65eddf8f67f5c7038b306a3c66505b0679833b66446?d=identicon)[sunchao](/maintainers/sunchao)

---

Top Contributors

[![appledady](https://avatars.githubusercontent.com/u/13883775?v=4)](https://github.com/appledady "appledady (4 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/gdshenrun-simple-jwt/health.svg)](https://phpackages.com/packages/gdshenrun-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.0k15.4k](/packages/prestashop-prestashop)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[contao-community-alliance/dc-general

Universal data container for Contao

1578.3k86](/packages/contao-community-alliance-dc-general)[pdir/social-feed-bundle

Social feed extension for Contao CMS

1414.8k](/packages/pdir-social-feed-bundle)

PHPackages © 2026

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