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

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

smalloyster/jwt
===============

1.2.1(5y ago)215GPL-3.0PHPPHP &gt;=5.6

Since Feb 13Pushed 4y ago1 watchersCompare

[ Source](https://github.com/SmallOyster/jwt)[ Packagist](https://packagist.org/packages/smalloyster/jwt)[ Docs](https://xshgzs.com/?from=composer)[ RSS](/packages/smalloyster-jwt/feed)WikiDiscussions master Synced today

READMEChangelog (5)Dependencies (1)Versions (5)Used By (0)

smalloyster\\jwt
================

[](#smalloysterjwt)

封装好的一个php-jwt包，必须通过composer安装

基本使用
====

[](#基本使用)

1️⃣ 安装composer之后，执行以下命令

```
composer require smalloyster/jwt

```

2️⃣ 在需要使用jwt的文件中引入此包

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

use smalloyster\Jwt;

```

3️⃣ 复制以下代码，生成JWT-Token

```
$token = Jwt::getInstance()
	->setKey('your-jwt-key')
	->setIss('') // 自定义，签发者
	->setAud('') // 自定义，接收者
	->setExpire(7200) // 自定义，有效秒数
	->setAlgorithmId('HS256'); // 自定义，签名加密算法（目前支持HS256/HS384/HS512）

// 可自定义payload的参数，定义data为一维数组即可
foreach ($data as $key => $value){
	$token = $token->setClaim($key, $value);
}

return $token->generate();

```

4️⃣ 验证JWT的签名有效性及使用者

```
return Jwt::getInstance()
	->setKey('your-jwt-key')
	->setIss('') // 自定义，签发者
	->setAud('') // 自定义，接收者
	->setAlgorithmId('HS256') // 自定义，签名加密算法（目前支持HS256/HS384/HS512）
	->setToken('..')
	->verify();

```

**上述将会返回一个数组：**

1. JWT有效：\["result" =&gt; true, "data" =&gt; payload中的数据\]
2. JWT无效：\["result" =&gt; false, "errorMsg" =&gt; 验证错误的信息\]

> 当token格式错误时，还会抛出错误，请catch ‼

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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

Every ~72 days

Total

4

Last Release

2116d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16716834?v=4)[Oyster Cheung](/maintainers/smalloyster)[@SmallOyster](https://github.com/SmallOyster)

---

Top Contributors

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

---

Tags

jwtsmalloyster

### Embed Badge

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

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

###  Alternatives

[tymon/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

11.7k51.8M371](/packages/tymon-jwt-auth)[php-open-source-saver/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

84611.1M63](/packages/php-open-source-saver-jwt-auth)[sizeg/yii2-jwt

JWT based on Icobucci

1951.1M7](/packages/sizeg-yii2-jwt)[jeremy379/laravel-openid-connect

OpenID Connect support to the PHP League's OAuth2 Server. Compatible with Laravel Passport.

59437.0k9](/packages/jeremy379-laravel-openid-connect)[bizley/jwt

JWT integration for Yii 2

69478.8k2](/packages/bizley-jwt)[hyperf-ext/jwt

The Hyperf JWT package.

53140.6k2](/packages/hyperf-ext-jwt)

PHPackages © 2026

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