PHPackages                             pluveto/swoole-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. pluveto/swoole-captcha

ActiveLibrary

pluveto/swoole-captcha
======================

One php captcha based on php-captcha

0163PHP

Since Jul 29Pushed 5y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

swoole-captcha
==============

[](#swoole-captcha)

基于 php-captcha 的验证码插件。对 PSR7 适配。增加 Base64 输出和字节输出。

安装
--

[](#安装)

```
$ composer require pluveto/swoole-captcha dev-master
```

使用
--

[](#使用)

```
/**
 * @api {get} /auth/captcha 获取验证码
 * @apiName GetCaptcha
 * @apiGroup auth
 * @apiVersion  1.0.0
 * @apiPermission none
 *
 * @apiParam  {number{32-320}} [width=180] 宽度
 * @apiParam  {number{32-320}} [height=64] 高度
 * @apiParam  {boolean} [raw=true]
 * @apiParam  {string} [uuid=""] UUID
 */
public function getCaptcha()
{
    $req = $this->params();

    if (!$req->uuid) {
        $uuid = uuid();
    } else {
        $uuid = $this->authValidation->validateUUID($req->uuid);
    }

    $captha = new CaptchaBuilder();

    $captha->initialize([
        'width' => $req->width,     // 宽度
        'height' => $req->height,   // 高度
        'line' => false,            // 直线
        'curve' => true,            // 曲线
        'noise' => 1,               // 噪点背景
        'fonts' => []               // 字体
    ]);
    $captha->create();
    $text = $captha->getText(); // 获取验证码文本

    // 将验证码放到缓存中
    $redis = ApplicationContext::getContainer()->get(\Hyperf\Redis\Redis::class);
    $redis->set('captcha_' . str_replace("-", "", $uuid), $text, 60);

    if ($req->raw) {
        // 直接输出验证码
        return $captha->output($this->response->raw(""), 1);
    } else {
        // 通过 base64 输出验证码
        return $this->success(
            [
                "uuid" => $uuid,
                "expiredAt" => time() + 60,
                "content" => $captha->getBase64(1)
            ]
        );
    }
}
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity32

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/255051068?v=4)[Zhangzijing](/maintainers/Zhangzijing)[@zhangzijing](https://github.com/zhangzijing)

---

Top Contributors

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

### Embed Badge

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

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

PHPackages © 2026

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