PHPackages                             diaojinlong/captcha - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. diaojinlong/captcha

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

diaojinlong/captcha
===================

Hyperf3.0框架图片验证码

v3.0.2(2y ago)112MITPHPPHP &gt;=8.0

Since Aug 8Pushed 2y ago1 watchersCompare

[ Source](https://github.com/diaojinlong/captcha)[ Packagist](https://packagist.org/packages/diaojinlong/captcha)[ RSS](/packages/diaojinlong-captcha/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (8)Versions (2)Used By (0)

Hyperf CAPTCHA 组件（Hyperf3.0）
============================

[](#hyperf-captcha-组件hyperf30)

需要安装 imagick php扩展
------------------

[](#需要安装-imagick-php扩展)

安装
--

[](#安装)

```
composer require diaojinlong/captcha
```

发布配置
----

[](#发布配置)

```
php bin/hyperf.php vendor:publish diaojinlong/captcha
```

> 字体文件默认发布到 `/storage/fonts` 目录。

组件使用 `aes` 加解密 `key`，依赖 `hyperf/cache` 组件暂存使用过的 `key`，您需要发布这些组件的配置：

```
#生成加密的key,请将key设置.env中的CAPTCHA_AES_KEY=xxxxxxx
php bin/hyperf.php gen:key
php bin/hyperf.php vendor:publish hyperf/cache
```

使用
--

[](#使用)

```
use Hyperf\Utils\ApplicationContext;
use Diaojinlong\Captcha\CaptchaFactory;

$captchaFactory = ApplicationContext::getContainer()->get(CaptchaFactory::class);

// 生成
$captcha = $captchaFactory->create();
$response = [
    'key' => $captcha->getKey(),
    'blob' => $captcha->getBlob()->toDataUrl(),
    'ttl' => $captcha->getTtl(),
];

// 验证
$captchaFactory->validate($key, $text);
```

### 验证器

[](#验证器)

您可将 `key` 与用户输入用逗号 `,` 连接后传递给 `captcha` 验证规则来自动完成验证，验证成功的 `key` 将被自动暂存到缓存中直至该 `key` 过期。

### Hyperf2.0请使用，下面组件

[](#hyperf20请使用下面组件)

```
composer require hyperf-ext/captcha
```

### 本组件通过hyperf-ext/captcha改版

[](#本组件通过hyperf-extcaptcha改版)

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

1060d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/31237260?v=4)[May丶泡泡](/maintainers/diaojinlong)[@diaojinlong](https://github.com/diaojinlong)

---

Top Contributors

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

---

Tags

phpcaptchahyperf

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/diaojinlong-captcha/health.svg)

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

###  Alternatives

[hyperf/watcher

Hot reload watcher for Hyperf

17904.9k31](/packages/hyperf-watcher)

PHPackages © 2026

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