{"id":15938032,"url":"https://github.com/pluveto/swoole-captcha","last_synced_at":"2026-06-18T22:31:47.838Z","repository":{"id":57042995,"uuid":"283241826","full_name":"pluveto/swoole-captcha","owner":"pluveto","description":"Captcha for swoole (or swoft / hyperf ...) modified from php-captcha.","archived":false,"fork":false,"pushed_at":"2020-07-30T05:04:50.000Z","size":339,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-02-22T22:14:30.473Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pluveto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-28T14:46:23.000Z","updated_at":"2020-07-30T05:04:52.000Z","dependencies_parsed_at":"2022-08-23T23:40:31.694Z","dependency_job_id":null,"html_url":"https://github.com/pluveto/swoole-captcha","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pluveto/swoole-captcha","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pluveto%2Fswoole-captcha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pluveto%2Fswoole-captcha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pluveto%2Fswoole-captcha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pluveto%2Fswoole-captcha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pluveto","download_url":"https://codeload.github.com/pluveto/swoole-captcha/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pluveto%2Fswoole-captcha/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34510282,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-18T02:00:06.871Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-07T05:20:45.408Z","updated_at":"2026-06-18T22:31:47.818Z","avatar_url":"https://github.com/pluveto.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swoole-captcha\n\n基于 php-captcha 的验证码插件。对 PSR7 适配。增加 Base64 输出和字节输出。\n\n## 安装\n\n```bash\n$ composer require pluveto/swoole-captcha dev-master\n```\n\n## 使用\n\n```php\n/**\n * @api {get} /auth/captcha 获取验证码\n * @apiName GetCaptcha\n * @apiGroup auth\n * @apiVersion  1.0.0\n * @apiPermission none\n * \n * @apiParam  {number{32-320}} [width=180] 宽度 \n * @apiParam  {number{32-320}} [height=64] 高度 \n * @apiParam  {boolean} [raw=true]\n * @apiParam  {string} [uuid=\"\"] UUID\n */\npublic function getCaptcha()\n{    \n    $req = $this-\u003eparams();\n\n    if (!$req-\u003euuid) {\n        $uuid = uuid();\n    } else {\n        $uuid = $this-\u003eauthValidation-\u003evalidateUUID($req-\u003euuid);\n    }\n\n    $captha = new CaptchaBuilder();\n\n    $captha-\u003einitialize([\n        'width' =\u003e $req-\u003ewidth,     // 宽度\n        'height' =\u003e $req-\u003eheight,   // 高度\n        'line' =\u003e false,            // 直线\n        'curve' =\u003e true,            // 曲线\n        'noise' =\u003e 1,               // 噪点背景\n        'fonts' =\u003e []               // 字体\n    ]);\n    $captha-\u003ecreate();\n    $text = $captha-\u003egetText(); // 获取验证码文本\n\n    // 将验证码放到缓存中\n    $redis = ApplicationContext::getContainer()-\u003eget(\\Hyperf\\Redis\\Redis::class);\n    $redis-\u003eset('captcha_' . str_replace(\"-\", \"\", $uuid), $text, 60);\n    \n    if ($req-\u003eraw) {\n        // 直接输出验证码\n        return $captha-\u003eoutput($this-\u003eresponse-\u003eraw(\"\"), 1);\n    } else {\n        // 通过 base64 输出验证码\n        return $this-\u003esuccess(\n            [\n                \"uuid\" =\u003e $uuid,\n                \"expiredAt\" =\u003e time() + 60,\n                \"content\" =\u003e $captha-\u003egetBase64(1)\n            ]\n        );\n    }\n}","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpluveto%2Fswoole-captcha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpluveto%2Fswoole-captcha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpluveto%2Fswoole-captcha/lists"}