Documentos de Transporte Portugal y MSXML2.XMLHTTP

Documentos de Transporte Portugal y MSXML2.XMLHTTP

Postby fgondi » Wed Jul 28, 2021 8:08 am

Buenas,

Estoy intentando conectar con el webservice del Portal de finanças de Portugal, para el envío de documentos de transporte.

Y no consigo averiguar como establecer la comunicación.
No veo como enviar el certificado.

Code: Select all  Expand view
oHttp := CreateObject( "MSXML2.XMLHTTP" )
oHttp:Open( "POST", "https://servicos.portaldasfinancas.gov.pt/sgdtws/documentosTransporte/", .F. )
oHttp:SetRequestHeader("Content-Type" ,"text/xml;charset=UTF-8" )
oHttp:Send( cXml )


Code: Select all  Expand view
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
 <S:Header>
  <wss:Security xmlns:wss="http://schemas.xmlsoap.org/ws/2002/12/secext">
   <wss:UsernameToken>
    <wss:Username>770011055/1</wss:Username>
    <wss:Password>U2FsdGVkX19C08kTIChAGzoDiFgZxsunTpBdU96c8fl/XQSqTdnuA1PVW6R2FyID</wss:Password>
    <wss:Nonce>Auwkw0i3ndvJRG55YR5TbYnKp02BDoNJ/v+5YANfB4VS9qEEBxaOMXCRrx4I+08B
zy4jwJPHrDXnqQaRuNCXEUKNCnfLDVNJ5V0Pehm0tqAvT4cDvYSGRVZnd6dMOtfo
fBNSr3GTBfdSoLAoB1qf9SLtbBG/3cVrr6yOQtNKBGpCXruIKJFLVcBOWIRZbdgr
XFub3kK9HuGIMCujnhVpU1zOObkwK04k5Fpp9SXah5Ymyva6XKn/Oc5cva+5ZZ1d
+XuBBs/x02qQHj4M/yMrOti6+djba5ynr3yKXOr95o9Xm+Wl8ZeSoKi6CNFNnV6P
cSluU29ztsU3I/XSQaxK2A==</wss:Nonce>
    <wss:Created>U2FsdGVkX1/uZCMMWZYhdo3mkoFX1uVPY7MveUWYDFPfjezGLxrE+vzZH7Okb7Fa</wss:Created>
   </wss:UsernameToken>
  </wss:Security>
 </S:Header>
 <S:Body>
  <ns2:envioDocumentoTransporteRequestElem xmlns:ns2="https://servicos.portaldasfinancas.gov.pt/sgdtws/documentosTransporte/">
  .....
  </ns2:envioDocumentoTransporteRequestElem>
 </S:Body>
</S:Envelope>  
Un saludo
Fernando González Diez
ALSIS Sistemas Informáticos
User avatar
fgondi
 
Posts: 694
Joined: Fri Oct 07, 2005 6:58 am
Location: Palencia, España

Re: Documentos de Transporte Portugal y MSXML2.XMLHTTP

Postby fgondi » Wed Jul 28, 2021 10:33 am

Code: Select all  Expand view
oDoc := CreateObject( "MSXML2.DOMDocument" )
oDoc:LoadXml( cXml )

oHttp := CreateObject( "MSXML2.ServerXMLHTTP.6.0" )
oHttp:SetOption(2,  13056)
oHttp:setOption(3, "TesteWebservices")
oHttp:Open( "POST", "https://servicos.portaldasfinancas.gov.pt:701/sgdtws/documentosTransporte", .F. )
   
oHttp:SetRequestHeader( "Content-Type" ,"text/xml; charset=UTF-8" )
oHttp:SetRequestHeader( "SOAPAction", "https://servicos.portaldasfinancas.gov.pt/sgdtws/documentosTransporte/")
oHttp:SetRequestHeader( "Accept" ,"text/xml" )
oHttp:SetRequestHeader( "Cache-Control", "no-cache" )
oHttp:SetRequestHeader( "Connection:", "Keep-Alive" )
oHttp:SetRequestHeader( "Content-length: ", Str( len( oDoc:xml ) ) )

oHttp:Send( oDoc:xml )


Ya he conseguido realizar el envío.
Aunque ahora el problema lo tengo con el cifrado openssl
Error:
Created: Chave de sessão inválida. Não foi possível decifrar o campo Created

Code: Select all  Expand view
openssl rand -base64 -out Simkey.txt 16
openssl enc -aes-128-ecb -in Simkey.txt -out Pass.b64 -pass file:Pass.txt -base64
openssl enc -aes-128-ecb -in Simkey.txt -out Time.b64 -pass file:Time.txt -base64
openssl rsautl -in Simkey.txt -encrypt -inkey chavepublicaat.pem -pubin | openssl enc -base64 -out Nonce.txt
Un saludo
Fernando González Diez
ALSIS Sistemas Informáticos
User avatar
fgondi
 
Posts: 694
Joined: Fri Oct 07, 2005 6:58 am
Location: Palencia, España

Re: Documentos de Transporte Portugal y MSXML2.XMLHTTP

Postby fgondi » Thu Jul 29, 2021 11:51 am

Ya lo he conseguido solucionar.
Estoy realizando envios sin problemas

Code: Select all  Expand view
openssl rand -out Simkey.txt 16

Grabar el resultado en la variable cKey
Code: Select all  Expand view
cKey := Alltrim( MemoRead( 'Simkey.txt' ) )
cKey := Hb_StrToHex(cKey)


Code: Select all  Expand view
openssl rsautl -encrypt -inkey ChaveCifraPublicaAT2023.pem -pubin -in Simkey.txt -out Nonce.Sha1
openssl enc -base64 -in Nonce.Sha1 -out Nonce.b64
openssl enc -base64 -aes-128-ecb -K '+cKey+' -in Pass.txt -out Pass.b64
openssl enc -base64 -aes-128-ecb -K '+cKey+' -in Time.txt -out Time.b64
Un saludo
Fernando González Diez
ALSIS Sistemas Informáticos
User avatar
fgondi
 
Posts: 694
Joined: Fri Oct 07, 2005 6:58 am
Location: Palencia, España


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 39 guests