PHPackages                             easyswoole/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. [Framework](/categories/framework)
4. /
5. easyswoole/jwt

ActiveLibrary[Framework](/categories/framework)

easyswoole/jwt
==============

php stander lib

2.0.1(2y ago)439.4k↓26.8%11[3 issues](https://github.com/easy-swoole/jwt/issues)Apache-2.0PHPPHP &gt;=7.1.0

Since Sep 15Pushed 2y agoCompare

[ Source](https://github.com/easy-swoole/jwt)[ Packagist](https://packagist.org/packages/easyswoole/jwt)[ Docs](https://www.easyswoole.com/)[ RSS](/packages/easyswoole-jwt/feed)WikiDiscussions master Synced today

READMEChangelog (9)Dependencies (2)Versions (11)Used By (0)

jwt
===

[](#jwt)

基于easyswoole组件实现的json web token

安装
--

[](#安装)

可以通过composer安装

```
composer require easyswoole/jwt

```

依赖
--

[](#依赖)

```
* PHP version >= PHP 7.1
* easyswoole 组件包括 spl 与 utility

```

生成token
-------

[](#生成token)

```
use EasySwoole\Jwt\Jwt;

$jwtObject = Jwt::getInstance()
    ->setSecretKey('easyswoole') // 秘钥
    ->publish();

$jwtObject->setAlg('HMACSHA256'); // 加密方式
$jwtObject->setAud('user'); // 用户
$jwtObject->setExp(time()+3600); // 过期时间
$jwtObject->setIat(time()); // 发布时间
$jwtObject->setIss('easyswoole'); // 发行人
$jwtObject->setJti(md5(time())); // jwt id 用于标识该jwt
$jwtObject->setNbf(time()+60*5); // 在此之前不可用
$jwtObject->setSub('主题'); // 主题
$jwtObject->setPrefix('Bearer'); // token前缀(可选)
// 自定义数据
$jwtObject->setData([
    'other_info'
]);

// 最终生成的token
$token = $jwtObject->__toString();
// 如果设置了setPrefix将会在生成的token加入对应的前缀,decode的时候会自动截取还原token
// Bearer +token (前缀与token间有一个空格，请注意)
```

解析token
-------

[](#解析token)

```
use EasySwoole\Jwt\Jwt;

$token = "eyJhbGciOiJITUFDU0hBMjU2IiwiaXNzIjoiZWFzeXN3b29sZSIsImV4cCI6MTU3MzgzNTIxMSwic3ViIjoi5Li76aKYIiwibmJmIjoxNTczODMxOTExLCJhdWQiOiJ1c2VyIiwiaWF0IjoxNTczODMxNjExLCJqdGkiOiJjYWJhZmNiMWIxZTkxNTU3YzIxMDUxYTZiYTQ0MTliMiIsInNpZ25hdHVyZSI6IjZlNTI1ZjJkOTFjZGYzMjBmODE1NmEwMzE1MDhiNmU0ZDQ0YzhkNGFhYzZjNmU1YzMzMTNjMDIyMGJjYjJhZjQiLCJzdGF0dXMiOjEsImRhdGEiOlsib3RoZXJfaW5mbyJdfQ%3D%3D";

try {
    $jwtObject = Jwt::getInstance()->decode($token);

    $status = $jwtObject->getStatus();

    // 如果encode设置了秘钥,decode 的时候要指定
    // $status = $jwt->setSecretKey('easyswoole')->decode($token)

    switch ($status)
    {
        case -1:
            echo 'token无效';
            break;
        case  1:
            echo '验证通过';
            $jwtObject->getAlg();
            $jwtObject->getAud();
            $jwtObject->getData();
            $jwtObject->getExp();
            $jwtObject->getIat();
            $jwtObject->getIss();
            $jwtObject->getNbf();
            $jwtObject->getJti();
            $jwtObject->getSub();
            $jwtObject->getSignature();
            $jwtObject->getPrefix();
            $jwtObject->getProperty('alg');
            break;
        case  2:
            echo '验证失败';
            break;
        case  3:
            echo 'token过期';
        break;
    }
} catch (\EasySwoole\Jwt\Exception $e) {

}
```

###  Health Score

31

—

LowBetter than 70% of packages

Maintenance5

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 57.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 ~144 days

Recently: every ~217 days

Total

10

Last Release

1082d ago

Major Versions

1.2.0 → 2.0.12023-04-07

### Community

Maintainers

![](https://www.gravatar.com/avatar/45c234d5f129ea570e630425636299127647534f0c2cbb073555e2c45d403d6f?d=identicon)[kiss291323003](/maintainers/kiss291323003)

---

Top Contributors

[![kiss291323003](https://avatars.githubusercontent.com/u/24490609?v=4)](https://github.com/kiss291323003 "kiss291323003 (15 commits)")[![huizhang001](https://avatars.githubusercontent.com/u/26496638?v=4)](https://github.com/huizhang001 "huizhang001 (10 commits)")[![RunsTp](https://avatars.githubusercontent.com/u/28254581?v=4)](https://github.com/RunsTp "RunsTp (1 commits)")

---

Tags

asyncframeworkswooleeasyswoole

### Embed Badge

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

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

###  Alternatives

[easyswoole/easyswoole

An efficient swoole framework

4.8k185.9k46](/packages/easyswoole-easyswoole)[easyswoole/rpc

An efficient swoole framework

7731.0k2](/packages/easyswoole-rpc)[easyswoole/orm

php stander lib

3088.7k](/packages/easyswoole-orm)[easyswoole/actor

easyswoole component

1410.3k](/packages/easyswoole-actor)

PHPackages © 2026

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