<?php
class SafeBrowsingAPI {

    private $apiKey;

    public function __construct($apiKey) {
        $this->apiKey = $apiKey;
    }

    public function checkUrls($urlArray) {
        
        $data = array(
            'client' => array(
                "clientId" => 'Volatine',
                "clientVersion" => '1.5.2'
            ),
            'threatInfo' => array(
                'threatTypes' => array("MALWARE", "SOCIAL_ENGINEERING"),
                'platformTypes' => array("ANY_PLATFORM"),
                'threatEntryTypes' => array("URL"),
                'threatEntries' => array(array("url" => $urlArray))
            )
        );

        $encoded = json_encode($data);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://safebrowsing.googleapis.com/v4/threatMatches:find?key='.$this->apiKey);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        $result = curl_exec($ch);
        curl_close($ch);
        return json_decode($result, true);
    }

}