File tree 2 files changed +57
-1
lines changed
2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 3
3
4
4
use App \Captcha \Providers \HCaptchaProvider ;
5
5
use App \Captcha \Providers \ReCaptchaProvider ;
6
+ use App \Captcha \Providers \ProcaptchaProvider ;
6
7
7
8
final class Captcha
8
9
{
9
10
public const CAPTCHA_PROVIDER_RECAPTCHA = 0 ;
10
11
public const CAPTCHA_PROVIDER_HCAPTCHA = 1 ;
12
+ public const CAPTCHA_PROVIDER_PROCAPTCHA = 2 ;
11
13
12
14
public function getProviders (): array
13
15
{
14
16
return [
15
17
self ::CAPTCHA_PROVIDER_RECAPTCHA => new ReCaptchaProvider (),
16
18
self ::CAPTCHA_PROVIDER_HCAPTCHA => new HCaptchaProvider (),
19
+ self ::CAPTCHA_PROVIDER_PROCAPTCHA => new ProcaptchaProvider ()
17
20
];
18
21
}
19
22
20
23
public function getProvider (int $ provider ): ?CaptchaProviderInterface
21
24
{
22
25
return $ this ->getProviders ()[$ provider ] ?? null ;
23
26
}
24
- }
27
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ namespace App \Captcha \Providers ;
3
+
4
+ use App \Captcha \CaptchaProviderInterface ;
5
+
6
+ class ProcaptchaProvider implements CaptchaProviderInterface
7
+ {
8
+ private string $ verifyUrl = 'https://api.procaptcha.io/siteverify ' ;
9
+
10
+ public function validate (string $ response , string $ secretKey , ?string $ userIp = null ): bool
11
+ {
12
+ if (empty ($ response )) {
13
+ return false ;
14
+ }
15
+
16
+ $ data = [
17
+ 'captcha ' => $ response ,
18
+ 'maxVerifiedTime ' => 60 ,
19
+ ];
20
+
21
+ $ options = [
22
+ 'http ' => [
23
+ 'header ' => "Content-type: application/x-www-form-urlencoded \r\n" ,
24
+ 'method ' => 'POST ' ,
25
+ 'content ' => http_build_query ($ data )
26
+ ]
27
+ ];
28
+
29
+ $ context = stream_context_create ($ options );
30
+ $ response = file_get_contents ($ this ->verifyUrl , false , $ context );
31
+ if ($ response === false ) {
32
+ return false ;
33
+ }
34
+
35
+ $ result = json_decode ($ response );
36
+ return $ result ->success ;
37
+ }
38
+
39
+ public function getName (): string
40
+ {
41
+ return 'Procaptcha ' ;
42
+ }
43
+
44
+ public function getHomePageUrl (): string
45
+ {
46
+ return 'https://www.prosopo.io/?utm_source=phpform&utm_medium=plugin&utm_campaign=phpform ' ;
47
+ }
48
+
49
+ public function getDocumentationUrl (): string
50
+ {
51
+ return 'https://github.com/prosopo/captcha/blob/main/README.md ' ;
52
+ }
53
+ }
You can’t perform that action at this time.
0 commit comments