Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Internet
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Colaboración Paypal con ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 23-01-2025
Avatar de YellowStone
YellowStone YellowStone is offline
Miembro
 
Registrado: feb 2007
Ubicación: Adeje
Posts: 165
Poder: 20
YellowStone Va por buen camino
Este código de DELPHI 2007 Funciona en 2008 Y 2012 en la consulta de NIFS, sin IISCrypto ni tocar el registro. (Y no necesita CAPICOM)

Código PHP:
unit VNifV2;

interface

uses WindowsDialogsSysUtilsMessagesClassesxmldomXMLDocXMLIntfDateUtilsStrUtilsIdHTTPIdSSLOpenSSL;

type

  
Forward Decls }

  
IXMLContribuyenteType = interface;

IXMLContribuyenteType }

  
IXMLContribuyenteType = interface(IXMLNode)
    [
'{501E2A2E-11EB-42A7-A9D1-D1D7FA481B5B}']
    { 
Property Accessors }
    function 
Get_NifWideString;
    function 
Get_NombreWideString;
    function 
Get_ResultadoWideString;
    
procedure Set_Nif(ValueWideString);
    
procedure Set_Nombre(ValueWideString);
    
procedure Set_Resultado(ValueWideString);
    { 
Methods Properties }
    
property NifWideString read Get_Nif write Set_Nif;
    
property NombreWideString read Get_Nombre write Set_Nombre;
    
property ResultadoWideString read Get_Resultado write Set_Resultado;
  
end;

Forward Decls }

  
TXMLContribuyenteType = class;

TXMLContribuyenteType }

  
TXMLContribuyenteType = class(TXMLNodeIXMLContribuyenteType)
  protected
    { 
IXMLContribuyenteType }
    function 
Get_NifWideString;
    function 
Get_NombreWideString;
    function 
Get_ResultadoWideString;
    
procedure Set_Nif(ValueWideString);
    
procedure Set_Nombre(ValueWideString);
    
procedure Set_Resultado(ValueWideString);
  
end;

  
TGetCertificado = class(Tobject)
  
procedure hServidorGetPassword(var Passwordstring);
  
end;

{ Global 
Functions }

function 
GetContribuyente(DocIXMLDocument): IXMLContribuyenteType;
function 
NewContribuyenteIXMLContribuyenteType;
function 
VerificaNIFAEAT(var nifstring; var nombrestring): boolean// versión indy
function LimpiaRespuesta(respuestastring): string;

const

  
TargetNamespace '';

implementation

var rDatosEmisorTDatosEmisor;
    
bCertificadoboolean;

{ Global 
Functions }

function 
GetContribuyente(DocIXMLDocument): IXMLContribuyenteType;
begin
  Result 
:= Doc.GetDocBinding('Contribuyente'TXMLContribuyenteTypeTargetNamespace) as IXMLContribuyenteType;
end;

function 
NewContribuyenteIXMLContribuyenteType;
begin
  Result 
:= NewXMLDocument.GetDocBinding('Contribuyente'TXMLContribuyenteTypeTargetNamespace) as IXMLContribuyenteType;
end;

TXMLContribuyenteType }

function 
TXMLContribuyenteType.Get_NifWideString;
begin
  Result 
:= ChildNodes['Nif'].Text;
end;

procedure TXMLContribuyenteType.Set_Nif(ValueWideString);
begin
  ChildNodes
['Nif'].NodeValue := Value;
end;

function 
TXMLContribuyenteType.Get_NombreWideString;
begin
  Result 
:= ChildNodes['Nombre'].Text;
end;

procedure TXMLContribuyenteType.Set_Nombre(ValueWideString);
begin
  ChildNodes
['Nombre'].NodeValue := Value;
end;

function 
TXMLContribuyenteType.Get_ResultadoWideString;
begin
  Result 
:= ChildNodes['Resultado'].Text;
end;

procedure TXMLContribuyenteType.Set_Resultado(ValueWideString);
begin
  ChildNodes
['Resultado'].NodeValue := Value;
end;

//Versión Indy
function VerificaNIFAEAT(var nifstring; var nombrestring): boolean;
var 
RespuestaTStringList;
    
ixmlDocIXMLDocument;
    
hServidorTIdHTTP;
    
LHandlerTIdSSLIOHandlerSocketOpenSSL;
    
stRequestTStringStream;
    
sXMLsURLstring;
    
salidaIXMLContribuyenteType;
    
rGetCertificadoTGetCertificado;
begin
  
// Creamos la petición para comprobar
  
salida := NewContribuyente;
  
result := false;
  
Respuesta := TStringList.Create();
  
hServidor := TIdHTTP.Create(nil);
  
rGetCertificado := TGetCertificado.Create;
  try
    try
      
