メインコンテンツまでスキップ
Version: Fegg 5.x

ReCAPTCHA::auth

reCAPTCHAのトークンを検証します

説明​

public array ReCAPTCHA::auth( string $response, [ float $threshold = null ] )

トークンをhttps://www.google.com/recaptcha/api/siteverifyに送信し、次の配列を返します。

キーデータ型備考
successbooleanAPIが成功を返し、スコアがしきい値以上で、エラーがなければtrue
errorsarrayエラーメッセージ(APIのエラーコードは英語、スコアがしきい値未満のときは日本語のメッセージ)

サービスに接続できないときは、successがfalseになります(サービスに接続できないときを参照)。

引数​

名前データ型デフォルト備考
$responsestringウィジェットが送信したトークン(g-recaptcha-response)
$thresholdfloatnullこの呼び出しでの最低スコア。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']);
}