| Server IP : 34.87.99.72 / Your IP : 216.73.217.31 Web Server : Apache/2.4.46 (Unix) OpenSSL/1.1.1n System : Linux zlock-bitnami-lamp-prod-v2-vm 4.19.0-16-cloud-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 User : bitnami ( 1000) PHP Version : 7.4.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /opt/bitnami/apache/htdocs/app/app/Http/Services/ |
Upload File : |
<?php
namespace App\Http\Services;
use Auth;
use Illuminate\Validation\ValidationException;
use Illuminate\Support\Facades\Log;
use Google\Cloud\RecaptchaEnterprise\V1\RecaptchaEnterpriseServiceClient;
use Google\Cloud\RecaptchaEnterprise\V1\Event;
use Google\Cloud\RecaptchaEnterprise\V1\Assessment;
use Google\Cloud\RecaptchaEnterprise\V1\TokenProperties\InvalidReason;
class GoogleRecaptchaService
{
public function __construct()
{
}
public function verifyRecaptcha($platform, $recaptcha_token)
{
$client = new RecaptchaEnterpriseServiceClient(
[
'credentials' => storage_path("zlock-app-32a2280166cb.json")
]
);
$site_key = config('services.recaptcha.secretKey');
if($platform != "android")
$site_key = config('services.recaptcha.secretKeyIOS');
$project_id = config('services.recaptcha.googleCloudProjectId');
\Log::info($recaptcha_token);
\Log::info($site_key);
\Log::info($platform);
try
{
$projectName = $client->projectName($project_id);
$event = (new Event())
->setSiteKey($site_key)
->setToken($recaptcha_token);
$assessment = (new Assessment())
->setEvent($event);
$response = $client->createAssessment(
$projectName,
$assessment
);
// You can use the score only if the assessment is valid,
// In case of failures like re-submitting the same token, getValid() will return false
if ($response->getTokenProperties()->getValid() == false) {
\Log::info('The CreateAssessment() call failed because the token was invalid for the following reason: ');
\Log::info(InvalidReason::name($response->getTokenProperties()->getInvalidReason()));
return false;
} else {
\Log::info('The score for the protection action is:');
\Log::info($response->getRiskAnalysis()->getScore());
return true;
}
}
catch(\Exception $e){
\Log::info('Error verifying: ');
\Log::info($e);
return false;
}
}
}