sURL := 'https://www1.agenciatributaria.gob.es/wlpl/BURT-JDIT/ws/VNifV2SOAP';
      
sXML := '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" '+
              
'xmlns:vnif="http://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/burt/jdit/ws/VNifV2Ent.xsd">';
      
sXML := sXML '<soapenv:Body><vnif:VNifV2Ent><vnif:Contribuyente><vnif:Nif>'+Trim(nif)+'</vnif:Nif>';
      
sXML := sXML '<vnif:Nombre>'+Trim(nombre)+'</vnif:Nombre></vnif:Contribuyente></vnif:VNifV2Ent></soapenv:Body></soapenv:Envelope>';

      
stRequest := TStringStream.Create(Utf8Encode(sXML));

      
hServidor.Request.CustomHeaders.AddValue('Accept''*/*');
      
hServidor.Request.CustomHeaders.AddValue('Accept-Encoding''gzip, deflate');
      
hServidor.Request.CustomHeaders.AddValue('Content-Type''text/xml; charset=utf-8');
      
hServidor.Request.CustomHeaders.AddValue('Connection''keep-alive');
      
hServidor.Request.CustomHeaders.AddValue('User-Agent''gVisualRec (Language=Delphi/2007)');
      
hServidor.Request.CustomHeaders.AddValue('SOAPAction''VNifV2Service');

      
LHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
      
LHandler.sslOptions.Method := sslvTLSv1_2;
      
LHandler.sslOptions.SSLVersions := [sslvTLSv1_2];
      
LHandler.SSLOptions.CertFile := 'CERTIFICADO.PFX'//<<<--- Nombre del certificado PFX / P12
      
LHandler.SSLOptions.KeyFile := 'CERTIFICADO.PFX';  //<<<--- Nombre del certificado PFX / P12  // Certificado de dispositivo a usar (el mismo que certfile)
      
LHandler.OnGetPassword := rGetCertificado.hServidorGetPassword;    // Cuando se solicite la clave, el evento se encarga de aportarla
      
hServidor.IOHandler := LHandler;

      
Respuesta.Append(hServidor.Post(Trim(sURL), stRequest));

      if 
hServidor.ResponseCode 200 then
        begin
              Respuesta
.Text := LimpiaRespuesta(Respuesta.Text);
              
ixmlDoc := TXMLDocument.Create(nil);
              
ixmlDoc.XML.Add(Respuesta.Text);
              
ixmlDoc.Active := True;
              
ixmlDoc.Encoding := 'UTF-8';
              try
                
salida := GetContribuyente(ixmlDoc);
                
result := ((salida.Resultado 'IDENTIFICADO') and (salida.Nif Nif));
                if 
result then
                  begin
                    Nif 
:= salida.Nif;
                    
Nombre := salida.Nombre;
                  
end
                
else
                  
begin
                    Nif 
:= '';
                    
Nombre := '';
                  
end;
              
except
                on E
:Exception do
                  
begin
                    ShowMessage
(E.Message);
                    
Nif := '';
                    
Nombre := '';
                  
end;
              
end;
        
end
      
else
        
begin
          Nif 
:= '';
          
Nombre := '';
        
end;
    
except
      on e
exception do
        
begin
          ShowMessage
(e.message);
          
Nif := '';
          
Nombre := '';
        
end
    end
;
  
finally
    Respuesta
.Free;
    
stRequest.Free;
    
hServidor.Free;
  
end;
end;

function 
LimpiaRespuesta(respuestastring): string;
var 
iIniiLoninteger;
begin
  result 
:= StringReplace(respuesta'
'
'', [rfReplaceAll]);
  
result := StringReplace(result'&lt;''<', [rfReplaceAll]);
  
result := StringReplace(result'&gt;''>', [rfReplaceAll]);
  
iIni := Pos('<VNifV2Sal:Contribuyente'result);
  
iLon := Pos('</VNifV2Sal:Contribuyente>'result) +26 iIni;
  
result := Copy(resultiIniiLon);
  
result := StringReplace(result'VNifV2Sal:''', [rfReplaceAll]);
end;

procedure TGetCertificado.hServidorGetPassword(var Passwordstring);
begin
  Password 
:= Clave// Password del certificado pfx
end;

end

Última edición por YellowStone fecha: 23-01-2025 a las 17:54:20.
Responder Con Cita
  #2  
Antiguo 23-01-2025
Anagnostes Anagnostes is offline
Registrado
 
Registrado: feb 2007
Posts: 9
Poder: 0
Anagnostes Va por buen camino
Perfecto, pues ya me funciona a mi tambien. Lo dejo aqui para si a alguien le sirve.

