maatify / hcaptcha
非官方HCaptcha for PHP,是maatify.dev HCaptcha处理器库,由我们团队熟知
1.0.0005
2024-08-10 11:13 UTC
Requires
- php: >=8.0
- ext-curl: *
- maatify/functions: ^1.2
- maatify/json: ^1.1
- maatify/logger: ^1.1
README
安装
composer require maatify/hcaptcha
使用
<?php /** * Created by Maatify.dev * User: Maatify.dev * Date: 2024-08-07 * Time: 1:10 PM * https://www.Maatify.dev */ use Maatify\HCaptcha\HCaptchaPublisherProValidation; require 'vendor/autoload.php'; $secret_key = '0x0000000000000000000000000000000000000000'; $hCaptcha = HCaptchaPublisherProValidation::getInstance($secret_key); // ===== get result in array format $result = $hCaptcha->getResponse(); // ====== get bool of validation $result = $hCaptcha->isSuccess(); // ====== using maatify json on error response with json code with die and if success there is no error $hCaptcha->jsonErrors();
示例
getResponse();
成功示例
Array ( [success] => 1 [challenge_ts] => 2024-08-07T10:09:36.000000Z [hostname] => localhost [credit] => )
错误示例
Array ( [success] => [error-codes] => Array ( [0] => missing-input-response [1] => missing-input-secret ) )
isSuccess();
返回 true || false
jsonErrors();
错误示例
Header 400
正文
- 在验证错误时
{ "success": false, "response": 40002, "var": "captcha", "description": { "success": false, "error-codes": [ "invalid-input-secret" ], "messages": [] }, "more_info": "invalid-input-secret", "error_details": "test:72" }{ "success": false, "response": 40002, "var": "captcha", "description": { "success": false, "error-codes": [ "timeout-or-duplicate" ], "messages": [] }, "more_info": "timeout-or-duplicate", "error_details": "test:72" }
- 在缺少或空的
$_POST['h-captcha-response']
时{ "success": false, "response": 1000, "var": "h-captcha-response", "description": "MISSING h-captcha-response", "more_info": "", "error_details": "" }
从HTML代码中创建
<form action="process.php" method="POST"> <form method="POST"> <!-- Your other form fields --> <div class="h-captcha" data-sitekey="__YOUR_SITE_KEY__" data-theme="dark" data-hl="ar"></div> <input type="submit" value="Submit"> </form> <script src="https://js.hcaptcha.com/1/api.js" async defer></script>