Google Recaptcha v3 example demo

后端 未结 7 919
故里飘歌
故里飘歌 2020-12-02 10:44

Until now, I was working with Google Recaptcha v2, but now I want to update my WebApp using the lastest version (v3).

Is it possible to anyone add a fully working Go

7条回答
  •  情歌与酒
    2020-12-02 11:11

    We use recaptcha-V3 only to see site traffic quality, and used it as non blocking. Since recaptcha-V3 doesn't require to show on site and can be used as hidden but you have to show recaptcha privacy etc links (as recommended)

    Script Tag in Head

     
    

    HTML/Css Code:

    there is no html code since our requirement is just to get score and don't want to show recaptcha badge.
    

    Backend - Laravel Code:

    Route:
    
    Route::post('/recaptcha/score', 'Api\\ReCaptcha\\RecaptchaScore@index');
    
    
    Class:
    
    class RecaptchaScore extends Controller
    {
        public function index(Request $request)
        {
            $score = null;
    
            $response = (new Client())->request('post', 'https://www.google.com/recaptcha/api/siteverify', [
                'form_params' => [
                    'response' => $request->get('token'),
                    'secret' => 'SECRET HERE',
                ],
            ]);
    
            $score = json_decode($response->getBody()->getContents(), true);
    
            if (!$score['success']) {
                Log::warning('Google ReCaptcha Score', [
                    'class' => __CLASS__,
                    'message' => json_encode($score['error-codes']),
                ]);
            }
    
            return [
                'response' => $score,
            ];
        }
    } 
    

    we get back score and save in variable which we later user when submit form.

    Reference: https://developers.google.com/recaptcha/docs/v3 https://developers.google.com/recaptcha/

提交回复
热议问题