Al final lo que he hecho es copiar todas las units de "C:\Program Files (x86)\Embarcadero\RAD Studio\7.0\source\Win32\soap" a una carpeta dentro del proyecto. Compilar el proyecto con los defines de USE_INDY y INDY_CUSTOM_IOHANDLER, para que el THTTPRIO use Indy al hacer el post.

Luego configurar el TIdSSLIOHandlerSocketOpenSSL tal y como comenta YellowStone y pasarselo al HTTPRIO asi:

HTTPRIO1.HTTPWebNode.IOHandler := IdSSLIOHandlerSocketOpenSSL1;

Ahora voy a pulir el codigo, pero recibo una respuesta ya de AEAT en formato SOAP.

Gracias a todos
Responder Con Cita
  #3  
Antiguo 23-01-2025
Ramon88 Ramon88 is offline
Miembro
 
Registrado: ago 2021
Posts: 157
Poder: 5
Ramon88 Va por buen camino
Hola!
Voy a ponerme con las pruebas de SII...
No encuentro información clara, no sé si alguien podría decirme si en alguna página esta todo o donde puedo encontrarlo...
Endpoint, XML de ejemplo, documentos con los esquemas...

Llevo un ratito pegándome en esta web: https://sede.agenciatributaria.gob.e...icios-web.html
Pero no encuentro lo que comento...

Veo que necesito certificado de prueba, o eso me dice ChatGPT... sabéis de donde puedo sacarlo?

Última edición por Ramon88 fecha: 23-01-2025 a las 19:45:50.
Responder Con Cita
  #4  
Antiguo 24-01-2025
Anagnostes Anagnostes is offline
Registrado
 
Registrado: feb 2007
Posts: 9
Poder: 0
Anagnostes Va por buen camino
Justo la web que comentas es la web oficial donde està todo. De hecho todos los puntos que pones que no encuentras estan alli:

Endpoint -> WSDL de los servicios web
XML -> Descripción del servicio web ( en el pdf )
documentos con los esquemas -> Esquemas

Certificado es con el tuyo de FNMT o del que hace las presentaciones. No recuerdo mucho en el caso del SII pero todos los servicios de AEAT tienen un EndPoint de pruebas.
Responder Con Cita
  #5  
Antiguo 30-01-2025
APO APO is offline
Miembro
 
Registrado: feb 2008
Posts: 129
Poder: 19
APO Va por buen camino
En un ordenador con W10 Pro y Framework 4.8 también nos sigue dando el mismo error:

Received content of invalid Content-Type setting: text/html - SOAP expects "text/xml"

También hemos agregado la entrada TLS 1.2 en el registro, pero no hay manera.
¿Os ha pasado con algún W10?
Responder Con Cita
  #6  
Antiguo 30-01-2025
Anagnostes Anagnostes is offline
Registrado
 
Registrado: feb 2007
Posts: 9
Poder: 0
Anagnostes Va por buen camino
Si, a mi también me ha pasado con un W10 pero como no puedo ver la respuesta del SOAP y que texto HTML devuelve directamente no he seguido mirando el problema.

Estoy a la espera de poder hacer el cambio de todo el sistema SOAP a Indy como puse en un mensaje anterior y luego lo volveré a provar a estos clientes.
Responder Con Cita
  #7  
Antiguo 30-01-2025
Ramon88 Ramon88 is offline
Miembro
 
Registrado: ago 2021
Posts: 157
Poder: 5
Ramon88 Va por buen camino
Creo que eso se puede activar en las características del Windows.
Responder Con Cita
  #8  
Antiguo 31-01-2025
Ramon88 Ramon88 is offline
Miembro
 
Registrado: ago 2021
Posts: 157
Poder: 5
Ramon88 Va por buen camino
Perdonar mi ignorancia, pensaba que esto sería más sencillo y no saco nada en claro, me he leído varias páginas del post, pero es infinito!
Veo que importáis el WDSL, esto nunca lo he hecho, es para generar el XML? o para que?
Yo trabajo con visual studio, pero como me ayudasteis muchísimo en el tema de TicketBai, pues siempre os leo...

El proceso es:
1- Generar XML
2- Subirlo logeandote con certificado?

Por favor arrojarme algo de luz!(o a los leones...)
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
TICKET BAI (TicketBAI); Nuevo sistema de la Agencia Tributaria del Pais Vasco keys Internet 4524 Hace 1 Semana 16:17:40
AEAT envio de datos vía Webservice problemas con WSDL CelsoO Internet 11 09-10-2019 20:03:41
webService Soap de la Administración Digital Española notific@ apicito Internet 3 31-01-2017 11:25:28
Error en Webservice funcion envio de sms webmasterplc Delphi para la web 5 25-07-2013 20:10:29
Problemas con envío de XML a un WebService davidvamo Internet 1 13-02-2007 15:49:20


La franja horaria es GMT +2. Ahora son las 21:06:26.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi