serviceUri = "localhost:8000/api"; //$this->serviceUri = "https://volamailtool-local.nginx-apps-ns:4448/api"; $this->username = "vola01"; $this->password = "Password01"; $this->login_request_api_endpoint = "/auth/login"; $this->mail_request_api_endpoint = "/mail/request"; $this->ssl_verify_host = 0; $this->ssl_verify_peer = false; } public function mailRequest($params) { try { $mapping = [ "template_mail_id" => $params["template_mail"], "template_mail_params" => $params["template_mail_params"], "recipient_to" => [$params["registration_email"]], "recipient_cc" => [], "template_pdf_params" => (isset($params["template_pdf_params"])) ? $params["template_pdf_params"] : array(), "attached_files" => (isset($params["attached_files"])) ? $params["attached_files"] : array(), //"optional_pdf_group" => "test_group", ]; $token = $this->login(); if ($token) { return ["result" => true, "idreq" => $this->call($token, $mapping)]; } return ["result" => false]; } catch (Exception $e) { error_log("Errore nell'esecuzione della chiamata a Vola Rest Mail Tool:\r".$e->getTraceAsString()); return ["result" => false]; } } private function login() { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $this->serviceUri.$this->login_request_api_endpoint, 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 => json_encode(["username"=>$this->username,"password"=>$this->password]), CURLOPT_HTTPHEADER => array('Content-Type: application/json'), CURLOPT_SSL_VERIFYHOST => $this->ssl_verify_host, CURLOPT_SSL_VERIFYPEER => $this->ssl_verify_peer, )); $response = curl_exec($curl); curl_close($curl); if (isset($response)) { $parsing = json_decode($response); if (isset($parsing->token)) { return $parsing->token; } else { error_log("Token non ricevuto. Risposta:\r" . print_r($response, 1)); return false; } } error_log("Si è verificato un errore nella chiamata di login"); return false; } private function call($token, $data) { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $this->serviceUri.$this->mail_request_api_endpoint, 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 => json_encode($data), CURLOPT_HTTPHEADER => array( 'Authorization: Bearer '.$token, 'Content-Type: application/json', ), CURLOPT_SSL_VERIFYHOST => $this->ssl_verify_host, CURLOPT_SSL_VERIFYPEER => $this->ssl_verify_peer, )); $response = curl_exec($curl); curl_close($curl); if (isset($response)) { $parsing = json_decode($response); if (isset($parsing->result)) { return $parsing->result; } else { error_log("Id Req non ricevuto. Risposta:\r" . print_r($response, 1)); return false; } } error_log("Si è verificato un errore nella chiamata di richiesta mail"); return false; } }