getInfo()["ambienteTest"] == "S" || $_SESSION["developEnv"] || $_SESSION["demoEnv"]) { $endpoints["login"] = "https://www.serviziocontrattipubblici.it/WSLoginCollaudo/rest/"; $endpoints["atti"] = "https://www.serviziocontrattipubblici.it/WSPubblicazioniCollaudo/rest/"; $endpoints["programmi"] = "https://www.serviziocontrattipubblici.it/WSProgrammiCollaudo/rest/"; $endpoints["tabelle"] = "https://www.serviziocontrattipubblici.it/WSTabelleDiContestoCollaudo/rest/"; } else { $endpoints["login"] = "https://www.serviziocontrattipubblici.it/WSLogin/rest/"; $endpoints["atti"] = "https://www.serviziocontrattipubblici.it/WSPubblicazioni/rest/"; $endpoints["programmi"] = "https://www.serviziocontrattipubblici.it/WSProgrammi/rest/"; $endpoints["tabelle"] = "https://www.serviziocontrattipubblici.it/WSTabelleDiContesto/rest/"; } return $endpoints; } public static function printLoginStatus() { include __DIR__ . "/views/loginInfo.php"; } public function __construct($codice_ente,$riferimento = "",$codiceRiferimento = 0) { $this->debug = false; $this->endpoints = self::getEndpoints(); $this->ente = Ente::getInfoFromID($codice_ente)[0] ?? null; if (!empty($riferimento)) { $this->riferimento = $riferimento; } if (!empty($codiceRiferimento)) { $this->codiceRiferimento = $codiceRiferimento; } if (!empty($this->ente)) { $this->clientKey = $this->ente["cpnClientKey"]; $this->clientId = $this->ente["cpnClientId"]; if (!empty($_SESSION["cpn"]["token"])) { $this->token = $_SESSION["cpn"]["token"]; } } else { return false; } } public function login($username,$password) { $ep = $this->endpoints["login"] . "Account/LoginPubblica"; $data = [ "username" => $username, "password" => $password, "clientKey" => $this->clientKey, "clientId" => $this->clientId, ]; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $ep, CURLOPT_HTTPHEADER => [ "Content-Type: application/x-www-form-urlencoded" ], CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => http_build_query($data), )); $return = curl_exec($curl); curl_close($curl); if (!empty($return)) { $return = json_decode($return,true); if (!empty($return["esito"]) && !empty($return["token"])) { $this->token = $return["token"]; return true; } } return false; } public function inviaGara($dati,$modalita = 2) { $ep = $this->endpoints["atti"] . "Anagrafiche/GaraLotti"; $data = json_encode(removeEmpty($dati)); return $this->sendCURL($ep,$modalita,$data); } public function inviaAtto($dati,$modalita = 2) { $ep = $this->endpoints["atti"] . "Atti/Pubblica"; $data = json_encode(removeEmpty($dati)); return $this->sendCURL($ep,$modalita,$data); } public function inviaProgramma($tipologia,$modalita,$dati) { $ep = $this->endpoints["programmi"]; switch($tipologia) { case "LV": $ep .= "Programmi/PubblicaLavori"; break; case "SF": $ep .= "Programmi/PubblicaFornitureServizi"; break; default: return false; } $data = json_encode(removeEmpty($dati)); return $this->sendCURL($ep,$modalita,$data); } public function downloadProgramma($id) { $ep = $this->endpoints["programmi"] . "Programmi/ScaricaPdf?idRicevuto={$id}&token={$this->token}"; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $ep, CURLOPT_HTTPHEADER => [ "Content-Type: application/x-www-form-urlencoded", "Accept: application/octet-stream" ], CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_FOLLOWLOCATION => true, // CURLOPT_CUSTOMREQUEST => "GET", // CURLOPT_POSTFIELDS => http_build_query(["idRicevuto"=>$id]) )); $return = curl_exec($curl); $info = curl_getinfo($curl); curl_close($curl); if (!empty($return)) { if ($info["http_code"] == 401 && $this->login($_SESSION["cpn"]["username"],$_SESSION["cpn"]["password"])) { $_SESSION["cpn"]["token"] = $this->token; return $this->downloadProgramma($id); } return $return; } return false; } private function sendCURL($endpoint,$modalita,$data,$method = "POST") { $curl = curl_init(); if ($this->debug) { ob_start(); ?> DEBUG CPN: Impostazioni

Endpoint:
Send mode:
Method:
Token: token ?>
URL: Prova
DEBUG CPN: Dati invio
riferimento; $log["codice_riferimento"] = $this->codiceRiferimento; $log["endpoint"] = "{$endpoint}?modalitaInvio={$modalita}"; $log["richiesta"] = (is_array($data)) ? json_encode($data) : $data; if (empty($data)) { $data = null; } $salva = new salva(); $salva->debug = false; $salva->nome_tabella = "b_cpn_log"; $salva->operazione = "INSERT"; $salva->oggetto = $log; $log = ["codice"=>$salva->save()]; curl_setopt_array($curl, array( CURLOPT_URL => "{$endpoint}?modalitaInvio={$modalita}&token={$this->token}", CURLOPT_HTTPHEADER => [ "Content-Type: application/json" ], CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_CUSTOMREQUEST => $method, CURLOPT_POSTFIELDS => $data, )); $log["risposta"] = $risposta = curl_exec($curl); $salva->oggetto = $log; $salva->operazione = "UPDATE"; $salva->save(); if ($this->debug) { ob_start(); ?> DEBUG CPN: Risposta
DEBUG CPN: Errori CURL
login($_SESSION["cpn"]["username"],$_SESSION["cpn"]["password"])) { $_SESSION["cpn"]["token"] = $this->token; return $this->sendCURL($endpoint,$modalita,$data,$method); } } } return $risposta; } } ?>