pablosanches/hcaptcha

hCaptcha 的简单封装

dev-master 2021-09-30 11:02 UTC

This package is auto-updated.

Last update: 2024-09-29 05:56:55 UTC


README

hcaptcha header

快速开始

  1. hCaptcha 上注册。
  2. 设置 选项卡获取您的公钥和站点密钥。
  3. 获取此包 composer require pablosanches/hcaptcha
  4. 设置您的 前端 如下
    <head>
        <script src="https://hcaptcha.com/1/api.js" async defer></script>
        ...
    </head>
    <body>
    
    <form action="endpoint.php" method="post">
        ...
        <div class="h-captcha" data-sitekey="your-sitekey"></div>
        <input type="submit" value="send">
    </form>
    
    </body>
  1. 现在,在您的 PHP 后端
    require('../vendor/autoload.php');
    use PabloSanches\hCaptcha;

    $hCaptcha = new hCaptcha('your-secret-key');
    $hCaptchaResult = $hCaptcha->challenge($_POST['h-captcha-response']);
    $isHuman = $hCaptchaResult->isHuman(); // True or False
    
    if (!$isHuman) {
        $errors = $hCaptchaResult->getErrors(); // An array with all errors
    }

享受它 ;)