friendsofhyperf / recaptcha
The Google recaptcha component for Hyperf.
v3.0.2
2023-01-06 14:32 UTC
Requires
- google/recaptcha: ^1.2
- hyperf/di: ~3.0.0
- hyperf/event: ~3.0.0
- hyperf/http-server: ~3.0.0
- hyperf/validation: ~3.0.0
- 3.x-dev
- v3.0.2
- v3.0.0
- v3.0.0-rc.16
- v3.0.0-rc.9
- v3.0.0-rc.8
- v3.0.0-rc.7
- v3.0.0-rc.6
- v3.0.0-rc.4
- v3.0.0-rc.2
- v3.0.0-rc.1
- v3.0.0-beta34
- v3.0.0-beta33
- v3.0.0-beta32
- v3.0.0-beta29
- v3.0.0-beta28
- v3.0.0-beta27
- v3.0.0-beta26
- v3.0.0-beta25
- v3.0.0-beta24
- v3.0.0-beta23
- v3.0.0-beta22
- v3.0.0-beta21
- v3.0.0-beta20
- v3.0.0-beta19
- v3.0.0-beta18
- v3.0.0-beta17
- v3.0.0-beta16
- v3.0.0-beta15
- v3.0.0-beta14
- v3.0.0-beta13
- v3.0.0-beta12
- v3.0.0-beta11
- v3.0.0-beta10
- v3.0.0-beta9
- v3.0.0-beta8
- v3.0.0-beta7
- v3.0.0-beta6
- v3.0.0-beta5
- v3.0.0-beta4
- v3.0.0-beta3
- 2.x-dev / 2.0.x-dev
- v2.0.28
- v2.0.24
- v2.0.22
- v2.0.19
- v2.0.13
- v2.0.12
- v2.0.11
- v2.0.10
- v2.0.9
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- dev-HEAD
This package is auto-updated.
Last update: 2023-02-07 00:23:35 UTC
README
The Google recaptcha component for Hyperf.
Installation
- Request
composer require friendsofhyperf/recaptcha
Usage
- Middleware
namespace App\Middleware; use FriendsOfHyperf\ReCaptcha\Middleware\ReCaptchaMiddleware; class V3CaptchaMiddleware extends ReCaptchaMiddleware { protected $version = 'v3'; protected $action = 'register'; protected $score = 0.35; protected $hostname; } class V2CaptchaMiddleware extends ReCaptchaMiddleware { protected $version = 'v2'; protected $action = 'register'; protected $score = 0.35; protected $hostname; }
- Validator
<?php namespace App\Controller; use Hyperf\Di\Annotation\Inject; use Hyperf\HttpServer\Contract\RequestInterface; use Hyperf\Validation\Contract\ValidatorFactoryInterface; class IndexController { /** * @Inject() * @var ValidatorFactoryInterface */ protected $validationFactory; public function foo(RequestInterface $request) { $validator = $this->validationFactory->make( $request->all(), [ 'g-recaptcha' => 'required|recaptcha:register,0.34,hostname,v3', ], [ 'g-recaptcha.required' => 'g-recaptcha is required', 'g-recaptcha.recaptcha' => 'Google ReCaptcha Verify Fails', ] ); if ($validator->fails()){ // Handle exception $errorMessage = $validator->errors()->first(); } // Do something } }