Quantcast
Channel: Tópicos
Viewing all articles
Browse latest Browse all 14700

Utilizar Webservices da AT

$
0
0
Continuo sem conseguir comunicar por PHP e tenho quase a certeza que quando testei isto à um ano atrás funcionou. Alguém consegue-me dizer se tenho de mudar alguma parametrização para fazer a comunicação? $xml = '<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>599999993/37</wss:Username> <wss:Password>ikCyRV+SWfvZ5c6Q0bhrBQ==</wss:Password> <wss:Nonce> fkAHne7cqurxpImCfBC8EEc2vskyUyNofWi0ptIijYg4gYCxir++unzfPVPpusloEtmLkcZjf+E6 T9/76tsCqdupUkxOhWtkRH5IrNwmfEW1ZGFQgYTF21iyKBRzMdsJMhhHrofYYV/YhSPdT4dlgG0t k9Z736jFuw061mP2TNqHcR/mQR0yW/AEOC6RPumqO8OAfc9/b4KFBSfbpY9HRzbD8bKiTo20n0Pt amZevCSVHht4yt/Xwgd+KV70WFzyesGVMOgFRTWZyXyXBVaBrkJS8b6PojxADLcpWRnw5+YeOs3c PU2o1H/YgAam1QuEHioCT2YTdRt+9p6ARNElFg== </wss:Nonce> <wss:Created>>YEWoIoqIY5DOD11SeXz+0i4b/AJg1/RgNcOHOYpSxGk</wss:Created> </wss:UsernameToken> </wss:Security> </S:Header> <S:Body> <ns2:RegisterInvoiceElem xmlns:ns2="http://servicos.portaldasfinancas.gov.pt/faturas/"> <TaxRegistrationNumber>222222222</TaxRegistrationNumber> <ns2:InvoiceNo>FT 1/1</ns2:InvoiceNo> <ns2:InvoiceDate>2012-05-05</ns2:InvoiceDate> <ns2:InvoiceType>FT</ns2:InvoiceType> <ns2:InvoiceStatus>N</ns2:InvoiceStatus> <CustomerTaxID>111111111</CustomerTaxID> <Line> <ns2:DebitAmount>100</ns2:DebitAmount> <ns2:Tax><ns2:TaxType>IVA</ns2:TaxType> <ns2:TaxCountryRegion>PT</ns2:TaxCountryRegion> <ns2:TaxPercentage>23</ns2:TaxPercentage> </ns2:Tax> </Line> <DocumentTotals> <ns2:TaxPayable>23</ns2:TaxPayable> <ns2:NetTotal>100</ns2:NetTotal> <ns2:GrossTotal>123</ns2:GrossTotal> </DocumentTotals> </ns2:RegisterInvoiceElem> </S:Body> </S:Envelope> '; $cert_pem = 'E:/xampp2/htdocs/pfxcert.pem'; $key_pem = 'E:/xampp2/htdocs/pfxKey.pem'; $pass_cert = 'TESTEwebservice'; $Action = "https://servicos.portaldasfinancas.gov.pt:701/sgdtws/documentosTransporte"; $SoapAction = "https://servicos.portaldasfinancas.gov.pt/sgdtws/documentosTransporte/"; $curl = curl_init(trim($Action)); curl_setopt($curl, CURLOPT_FRESH_CONNECT, TRUE); curl_setopt($curl, CURLOPT_HTTPHEADER,array( 'Content-Type:text/xml;Charset=UTF-8', 'Accept: text/xml', 'Cache-Control: no-cache', 'SoapAction='.$SoapAction )); curl_setopt($curl, CURLOPT_URL, trim($Action)); curl_setopt($curl, CURLOPT_SSLVERSION, 3); curl_setopt($curl, CURLOPT_VERBOSE, TRUE); // para ver o que se passa... curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $xml); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_SSLCERT, $cert_pem); // o certificado em formato PEM (.pem) curl_setopt($curl, CURLOPT_SSLCERTTYPE, 'PEM'); curl_setopt($curl, CURLOPT_SSLCERTPASSWD, $pass_cert); curl_setopt($curl, CURLOPT_SSLKEY, $key_pem); curl_setopt($curl, CURLOPT_SSLKEYPASSWD, $pass_cert); curl_setopt($curl, CURLOPT_SSLKEYTYPE, 'PEM'); curl_setopt($curl, CURLOPT_SSL_CIPHER_LIST, 'TLSv1'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($curl); var_dump( $response); var_dump(curl_error($curl)); print curl_errno($curl); curl_close($curl);

Viewing all articles
Browse latest Browse all 14700