Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Internet
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Colaboración Paypal con ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 23-01-2025
Anagnostes Anagnostes is offline
Registrado
 
Registrado: feb 2007
Posts: 9
Poder: 0
Anagnostes Va por buen camino
Si ya se lo del SO. Pero segun veo se puede activar, por ejemplo des de support.microsoft.com/es-es/topic/actualizar-para-habilitar-tls-1-1-y-tls-1-2-como-protocolos-seguros-predeterminados-en-winhttp-en-windows-c4bd73d2-31d7-761e-0178-11268bb10392 indican como habilitarlo en SO antiguos. Queria saber si alguien lo ha provado antes y le ha funcionado.

Me parece dificil de entender que de un dia por otro no podamos hacer llamadas a AEAT des de Servidores porque tienen Windows Server 2008 o 2012. Ya se que tienen años pero seguimos teniendo clientes con estos SO.
Responder Con Cita
  #2  
Antiguo 23-01-2025
Avatar de YellowStone
YellowStone YellowStone is offline
Miembro
 
Registrado: feb 2007
Ubicación: Adeje
Posts: 170
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 Windows, Dialogs, SysUtils, Messages, Classes, xmldom, XMLDoc, XMLIntf, DateUtils, StrUtils, IdHTTP, IdSSLOpenSSL;

type

  
{ Forward Decls }

  
IXMLContribuyenteType = interface;

{ 
IXMLContribuyenteType }

  
IXMLContribuyenteType = interface(IXMLNode)
    [
'{501E2A2E-11EB-42A7-A9D1-D1D7FA481B5B}']
    { 
Property Accessors }
    function 
Get_Nif: WideString;
    function 
Get_Nombre: WideString;
    function 
Get_Resultado: WideString;
    
procedure Set_Nif(Value: WideString);
    
procedure Set_Nombre(Value: WideString);
    
procedure Set_Resultado(Value: WideString);
    { 
Methods & Properties }
    
property Nif: WideString read Get_Nif write Set_Nif;
    
property Nombre: WideString read Get_Nombre write Set_Nombre;
    
property Resultado: WideString read Get_Resultado write Set_Resultado;
  
end;

{ 
Forward Decls }

  
TXMLContribuyenteType = class;

{ 
TXMLContribuyenteType }

  
TXMLContribuyenteType = class(TXMLNode, IXMLContribuyenteType)
  protected
    { 
IXMLContribuyenteType }
    function 
Get_Nif: WideString;
    function 
Get_Nombre: WideString;
    function 
Get_Resultado: WideString;
    
procedure Set_Nif(Value: WideString);
    
procedure Set_Nombre(Value: WideString);
    
procedure Set_Resultado(Value: WideString);
  
end;

  
TGetCertificado = class(Tobject)
  
procedure hServidorGetPassword(var Password: string);
  
end;

{ Global 
Functions }

function 
GetContribuyente(Doc: IXMLDocument): IXMLContribuyenteType;
function 
NewContribuyente: IXMLContribuyenteType;
function 
VerificaNIFAEAT(var nif: string; var nombre: string): boolean; // versión indy
function LimpiaRespuesta(respuesta: string): string;

const

  
TargetNamespace = '';

implementation

var rDatosEmisor: TDatosEmisor;
    
bCertificado: boolean;

{ Global 
Functions }

function 
GetContribuyente(Doc: IXMLDocument): IXMLContribuyenteType;
begin
  Result 
:= Doc.GetDocBinding('Contribuyente', TXMLContribuyenteType, TargetNamespace) as IXMLContribuyenteType;
end;

function 
NewContribuyente: IXMLContribuyenteType;
begin
  Result 
:= NewXMLDocument.GetDocBinding('Contribuyente', TXMLContribuyenteType, TargetNamespace) as IXMLContribuyenteType;
end;

{ 
TXMLContribuyenteType }

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

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

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

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

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

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

//Versión Indy
function VerificaNIFAEAT(var nif: string; var nombre: string): boolean;
var 
Respuesta: TStringList;
    
ixmlDoc: IXMLDocument;
    
hServidor: TIdHTTP;
    
LHandler: TIdSSLIOHandlerSocketOpenSSL;
    
stRequest: TStringStream;
    
sXML, sURL: string;
    
salida: IXMLContribuyenteType;
    
rGetCertificado: TGetCertificado;
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(respuesta: string): string;
var 
iIni, iLon: integer;
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(result, iIni, iLon);
  
result := StringReplace(result, 'VNifV2Sal:', '', [rfReplaceAll]);
end;

procedure TGetCertificado.hServidorGetPassword(var Password: string);
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
  #3  
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
  #4  
Antiguo 23-01-2025
Ramon88 Ramon88 is offline
Miembro
 
Registrado: ago 2021
Posts: 157
Poder: 6
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
  #5  
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
  #6  
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
  #7  
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
  #8  
Antiguo 30-01-2025
Ramon88 Ramon88 is offline
Miembro
 
Registrado: ago 2021
Posts: 157
Poder: 6
Ramon88 Va por buen camino
Creo que eso se puede activar en las características del Windows.
Responder Con Cita
Respuesta



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 4530 02-07-2026 14:09:59
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 20:55:06.


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