diff --git a/src/Captcha/Captcha.php b/src/Captcha/Captcha.php index 2724490..c737be9 100644 --- a/src/Captcha/Captcha.php +++ b/src/Captcha/Captcha.php @@ -3,17 +3,20 @@ use App\Captcha\Providers\HCaptchaProvider; use App\Captcha\Providers\ReCaptchaProvider; +use App\Captcha\Providers\ProcaptchaProvider; final class Captcha { public const CAPTCHA_PROVIDER_RECAPTCHA = 0; public const CAPTCHA_PROVIDER_HCAPTCHA = 1; + public const CAPTCHA_PROVIDER_PROCAPTCHA = 2; public function getProviders(): array { return [ self::CAPTCHA_PROVIDER_RECAPTCHA => new ReCaptchaProvider(), self::CAPTCHA_PROVIDER_HCAPTCHA => new HCaptchaProvider(), + self::CAPTCHA_PROVIDER_PROCAPTCHA => new ProcaptchaProvider() ]; } @@ -21,4 +24,4 @@ public function getProvider(int $provider): ?CaptchaProviderInterface { return $this->getProviders()[$provider] ?? null; } -} \ No newline at end of file +} diff --git a/src/Captcha/Providers/ProcaptchaProvider.php b/src/Captcha/Providers/ProcaptchaProvider.php new file mode 100644 index 0000000..34e2eed --- /dev/null +++ b/src/Captcha/Providers/ProcaptchaProvider.php @@ -0,0 +1,53 @@ + $response, + 'maxVerifiedTime' => 60, + ]; + + $options = [ + 'http' => [ + 'header' => "Content-type: application/x-www-form-urlencoded\r\n", + 'method' => 'POST', + 'content' => http_build_query($data) + ] + ]; + + $context = stream_context_create($options); + $response = file_get_contents($this->verifyUrl, false, $context); + if ($response === false) { + return false; + } + + $result = json_decode($response); + return $result->success; + } + + public function getName(): string + { + return 'Procaptcha'; + } + + public function getHomePageUrl(): string + { + return 'https://www.prosopo.io/?utm_source=phpform&utm_medium=plugin&utm_campaign=phpform'; + } + + public function getDocumentationUrl(): string + { + return 'https://github.com/prosopo/captcha/blob/main/README.md'; + } +}