diff --git a/.env.example b/.env.example index 0906027..9cc2c67 100644 --- a/.env.example +++ b/.env.example @@ -75,10 +75,11 @@ AWS_BUCKET= AWS_USE_PATH_STYLE_ENDPOINT=false # REPUVE FEDERAL -REPUVE_FED_URL= +REPUVE_FED_BASE_URL= REPUVE_FED_USERNAME= REPUVE_FED_PASSWORD= +# REPUVE ESTATAL REPUVE_EST_URL= REVERB_APP_ID= diff --git a/app/Http/Controllers/Repuve/InscriptionController.php b/app/Http/Controllers/Repuve/InscriptionController.php index 35ca69d..9ea25ab 100644 --- a/app/Http/Controllers/Repuve/InscriptionController.php +++ b/app/Http/Controllers/Repuve/InscriptionController.php @@ -358,7 +358,10 @@ public function stolen(Request $request) private function sendToRepuveNacional(string $niv): array { - return $this->repuveService->consultarPadron($niv); + // Obtener los datos completos del padrón estatal + $datosCompletos = $this->padronEstatalService->getVehiculoByNiv($niv); + // Enviar a inscripción de REPUVE Federal + return $this->repuveService->inscribirVehiculo($datosCompletos); } public function searchRecord(Request $request) diff --git a/app/Services/RepuveService.php b/app/Services/RepuveService.php index b0af8c5..e1c4ed2 100644 --- a/app/Services/RepuveService.php +++ b/app/Services/RepuveService.php @@ -6,19 +6,24 @@ class RepuveService { - private string $apiUrl; + private string $baseUrl; + private string $roboEndpoint; + private string $inscripcionEndpoint; private string $username; private string $password; public function __construct() { - $this->apiUrl = config('services.repuve_federal.soap_url'); + $this->baseUrl = config('services.repuve_federal.base_url'); + $this->roboEndpoint = config('services.repuve_federal.robo_endpoint'); + $this->inscripcionEndpoint = config('services.repuve_federal.inscripcion_endpoint'); $this->username = config('services.repuve_federal.username'); $this->password = config('services.repuve_federal.password'); } public function consultarPadron(string $niv) { + $url = $this->baseUrl . $this->roboEndpoint; $arg2 = $niv . '|||||||'; $soapBody = << XML; - $ch = curl_init($this->apiUrl); + $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $soapBody); @@ -137,7 +142,7 @@ private function parseVehicleResponse(string $soapResponse, string $niv): array throw new Exception("Formato de respuesta desconocido: {$contenido}"); } - /** + /** * Verifica si un vehículo está reportado como robado */ public function verificarRobo(string $niv): bool @@ -152,10 +157,121 @@ public function verificarRobo(string $niv): bool $estatus = $resultado['repuve_response']['estatus_registro'] ?? null; return in_array(strtoupper($estatus), ['ROBADO', 'ROBO']); - } catch (Exception $e) { logger()->error("Error al verificar robo en REPUVE: " . $e->getMessage()); return false; } } + + + public function inscribirVehiculo(array $datos): array + { + $url = $this->baseUrl . $this->inscripcionEndpoint; + + // DATOS HARDCODEADOS + $arg2 = '27|INTERNET|04/01/2022|WNU700B|2020-WNU700B|CHEVROLET G.M.C.|AVEO|PAQ. A LS|AUTOMOVIL|SEDAN|PARTICULAR|2022|BLANCO|H. EN WUHANLL,SGM|LSGHD52H0ND032457||4|COMENTARIO|1||GME111116GJA|||GOLSYSTEMS DE MEXICO|||27|04|BUGAMBILIAS|118||FRACC. BLANCAS MARIPOSAS|86170|0037804|5BK9MDO0|10/01/2025|1'; + + // Construir el cuerpo SOAP + $soapBody = << + + + + {$this->username} + {$this->password} + {$arg2} + + + + XML; + + // Configurar cURL + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $soapBody); + 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); + + // 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) { + return [ + 'has_error' => true, + 'error_code' => 'CURL_ERROR', + 'error_message' => "Error cURL: {$curlError}", + 'timestamp' => now()->toDateTimeString(), + 'http_code' => $httpCode, + 'raw_response' => $response, + ]; + } + + if ($httpCode !== 200) { + return [ + 'has_error' => true, + 'error_code' => 'HTTP_ERROR', + 'error_message' => "Error HTTP {$httpCode}", + 'timestamp' => now()->toDateTimeString(), + 'http_code' => $httpCode, + 'raw_response' => $response, + ]; + } + + // Parsear la respuesta + return $this->parsearRespuestaInscripcion($response); + } + + /** + * Parsea la respuesta + */ + private function parsearRespuestaInscripcion(string $soapResponse): array + { + // Retornar la respuesta completa + return [ + 'has_error' => false, + 'error_code' => null, + 'error_message' => null, + 'timestamp' => now()->toDateTimeString(), + 'raw_response' => $soapResponse, + 'parsed_response' => $this->extraerContenidoSOAP($soapResponse), + ]; + } + + private function extraerContenidoSOAP(string $soapResponse): ?string + { + // Intentar extraer el contenido del tag + preg_match('/(.*?)<\/return>/s', $soapResponse, $matches); + + if (isset($matches[1])) { + return trim($matches[1]); + } + + // Si no hay tag , intentar con otros tags comunes + preg_match('/(.*?)<\/result>/s', $soapResponse, $matches); + + if (isset($matches[1])) { + return trim($matches[1]); + } + + return null; + } } diff --git a/config/services.php b/config/services.php index d8cce6e..e3339e3 100644 --- a/config/services.php +++ b/config/services.php @@ -36,7 +36,9 @@ ], 'repuve_federal' => [ - 'soap_url' => env('REPUVE_FED_URL'), + 'base_url' => env('REPUVE_FED_BASE_URL'), + 'robo_endpoint' => '/jaxws-consultarpv/ConsultaRpv', + 'inscripcion_endpoint' => '/jaxrpc-inscripcion/Inscripcion?WSDLs=', 'username' => env('REPUVE_FED_USERNAME'), 'password' => env('REPUVE_FED_PASSWORD'), ],