diff --git a/app/Helpers/EncryptionHelper.php b/app/Helpers/EncryptionHelper.php new file mode 100644 index 0000000..2abc41d --- /dev/null +++ b/app/Helpers/EncryptionHelper.php @@ -0,0 +1,59 @@ +getMessage()); + } + } + + /** + * Decrypt the given data. + */ + public static function decryptData($encryptedData) + { + try{ + $decrypted = Crypt::decryptString($encryptedData); + return json_decode($decrypted, true); + }catch(DecryptException $e){ + Log::error('Error al desencriptar los datos: ' . $e->getMessage()); + return null; + }catch(\Exception $e){ + Log::error('Error inesperado al desencriptar los datos: ' . $e->getMessage()); + return null; + } + } + + public static function encryptFields(array $data, array $fields) + { + foreach ($fields as $field){ + if(isset($data[$field])){ + $data[$field] = self::encryptData($data[$field]); + } + } + return $data; + } + + public static function decryptFields(array $data, array $fields) + { + foreach ($fields as $field){ + if(isset($data[$field])){ + $data[$field] = self::decryptData($data[$field]); + } + } + return $data; + } +} diff --git a/app/Services/PadronEstatalService.php b/app/Services/PadronEstatalService.php index e937ab4..6759ad3 100644 --- a/app/Services/PadronEstatalService.php +++ b/app/Services/PadronEstatalService.php @@ -56,28 +56,34 @@ private function consultarPadron(string $tipo, string $valor): array curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $soapBody); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: text/xml; charset=utf-8', 'SOAPAction: ""', 'Content-Length: ' . strlen($soapBody) ]); - // Ejecutar la petición - $response = curl_exec($ch); - $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - $error = curl_error($ch); - curl_close($ch); + try { + // Ejecutar la petición + $response = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $error = curl_error($ch); - if ($error) { - throw new Exception("Error en la petición al padrón estatal: {$error}"); + if ($error) { + throw new Exception("Error en la petición al padrón estatal: {$error}"); + } + + if ($httpCode !== 200) { + throw new Exception("Error HTTP {$httpCode} al consultar padrón estatal"); + } + + // Parsear la respuesta + return $this->parsearRespuesta($response); + } finally { + // Liberar recursos del CurlHandle (PHP 8.0+) + unset($ch); } - - if ($httpCode !== 200) { - throw new Exception("Error HTTP {$httpCode} al consultar padrón estatal"); - } - - // Parsear la respuesta - return $this->parsearRespuesta($response); } /** diff --git a/app/Services/RepuveService.php b/app/Services/RepuveService.php index 88ccdb6..2ef8208 100644 --- a/app/Services/RepuveService.php +++ b/app/Services/RepuveService.php @@ -44,27 +44,32 @@ public function consultarPadron(string $niv) curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $soapBody); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: text/xml; charset=utf-8', 'SOAPAction: "doConsPadron"', 'Content-Length: ' . strlen($soapBody), ]); - // Ejecutar la solicitud - $response = curl_exec($ch); - $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - $error = curl_error($ch); - curl_close($ch); + try { + // Ejecutar la solicitud + $response = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $error = curl_error($ch); - if ($error) { - throw new Exception("Error en la petición SOAP: {$error}"); + if ($error) { + throw new Exception("Error en la petición SOAP: {$error}"); + } + + if ($httpCode !== 200) { + throw new Exception("Error al consultar REPUVE: Código HTTP {$httpCode}"); + } + + return $this->parseVehicleResponse($response, $niv); + } finally { + unset($ch); } - - if ($httpCode !== 200) { - throw new Exception("Error al consultar REPUVE: Código HTTP {$httpCode}"); - } - - return $this->parseVehicleResponse($response, $niv); } @@ -214,60 +219,65 @@ public function verificarRobo(?string $niv = null, ?string $placa = null): array curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $soapBody); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: text/xml; charset=utf-8', 'SOAPAction: "doConsRepRobo"', 'Content-Length: ' . strlen($soapBody), ]); - $response = curl_exec($ch); - $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - $error = curl_error($ch); - curl_close($ch); + try { + $response = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $error = curl_error($ch); - // Si hay error de conexión, retornar error - if ($error) { - logger()->error('REPUVE verificarRobo: Error de conexión', [ - 'error' => $error, - 'niv' => $niv, - 'placa' => $placa, - ]); - return [ - 'is_robado' => false, - 'has_error' => true, - 'error_message' => 'Error de conexión con el servicio REPUVE', - ]; + // Si hay error de conexión, retornar error + if ($error) { + logger()->error('REPUVE verificarRobo: Error de conexión', [ + 'error' => $error, + 'niv' => $niv, + 'placa' => $placa, + ]); + return [ + 'is_robado' => false, + 'has_error' => true, + 'error_message' => 'Error de conexión con el servicio REPUVE', + ]; + } + + // Si hay error HTTP, retornar error + if ($httpCode !== 200) { + logger()->error('REPUVE verificarRobo: HTTP error', [ + 'http_code' => $httpCode, + 'niv' => $niv, + 'placa' => $placa, + ]); + return [ + 'is_robado' => false, + 'has_error' => true, + 'error_message' => "Error HTTP {$httpCode} del servicio REPUVE", + ]; + } + + // Parsear respuesta + $valorBuscado = $niv ?: $placa ?: 'N/A'; + $resultado = $this->parseRoboResponse($response, $valorBuscado); + + // Si hubo error al parsear, loguear pero retornar el resultado completo + if ($resultado['has_error'] ?? false) { + logger()->warning('REPUVE verificarRobo: Error al parsear respuesta', [ + 'niv' => $niv, + 'placa' => $placa, + 'error' => $resultado['error_message'] ?? 'Desconocido', + ]); + } + + // Retornar el array completo con toda la información + return $resultado; + } finally { + unset($ch); } - - // Si hay error HTTP, retornar error - if ($httpCode !== 200) { - logger()->error('REPUVE verificarRobo: HTTP error', [ - 'http_code' => $httpCode, - 'niv' => $niv, - 'placa' => $placa, - ]); - return [ - 'is_robado' => false, - 'has_error' => true, - 'error_message' => "Error HTTP {$httpCode} del servicio REPUVE", - ]; - } - - // Parsear respuesta - $valorBuscado = $niv ?: $placa ?: 'N/A'; - $resultado = $this->parseRoboResponse($response, $valorBuscado); - - // Si hubo error al parsear, loguear pero retornar el resultado completo - if ($resultado['has_error'] ?? false) { - logger()->warning('REPUVE verificarRobo: Error al parsear respuesta', [ - 'niv' => $niv, - 'placa' => $placa, - 'error' => $resultado['error_message'] ?? 'Desconocido', - ]); - } - - // Retornar el array completo con toda la información - return $resultado; } catch (Exception $e) { logger()->error('REPUVE verificarRobo: Excepción capturada', [ 'niv' => $niv, @@ -311,55 +321,60 @@ public function consultarVehiculo(?string $niv = null, ?string $placa = null) curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $soapBody); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: text/xml; charset=utf-8', 'SOAPAction: "doConsRPV"', 'Content-Length: ' . strlen($soapBody), ]); - $response = curl_exec($ch); - $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - $error = curl_error($ch); - curl_close($ch); + try { + $response = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $error = curl_error($ch); - if ($error) { - logger()->error('REPUVE consultarVehiculo: Error de conexión', [ - 'error' => $error, - 'niv' => $niv, - 'placa' => $placa, - ]); - return [ - 'success' => false, - 'has_error' => true, - 'error_message' => 'Error de conexión con el servicio REPUVE', - ]; + if ($error) { + logger()->error('REPUVE consultarVehiculo: Error de conexión', [ + 'error' => $error, + 'niv' => $niv, + 'placa' => $placa, + ]); + return [ + 'success' => false, + 'has_error' => true, + 'error_message' => 'Error de conexión con el servicio REPUVE', + ]; + } + + if ($httpCode !== 200) { + logger()->error('REPUVE consultarVehiculo: HTTP error', [ + 'http_code' => $httpCode, + 'niv' => $niv, + 'placa' => $placa, + ]); + return [ + 'success' => false, + 'has_error' => true, + 'error_message' => "Error HTTP {$httpCode} del servicio REPUVE", + ]; + } + + // Parsear respuesta + $resultado = $this->parseConsultarVehiculoResponse($response); + + if ($resultado['has_error'] ?? false) { + logger()->warning('REPUVE consultarVehiculo: Error al parsear', [ + 'niv' => $niv, + 'placa' => $placa, + 'error' => $resultado['error_message'] ?? 'Desconocido', + ]); + } + + return $resultado; + } finally { + unset($ch); } - - if ($httpCode !== 200) { - logger()->error('REPUVE consultarVehiculo: HTTP error', [ - 'http_code' => $httpCode, - 'niv' => $niv, - 'placa' => $placa, - ]); - return [ - 'success' => false, - 'has_error' => true, - 'error_message' => "Error HTTP {$httpCode} del servicio REPUVE", - ]; - } - - // Parsear respuesta - $resultado = $this->parseConsultarVehiculoResponse($response); - - if ($resultado['has_error'] ?? false) { - logger()->warning('REPUVE consultarVehiculo: Error al parsear', [ - 'niv' => $niv, - 'placa' => $placa, - 'error' => $resultado['error_message'] ?? 'Desconocido', - ]); - } - - return $resultado; } catch (Exception $e) { logger()->error('REPUVE consultarVehiculo: Excepción', [ 'niv' => $niv, @@ -438,58 +453,63 @@ public function inscribirVehiculo(array $datos) curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $soapBody); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: text/xml; charset=utf-8', 'SOAPAction: "inscribe"', 'Content-Length: ' . strlen($soapBody), ]); - // Ejecutar la petición - $response = curl_exec($ch); - $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - $curlError = curl_error($ch); - curl_close($ch); + try { + // Ejecutar la petición + $response = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $curlError = curl_error($ch); - // Loguear para debug - logger()->info('REPUVE Inscripción Request', [ - 'url' => $url, - 'soap_body' => $soapBody - ]); + // Loguear para debug + logger()->info('REPUVE Inscripción Request', [ + 'url' => $url, + 'soap_body' => $soapBody + ]); - logger()->info('REPUVE Inscripción Response', [ - 'http_code' => $httpCode, - 'curl_error' => $curlError, - 'response' => $response - ]); - - if ($curlError) { - $errorFromDb = Error::where('code', '103')->first(); - return [ - 'has_error' => true, - 'error_code' => '103', - 'error_name' => $errorFromDb?->name, - 'error_message' => $errorFromDb?->description ?? "Error de conexión: {$curlError}", - 'timestamp' => now()->toDateTimeString(), + logger()->info('REPUVE Inscripción Response', [ 'http_code' => $httpCode, - 'raw_response' => $response, - ]; - } + 'curl_error' => $curlError, + 'response' => $response + ]); - if ($httpCode !== 200) { - $errorFromDb = Error::where('code', '-1')->first(); - return [ - 'has_error' => true, - 'error_code' => '-1', - 'error_name' => $errorFromDb?->name, - 'error_message' => $errorFromDb?->description ?? "Error interno HTTP {$httpCode}", - 'timestamp' => now()->toDateTimeString(), - 'http_code' => $httpCode, - 'raw_response' => $response, - ]; - } + if ($curlError) { + $errorFromDb = Error::where('code', '103')->first(); + return [ + 'has_error' => true, + 'error_code' => '103', + 'error_name' => $errorFromDb?->name, + 'error_message' => $errorFromDb?->description ?? "Error de conexión: {$curlError}", + 'timestamp' => now()->toDateTimeString(), + 'http_code' => $httpCode, + 'raw_response' => $response, + ]; + } - // Parsear la respuesta - return $this->parsearRespuestaInscripcion($response); + if ($httpCode !== 200) { + $errorFromDb = Error::where('code', '-1')->first(); + return [ + 'has_error' => true, + 'error_code' => '-1', + 'error_name' => $errorFromDb?->name, + 'error_message' => $errorFromDb?->description ?? "Error interno HTTP {$httpCode}", + 'timestamp' => now()->toDateTimeString(), + 'http_code' => $httpCode, + 'raw_response' => $response, + ]; + } + + // Parsear la respuesta + return $this->parsearRespuestaInscripcion($response); + } finally { + unset($ch); + } } /** diff --git a/resources/views/pdfs/constancia.blade.php b/resources/views/pdfs/constancia.blade.php index 3b0b43f..c110535 100644 --- a/resources/views/pdfs/constancia.blade.php +++ b/resources/views/pdfs/constancia.blade.php @@ -39,13 +39,13 @@ .left-col-marca { position: absolute; left: 5mm; - top: 35mm; + top: 33mm; } .left-col-linea-modelo { position: absolute; left: 5mm; - top: 41mm; + top: 39mm; width: 75mm; } @@ -63,20 +63,20 @@ .left-col-propietario { position: absolute; left: 5mm; - top: 45mm; + top: 43mm; } .left-col-direccion { position: absolute; left: 5mm; - top: 50mm; + top: 48mm; font-size: 8pt; } .left-col-municipio { position: absolute; left: 5mm; - top: 55mm; + top: 52mm; } /* COLUMNA DERECHA */ @@ -191,7 +191,7 @@