yuanlj-tea/click-captcha
Composer 安装命令:
composer require yuanlj-tea/click-captcha
包简介
click captcha
README 文档
README
Installation
Use composer:
composer require yuanlj-tea/click-captcha
Usage
You can create a captcha with output func:
$captcha = new \ClickCaptcha\Captcha(); $captcha->output();
Or inline it directly in the html page:
$inline = $captcha->getInline(); echo "<img src='".$linlie."' />";
You'll be able to get the code and compare it with a user input :
$captcha->getCode();
Used in Laravel
Register ServiceProvider and Facade with config/app.php:
'providers' => [ // ... \ClickCaptcha\ClickCaptchaServiceProvider::class, ], 'aliases' => [ // ... 'ClickCaptcha' => \ClickCaptcha\ClickCaptchaFacade::class, ],
Get a service instance:
Method parameter injection:
use ClickCaptcha\Captcha; public function getImage(Request $request, Captcha $captcha) { }
Obtained by the facade class:
use ClickCaptcha; public function getImageV1() { }
By service name:
public function getImageV2() { $captcha = app('click_captcha'); }
Check demo:
/** * 获取验证码信息 */ public function getCaptcha() { $key = 'click:captcha:' . str_random(32); $captcha = new Captcha(); $cacheMinutes = 30; $inline = $captcha->getInline(); $data['captcha_key'] = $key; $data['expired_at'] = time() + $cacheMinutes * 60; $code = $captcha->getCode(); $data['code'] = $code; Cache::put($key, $code, $cacheMinutes); $data['image'] = $inline; return AjaxResponse::success($data); } /** * 校验验证码 * @param Request $request */ public function check(Request $request) { $captcha_key = $request->input('captcha_key', ''); $param = $request->input('data', []); if (!Cache::has($captcha_key)) { return AjaxResponse::fail('验证码已过期,请刷新后再试'); } if (!is_array($param)) { return AjaxResponse::fail('验证失败,参数错误'); } $code = Cache::get($captcha_key); $checkCode = array_column($code, 'scope'); $errKey = $captcha_key . '_error'; if (Cache::get($errKey) >= 3) { Cache::forget($captcha_key); Cache::forget($errKey); return AjaxResponse::fail('错误次数过多,请刷新验证码后再试'); } foreach ($checkCode as $k => $v) { if (!isset($param[$k])) { Cache::increment($errKey); return AjaxResponse::fail('验证失败'); } if (!isset($param[$k]['x']) || !isset($param[$k]['y'])) { Cache::increment($errKey); return AjaxResponse::fail('验证失败'); } $x = $param[$k]['x']; $y = $param[$k]['y']; if ( !( $x >= $v['x_limit_left'] && $x <= $v['x_limit_right'] && $y >= $v['y_limit_up'] && $y <= $v['y_limit_down'] ) ) { Cache::increment($errKey); return AjaxResponse::fail('验证失败'); } } Cache::forget($errKey); return AjaxResponse::success('验证成功'); }
License
MIT
yuanlj-tea/click-captcha 适用场景与选型建议
yuanlj-tea/click-captcha 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 3, 最近一次更新时间为 2020 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 yuanlj-tea/click-captcha 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yuanlj-tea/click-captcha 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-08-13