PHPackages                             reaway/think-captcha-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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. reaway/think-captcha-jwt

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

reaway/think-captcha-jwt
========================

think captcha

v1.0.0(3y ago)0187[1 issues](https://github.com/reaway/think-captcha-jwt/issues)Apache-2.0PHPPHP &gt;=7.2.0

Since Mar 15Pushed 3y ago1 watchersCompare

[ Source](https://github.com/reaway/think-captcha-jwt)[ Packagist](https://packagist.org/packages/reaway/think-captcha-jwt)[ Docs](https://github.com/reaway/think-captcha-jwt)[ RSS](/packages/reaway-think-captcha-jwt/feed)WikiDiscussions main Synced 1mo ago

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

think-captcha
=============

[](#think-captcha)

安装
--

[](#安装)

```
composer require reaway/think-captcha-jwt
```

用法
--

[](#用法)

安装依赖

```
composer require firebase/php-jwt
```

ThinkPHP控制器中使用

```
namespace app\controller;

use Exception;
use app\BaseController;
use think\Response;
use Think\Component\CaptchaJwt\Facade\Captcha as CaptchaJwt;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;

class Captcha extends BaseController
{
    /**
     * 生成验证码
     * @return Response
     * @throws Exception
     */
    public function index(): Response
    {
        $tokenId = base64_encode(random_bytes(32)); // 生成随机ID
        $issuedAt = time(); // JWT的创建时间
        $notBefore = $issuedAt + 10; // 在创建10秒后才能使用
        $expire = $issuedAt + 60; // JWT的过期时间

        $captcha = CaptchaJwt::create();
        $data = [
            'iat' => $issuedAt,         // JWT的创建时间
            'jti' => $tokenId,          // JWT的随机ID
            'nbf' => $notBefore,        // 在创建10秒后才能使用
            'exp' => $expire,           // JWT的过期时间
            'data' => [                 // JWT的数据部分
                'code' => $captcha['key'], // 验证码
            ]
        ];

        $jwt = JWT::encode($data, config('jwt.secret'), 'HS256'); // 生成JWT

        return json([
                'code' => 0,
                'msg' => 'success',
                'data' => [
                    'token' => $jwt,
                    'content_type' => $captcha['content_type'],
                    'content_base64' => $captcha['content_base64']
                ]
            ]
        );
    }

    /**
     * 异步验证验证码
     * @return Response
     * @throws Exception
     */
    public function check(): Response
    {
        $param = [
            'captcha' => $this->request->param('captcha', '', 'trim'),
            'token' => $this->request->param('token', '', 'trim')
        ];

        //todo 验证提交参数

        try {
            $decoded = JWT::decode($param['token'], new Key(config('jwt.secret'), 'HS256'));
            $result = CaptchaJwt::check($decoded->data->code, $param['captcha']);
            $data = [
                'code' => 0,
                'msg' => 'success',
                'data' => $result
            ];
        } catch (Exception $e) {
            $data = [
                'code' => 1,
                'msg' => $e->getMessage(),
                'data' => false
            ];
        }

        return json($data);
    }
}
```

文档
--

[](#文档)

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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

1151d ago

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/reaway-think-captcha-jwt/health.svg)

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

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)[edward1108/edward-captcha

ThinkPHP6验证码(图片、短信)支持api友好化

157.9k](/packages/edward1108-edward-captcha)

PHPackages © 2026

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