14 require_once(
'ComposerRTSOA.php');
23 const NS =
'http://services.v1.ws.web.mastin.tra.dgm.gva.es/';
28 private $serviceParams = array(
29 'soap_version' => SOAP_1_1,
30 'user_agent' =>
'WSSSoapClient',
48 $this->wsURLWSDL = $wsURLWSDL;
52 private function getTipoRegistro($esRegistroEntrada) {
53 if ($esRegistroEntrada) {
58 private function codificarBooleano($valor) {
72 private function lanzaDispatcher($xmlEntrada, $vDocs)
77 $clienteWS = new \SoapClient($this->wsURLWSDL, $this->serviceParams);
78 $lanzaDispatcher = new \ArrayObject();
79 $lanzaDispatcher->append(
new \
SoapVar(base64_encode($xmlEntrada), XSD_STRING, null, null,
'xmlEntrada', null));
81 for($iDoc=0; $iDoc <
sizeof($vDocs); $iDoc++) {
82 $sDocB64 = base64_encode($vDocs[$iDoc]);
83 $lanzaDispatcher->append(
new \
SoapVar($sDocB64, XSD_STRING,null,null,
'documentos', null));
87 $miSoapRQ = new \SoapVar($lanzaDispatcher, SOAP_ENC_OBJECT,null,null,
'lanzaDispatcher', self::NS);
88 $respuesta = $clienteWS->lanzaDispatcher($miSoapRQ);
95 if (!isset($clienteWS)) {
100 $vRetorno = $this->tratarInnerException($clienteWS, $e);
119 $tipoRegistro = $this->getTipoRegistro($esRegistroEntrada);
122 $strCrearRegContent = $oCrearReg->generateString();
126 <?xml version=
"1.0" encoding=
"UTF-8"?>
127 <
API_CREAREGISTRO type=
"$tipoRegistro" formato=
"MASTIN" identificador=
"" version=
"3.0" idioma_error=
"" validarFirma=
"">
132 return $this->lanzaDispatcher(utf8_encode($xmlEntrada), $vDocs);
146 public function consultarRegistro($esRegistroEntrada, $numeroRegistro, $fechaRegistro, $claveConsulta, $devolverDocumentos, $docFirmados)
149 $tipoRegistro = $this->getTipoRegistro($esRegistroEntrada);
150 $devolverDocumentos = $this->codificarBooleano($devolverDocumentos);
151 $docFirmados = $this->codificarBooleano($docFirmados);
155 <?xml version=
"1.0" encoding=
"UTF-8"?>
156 <API_CONSULTAREGISTRO type=
"$tipoRegistro" formato=
"MASTIN" identificador=
"" version=
"3.0" idioma_error=
"" validarFirma=
"">
158 <NUMERO_REGISTRO>$numeroRegistro</NUMERO_REGISTRO>
159 <FECHA_REGISTRO>$fechaRegistro</FECHA_REGISTRO>
160 <CLAVE_CONSULTA>$claveConsulta</CLAVE_CONSULTA>
161 <DEVOLVER_DOCUMENTOS>$devolverDocumentos</DEVOLVER_DOCUMENTOS>
162 <DOCUMENTOS_FIRMADOS>$docFirmados</DOCUMENTOS_FIRMADOS>
164 </API_CONSULTAREGISTRO>
167 return $this->lanzaDispatcher(utf8_encode($xmlEntrada), null);
179 public function consultarDocumento($esRegistroEntrada, $numeroRegistro, $fechaRegistro, $claveConsulta, $tipoDocumento =
'T')
182 $tipoRegistro = $this->getTipoRegistro($esRegistroEntrada);
186 <?xml version=
"1.0" encoding=
"UTF-8"?>
187 <API_CONSULTADOCUMENTO type=
"$tipoRegistro" formato=
"MASTIN" identificador=
"" version=
"1.0" idioma_error=
"" validarFirma=
"">
189 <NUMERO_REGISTRO>$numeroRegistro</NUMERO_REGISTRO>
190 <FECHA_REGISTRO>$fechaRegistro</FECHA_REGISTRO>
191 <CLAVE_CONSULTA>$claveConsulta</CLAVE_CONSULTA>
192 <TIPO_DOCUMENTO>$tipoDocumento</TIPO_DOCUMENTO>
194 </API_CONSULTADOCUMENTO>
197 return $this->lanzaDispatcher(utf8_encode($xmlEntrada), null);
216 public function registrarAcuse($esRegistroEntrada, $numeroRegistro, $fechaRegistro, $claveConsulta, $expediente,
217 $nombreFichero, $codDocumento, $descDocumento, $asocioExpediente,
218 $entidadCertificadora, $formatoFirma, $valorFirma, $contenidoDoc)
221 $tipoRegistro = $this->getTipoRegistro($esRegistroEntrada);
222 $asocioExpediente = $this->codificarBooleano($asocioExpediente);
226 <?xml version=
"1.0" encoding=
"UTF-8"?>
227 <API_REGISTRAACUSE type=
"$tipoRegistro" formato=
"MASTIN" identificador=
"" version=
"" idioma_error=
"" validarFirma=
"">
230 <NUMERO_REGISTRO>$numeroRegistro</NUMERO_REGISTRO>
231 <FECHA_REGISTRO>$fechaRegistro</FECHA_REGISTRO>
232 <CLAVE_CONSULTA>$claveConsulta</CLAVE_CONSULTA>
235 <NOMBRE_FICHERO>$nombreFichero</NOMBRE_FICHERO>
236 <CODIGO_DOCUMENTO>$codDocumento</CODIGO_DOCUMENTO>
237 <DESCRIPCION_DOCUMENTO>$descDocumento</DESCRIPCION_DOCUMENTO>
238 <ASOCIO_EXPEDIENTE>$asocioExpediente</ASOCIO_EXPEDIENTE>
239 <TIPO_DOCUMENTO>R</TIPO_DOCUMENTO>
241 <ENTIDAD_CERTIFICADORA>$entidadCertificadora</ENTIDAD_CERTIFICADORA>
242 <FORMATO_FIRMA>$formatoFirma</FORMATO_FIRMA>
243 <VALOR_FIRMA>$valorFirma</VALOR_FIRMA>
246 <EXPEDIENTE></EXPEDIENTE>
252 $vDocs = array($contenidoDoc);
254 return $this->lanzaDispatcher(utf8_encode($xmlEntrada), $vDocs);
267 private function tratarInnerException($clienteWS, $e)
270 $mensaje = $e->getMessage();
271 $mensaje = trim(strtolower($mensaje));
274 case 'looks like we got no xml document' :
276 $response = $clienteWS->__getLastResponse();
302 $mimeBoundary =
'--MIME_Boundary';
303 $vBodyResponse = explode($mimeBoundary, $response);
304 $numElementos = count($vBodyResponse);
307 if ($numElementos<=1)
309 $mimeBoundary =
'--uuid:';
310 $vBodyResponse = explode($mimeBoundary, $response);
311 $numElementos = count($vBodyResponse);
312 $srcData = $response;
314 elseif ($numElementos>1)
316 $srcData = $vBodyResponse[1];
319 $vRespuesta = array();
320 ini_set(
'pcre.backtrack_limit',
'100000000');
321 preg_match(
"/<[a-z]*:Envelope.*?>(.*)<\/[a-z]*:Envelope>/is", $srcData, $vRespuesta);
322 if (preg_last_error()!=PREG_NO_ERROR)
325 $start = stripos($srcData,
':Envelope');
326 $start = strripos($srcData,
'<', $start - strlen($srcData));
327 $end = strripos($srcData,
':Envelope>');
328 $cadenaRespuesta = substr($srcData, $start, $end);
330 elseif (count($vRespuesta)<1)
332 throw new Exception(
'No puede ubicarse RESPONSE dentro de MTOM');
336 $cadenaRespuesta = $vRespuesta[0];
341 $dom->loadXML($cadenaRespuesta);
342 $xpath = new \DOMXpath($dom);
343 $vNodoRespuesta = $xpath->query(
"/*[local-name()='Envelope']/*[local-name()='Body']/*/*[local-name()='respuesta']");
345 if (!empty($itemToReturn))
347 $subStrXpath =
"/*[local-name()='{$itemToReturn}']";
349 $vNodoRespuesta = $xpath->query(
"/*[local-name()='Envelope']/*[local-name()='Body']/*".$subStrXpath);
350 $nodoRespuesta = $vNodoRespuesta->item(0);
355 $oMime = $oMimeParser->decodeMTOM($vBodyResponse);
356 unset($oMime->body);$oMime->body=null;gc_collect_cycles();
358 $vNodoInclude = $xpath->query(
"//*[local-name()='Include']");
359 foreach ($vNodoInclude as $nodoItem)
361 $subIdBuscado = (string) $nodoItem->getAttribute(
'href');
362 $subIdBuscado = urldecode($subIdBuscado);
363 $idBuscado =
'<'.substr($subIdBuscado, 4).
'>';
364 foreach ($oMime->parts as &$parte)
366 if ($idBuscado == ($parte->headers[
'content-id']))
368 if ( strtolower(substr($parte->mimetype, 0, 4)) !==
'text')
370 $parte->body = base64_encode($parte->body);
372 $textNode = $dom->createTextNode(($parte->body));
373 $nodoItem->parentNode->replaceChild($textNode, $nodoItem);
391 $vNodeRespuesta = $root->getElementsByTagName(
'respuesta');
392 if ($vNodeRespuesta->length == 0)
398 $nodeRespuesta = $vNodeRespuesta->item(0);
399 $oResp = RTSOAResponse::fromDOM($nodeRespuesta);
415 <?xml version=
"1.0" encoding=
"UTF-8"?>
416 <AVISO_NOTIFICACION_GRED>
417 <TITULO_AVISO>SIN USO</TITULO_AVISO>
418 <TEXTO_AVISO>$texto</TEXTO_AVISO>
419 </AVISO_NOTIFICACION_GRED>
422 return utf8_encode($xmlEntrada);
434 <?xml version=
"1.0" encoding=
"UTF-8"?>
435 <OFICIO_REMISION_GRED>
436 <TITULO_OFICIO_REMISION>SIN USO</TITULO_OFICIO_REMISION>
437 <TEXTO_OFICIO_REMISION>$texto</TEXTO_OFICIO_REMISION>
438 </OFICIO_REMISION_GRED>
441 return utf8_encode($xmlEntrada);
454 class RTSOAResponse {
457 private $_resultado = null;
458 private $_hasResultado =
false;
459 public function setResultado($value) {
460 $this->_resultado = $value;
461 $this->_hasResultado = ($value !== null);
463 public function hasResultado() {
464 return $this->_hasResultado;
466 public function getResultado() {
467 return $this->_resultado;
471 private $_document = array();
472 private $_hasDocument =
false;
473 public function replaceArrayDocument($value) {
474 $this->_document = $value;
475 $this->_hasDocument = (isset($this->_document) && !empty($this->_document));
477 public function retrieveArrayDocument() {
478 return $this->_document;
480 public function addDocument($value) {
481 array_push($this->_document, $value);
482 $this->_hasDocument = (isset($this->_document) && !empty($this->_document));
484 public function hasDocument() {
485 return $this->_hasDocument;
487 public function getDocument($index) {
488 return $this->_document[$index];
490 public function countDocument() {
491 return count($this->_document);
495 static public function fromDOM($nodoRespuesta) {
496 $newItem =
new RTSOAResponse();
499 $vNodeResultado = $nodoRespuesta->getElementsByTagName(
'resultado');
500 if ($vNodeResultado->length > 0)
502 $newItem->setResultado( $vNodeResultado->item(0)->nodeValue );
506 $vNodeDocumentos = $nodoRespuesta->getElementsByTagName(
'documentos');
507 if ($vNodeDocumentos->length > 0)
509 foreach($vNodeDocumentos as $nDoc) {
510 $newItem->addDocument( RTSOADocumentResponse::fromDOM($nDoc) );
517 public function ReadAPICrearRegistroFromString($strIn) {
518 $doc = new \DOMDocument();
519 $doc->loadXML($strIn);
521 $vAPI = $doc->getElementsByTagName(
'API_CREAREGISTRO');
522 if ($vAPI->length <= 0) {
526 $xmlAPI = $vAPI->item(0);
527 $oAPI = API_CREAREGISTRO::fromDOM( $xmlAPI );
532 public function ReadDatosRegistroFromString($strIn) {
533 $doc = new \DOMDocument();
534 $doc->loadXML($strIn);
536 $vAPI = $doc->getElementsByTagName(
'DATOS_DEL_REGISTRO');
537 if ($vAPI->length <= 0) {
541 $xmlAPI = $vAPI->item(0);
542 $oAPI = DATOS_DEL_REGISTRO::fromDOM( $xmlAPI );
550 class RTSOADocumentResponse
552 private $_nombre = null;
553 private $_hasNombre =
false;
554 private $_tipo = null;
555 private $_hasTipo =
false;
556 private $_contenido = null;
557 private $_hasContenido =
false;
560 public function setNombre($value) {
561 $this->_nombre = $value;
562 $this->_hasNombre = ($value !== null);
564 public function hasNombre() {
565 return $this->_hasNombre;
567 public function getNombre() {
568 return $this->_nombre;
573 public function setTipo($value) {
574 $this->_tipo = $value;
575 $this->_hasTipo = ($value !== null);
577 public function hasTipo() {
578 return $this->_hasTipo;
580 public function getTipo() {
586 public function setContenido($value) {
587 $this->_contenido = $value;
588 $this->_hasContenido = ($value !== null);
590 public function hasContenido() {
591 return $this->_hasContenido;
593 public function getContenido() {
594 return $this->_contenido;
598 static public function fromDOM($nodeDocumento) {
599 $newItem =
new RTSOADocumentResponse();
601 $vNode = $nodeDocumento->getElementsByTagName(
'nombre');
602 if ($vNode->length > 0)
604 $newItem->setNombre( $vNode->item(0)->nodeValue );
607 $vNode = $nodeDocumento->getElementsByTagName(
'tipo');
608 if ($vNode->length > 0)
610 $newItem->setTipo( $vNode->item(0)->nodeValue );
613 $vNode = $nodeDocumento->getElementsByTagName(
'contenido');
614 if ($vNode->length > 0)
616 $newItem->setContenido( $vNode->item(0)->nodeValue );
registrarAcuse($esRegistroEntrada, $numeroRegistro, $fechaRegistro, $claveConsulta, $expediente, $nombreFichero, $codDocumento, $descDocumento, $asocioExpediente, $entidadCertificadora, $formatoFirma, $valorFirma, $contenidoDoc)
crearRegistro($esRegistroEntrada, $oCrearReg, $vDocs)
consultarRegistro($esRegistroEntrada, $numeroRegistro, $fechaRegistro, $claveConsulta, $devolverDocumentos, $docFirmados)
static CrearFicheroOficioRemision($texto)
consultarDocumento($esRegistroEntrada, $numeroRegistro, $fechaRegistro, $claveConsulta, $tipoDocumento='T')
static CrearFicheroAviso($texto)
tratarMTOMEstandar($response, $itemToReturn=null)