"account_credentials", "account_id" => $config["zoom-OAuth-ACCOUNTID"] ])); $risposta = curl_exec($curl); curl_close($curl); if (!empty($risposta)) { $risposta = json_decode($risposta,true); if (!empty($risposta["access_token"])) { $success = true; $this->token = $risposta["access_token"]; $this->hosts = self::getHosts(); $this->ente = $_SESSION["ente"]->getInfo(); } } } if (empty($success)) { return false; } } public static function getHosts($onlyID= true) { if (isset($_SESSION["ente"])) { global $pdo; $hosts = $pdo->go("SELECT * FROM b_hosts WHERE provider = 'zoom' AND codice_ente = :ente",[":ente"=>$_SESSION["ente"]->codice]); if ($hosts->rowCount() > 0) { $hosts = $hosts->fetchAll(PDO::FETCH_ASSOC); if ($onlyID) { $tmp = []; foreach($hosts AS $host) { $tmp[] = $host["id"]; } $hosts = $tmp; } return $hosts; } } return false; } public function getMeetingDetails($id) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "https://api.zoom.us/v2/meetings/{$id}"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 0); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer {$this->token}")); $risposta = curl_exec($curl); curl_close($curl); if (!empty($risposta)) { $risposta = json_decode($risposta,true); if (!empty($risposta["id"])) { return $risposta; } } return false; } public function getPastMeeting($id) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "https://api.zoom.us/v2/past_meetings/{$id}"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 0); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer {$this->token}")); $risposta = curl_exec($curl); curl_close($curl); if (!empty($risposta)) { $risposta = json_decode($risposta,true); if (!empty($risposta["id"])) { if ($risposta["participants_count"] > 0) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "https://api.zoom.us/v2/past_meetings/{$id}/participants"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 0); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer {$this->token}")); $participants = curl_exec($curl); curl_close($curl); if (!empty($participants)) { $participants = json_decode($participants,true); if (!empty($participants["participants"])) { $risposta["participants"] = $participants["participants"]; } } } return $risposta; } } return false; } public function getMeetingFromDB($sezione,$codice_elemento,$sub_elemento,$contesto,$codice_meeting=false) { global $pdo; $bind = [":sezione"=>$sezione,":codice_elemento"=>$codice_elemento,":sub_elemento"=>$sub_elemento,":contesto"=>$contesto,"ente"=>$this->ente["codice"]]; $sql = "SELECT * FROM b_conference WHERE provider = 'zoom' AND codice_ente = :ente AND sezione = :sezione AND codice_elemento = :codice_elemento AND sub_elemento = :sub_elemento AND contesto = :contesto "; if (!empty($codice_meeting)) { $bind[":codice"] = $codice_meeting; $sql .= " AND codice = :codice"; } $sql .= " ORDER BY codice DESC LIMIT 0,1"; $meetings = $pdo->go($sql,$bind); if ($meetings->rowCount() > 0) { return $meetings->fetch(PDO::FETCH_ASSOC); } return false; } public function createUser() { global $config; $body = []; $body["action"] ="custCreate"; $body["user_info"] = [ "first_name" => "Host", "last_name" => substr($this->ente["denominazione"], 0, 20), "email" => time()."-".$this->ente["codice"]."@studioamica.it", "password" => $config["zoom-JWT-APIKEY"], "type" => (($_SESSION["demoEnv"]) ? 1 : 2) ]; $body = json_encode($body); $curl = curl_init(); global $pdo; curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.zoom.us/v2/users', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => $body, CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', 'Accept: application/json', "Authorization: Bearer {$this->token}" ), )); $risposta = $response = curl_exec($curl); curl_close($curl); if (!empty($risposta)) { $risposta = json_decode($risposta,TRUE); if (!empty($risposta["id"])) { $salva = new salva($pdo); $salva->debug = false; $salva->nome_tabella = "b_hosts"; $salva->operazione = "INSERT"; $salva->oggetto = ["id"=>$risposta["email"],"codice_ente"=>$this->ente["codice"],"other"=>$response]; $salva->save(); if (!$_SESSION["demoEnv"]) { $this->allowLiveStreaming($risposta["email"]); } return true; } } return false; } public function getInfoLicenze() { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "https://api.zoom.us/v2/accounts/me/plans/usage"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 0); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer {$this->token}")); $risposta = curl_exec($curl); curl_close($curl); if (!empty($risposta)) { $risposta = json_decode($risposta,true); return $risposta; } return false; } public function allowLiveStreaming($id) { $body = []; $body["members"] = [["email"=>$id]]; $body = json_encode($body); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "https://api.zoom.us/v2/groups/n7MPX8PZQzaKFY9YPekQ0w/members"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 0); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_POSTFIELDS, $body); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer {$this->token}")); curl_exec($curl); curl_close($curl); } public function getSettings($id) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "https://api.zoom.us/v2/users/{$id}/settings"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 0); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer {$this->token}")); curl_exec($curl); curl_close($curl); } public function deleteUser($codice) { $hosts = self::getHosts(false); foreach($hosts AS $tmp) { if ($tmp["codice"] == $codice) { $host = json_decode($tmp["other"],true); break; } } if (!empty($host)) { $curl = curl_init(); global $pdo; curl_setopt($curl, CURLOPT_URL, "https://api.zoom.us/v2/users/{$host["id"]}?action=delete"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 0); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer {$this->token}")); $risposta = curl_exec($curl); curl_close($curl); if (empty($risposta)) { $pdo->go("DELETE FROM b_hosts WHERE codice = :codice",[":codice"=>$codice]); return true; } } return false; } public function createMeeting($sezione,$codice_elemento,$sub_elemento,$contesto) { $body = []; $body["type"] = 1; $body["topic"] = "{$sezione} - #{$codice_elemento} - {$contesto}"; $body["password"] = ""; // randomPassword(10); TODO: IMPLEMENTARE PASSWORD $body["timezone"] = "Europe/Rome"; $body["settings"] = [ "audio" => "voip", "auto_recording" => "local", "waiting_room" => true, "contact_name" => $this->ente["denominazione"], "contact_email" => $this->ente["pec"], "approval_type" => 1 ]; $body = json_encode($body); $curl = curl_init(); global $pdo; $check = $pdo->prepare("SELECT response FROM b_conference WHERE provider = 'zoom' AND codice_ente = :ente AND host = :host AND DATE(timestamp) = curdate() ORDER BY codice DESC LIMIT 0,1"); $check->bindValue(":ente",$this->ente["codice"]); foreach($this->hosts AS $tmpHost) { $check->bindValue(":host",$tmpHost); $check->execute(); if ($check->rowCount() > 0) { $tmpResponse = $check->fetch(PDO::FETCH_ASSOC); $meeting = json_decode($tmpResponse["response"],true); $status = $this->getMeetingDetails($meeting["id"]); if (empty($status["status"]) || $status["status"] == "finished") { $host = $tmpHost; } } else { $host = $tmpHost; } if (!empty($host)) { break; } } if (!empty($host)) { curl_setopt($curl, CURLOPT_URL, "https://api.zoom.us/v2/users/{$host}/meetings"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 0); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_POSTFIELDS, $body); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer {$this->token}")); $risposta = $response = curl_exec($curl); curl_close($curl); if (!empty($risposta)) { $risposta = json_decode($risposta,TRUE); if (!empty($risposta["uuid"])) { $salva = new salva($pdo); $salva->debug = false; $salva->nome_tabella = "b_conference"; $salva->operazione = "INSERT"; $salva->oggetto = ["sezione"=>$sezione,"codice_ente"=>$this->ente["codice"],"provider"=>"zoom","codice_elemento"=>$codice_elemento,"sub_elemento"=>$sub_elemento,"contesto"=>$contesto,"response"=>$response,"host"=>$host]; $salva->save(); return $risposta; } } } return false; } public function deleteMeeting($id) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "https://api.zoom.us/v2/meetings/{$id}"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 0); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer {$this->token}")); $risposta = curl_exec($curl); curl_close($curl); if (curl_getinfo($curl, CURLINFO_HTTP_CODE) == 204) { return true; } return false; } public function printLog($id) { $bind = []; $bind[":codice"] = $id; global $pdo; $risultato_conference = $pdo->go("SELECT * FROM b_conference WHERE provider = 'zoom' AND codice = :codice ",$bind); if ($risultato_conference->rowCount() > 0) { $zoomMeeting = $risultato_conference->fetch(PDO::FETCH_ASSOC); $response = json_decode($zoomMeeting["response"],true); $info = $this->getPastMeeting($response["uuid"]); if (!empty($info)) { include(__DIR__."/log.php"); } } } } ?>