/** * Invokes the Safebrowing API * * @author [A. Gianotto] [<*****@*****.**>] * @param $url string|array * @since [v0.1.0] * @return String JSON */ public static function checkSafeBrowsing($urls) { $postUrl = 'https://safebrowsing.googleapis.com/v4/threatMatches:find?key=' . config('safebrowsing.google.api_key'); $payload = ['client' => ['clientId' => config('safebrowsing.google.clientId'), 'clientVersion' => config('safebrowsing.google.clientVersion')], 'threatInfo' => ["threatTypes" => config('safebrowsing.google.threat_types'), "platformTypes" => config('safebrowsing.google.threat_platforms'), "threatEntryTypes" => ["URL"], "threatEntries" => Safebrowsing::formatUrls($urls)]]; $ch = curl_init(); $timeout = config('safebrowsing.google.timeout'); curl_setopt($ch, CURLOPT_URL, $postUrl); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Connection: Keep-Alive')); $data = curl_exec($ch); $responseDecoded = json_decode($data, true); $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($responseCode != 200) { return $responseDecoded; } return $data; }