ReCAPTCHA::auth
reCAPTCHAのトークンを検証します
説明
public array ReCAPTCHA::auth( string $response, [ float $threshold = null ] )
トークンをhttps://www.google.com/recaptcha/api/siteverifyに送信し、次の配列を返します。
| キー | データ型 | 備考 |
|---|---|---|
| success | boolean | APIが成功を返し、スコアがしきい値以上で、エラーがなければtrue |
| errors | array | エラーメッセージ(APIのエラーコードは英語、スコアがしきい値未満のときは日本語のメッセージ) |
サービスに接続できないときは、successがfalseになります(サービスに接続できないときを参照)。
引数
| 名前 | データ型 | デフォルト | 備考 |
|---|---|---|---|
| $response | string | ウィジェットが送信したトークン(g-recaptcha-response) | |
| $threshold | float | null | この呼び出しでの最低スコア。nullならコンストラクターに渡したしきい値 |
例
Controller
use Fegg\Tool\Captcha\ReCAPTCHA;
$recaptcha = new ReCAPTCHA(feggEnv('FEGG_RECAPTCHA_SECRET', ''), 0.5);
$result = $recaptcha->auth($this->in('g-recaptcha-response'));
if (!$result['success']) {
$errorMessage = implode(',', $result['errors']);
}