Error : peer certificate can not be authenticated...
Posted: Thu Aug 22, 2019 10:03 pm
Saludos amigos, yo de nuevo,
Estoy tratando de levantar mi primer documento electrónico al webservice de Sunat, este es mi código de prueba:
Pero al usar cualquiera de las dos opciones me lanza el error:
Ya probé instalando varios certificados, 2 de google y uno más de una empresa Llama.pe sin resultado.
Alguién que me eche una mano por fa.
Cordiales saludos.
Estoy tratando de levantar mi primer documento electrónico al webservice de Sunat, este es mi código de prueba:
Code: Select all
* ------------------------------------------------------ *
* SISTEMA : *
* PRG : *
* CREADO : *
* ACTUALIZADO : *
* AUTOR : *
* COMENTARIOS : *
* ------------------------------------------------------ *
#include <minigui.ch>
#include <hbcurl.ch>
FUNCTION MAIN
DEFINE WINDOW Win_1;
AT 0,0 ;
WIDTH 640 HEIGHT 460 ;
TITLE 'Consulta CPE' ;
ON INIT INISETS() ;
MAIN
DEFINE MAIN MENU
POPUP "&Operaciones"
ITEM '&1. Buscar CPE' ACTION CPE_Cons()
ITEM '&2. Enviar CPE a Sunat' ACTION CPE_Send()
END POPUP
END MENU
//
// BARRA DE ESTADO
//
DEFINE STATUSBAR
STATUSITEM "..."
CLOCK WIDTH 70
DATE WIDTH 90
END STATUSBAR
END WINDOW
CENTER WINDOW Win_1
ACTIVATE WINDOW Win_1
RETURN
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
* FUNCION...: INISETS
* COMENTARIO: INICIALIZA LOS SETEOS DEL SISTEMA.
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
PROC INISETS
SET BELL Off
SET CONSOLE Off
SET CURSOR Off
SET DATE TO BRIT
SET DELETED On
SET DELIMITERS Off
SET ECHO Off
SET EPOCH TO 1990
SET MESSAGE TO 22 CENTER
SET SAFETY Off
SET SCOREBOARD Off
SET TALK Off
SET WRAP On
ALTD(0)
RETURN
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
Proc CPE_Cons
LOCAL cxml
cxml := '<soapenv:Envelope xmlns:ser="http://service.sunat.gob.pe" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">'+chr(13)+chr(10)
cxml += '<soapenv:Header>'+chr(13)+chr(10)
cxml += '<wsse:Security>'+chr(13)+chr(10)
cxml += '<wsse:UsernameToken>'+chr(13)+chr(10)
cxml += '<wsse:Username>10074902419MODDATOS</wsse:Username>'+chr(13)+chr(10)
cxml += '<wsse:Password>moddatos</wsse:Password>'+chr(13)+chr(10)
cxml += '</wsse:UsernameToken>'+chr(13)+chr(10)
cxml += '</wsse:Security>'+chr(13)+chr(10)
cxml += '</soapenv:Header>'+chr(13)+chr(10)
cxml += '<soapenv:Body>'+chr(13)+chr(10)
cxml += '<ser:getStatus>'+chr(13)+chr(10)
cxml += '<rucComprobante>20101088881</rucComprobante>'+chr(13)+chr(10)
cxml += '<tipoComprobante>01</tipoComprobante>'+chr(13)+chr(10)
cxml += '<serieComprobante>F001</serieComprobante>'+chr(13)+chr(10)
cxml += '<numeroComprobante>00002869</numeroComprobante>'+chr(13)+chr(10)
cxml += '</ser:getStatus>'+chr(13)+chr(10)
cxml += '</soapenv:Body>'+chr(13)+chr(10)
cxml += '</soapenv:Envelope>'+chr(13)+chr(10)
canswer := SunatConsultar(cxml)
canswer := strtran(canswer,"><",">"+chr(10)+"<")
memowrit("soapanswer.txt",canswer)
RETURN
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
FUNC SunatConsultar(cxml)
local endpointUrl,curlHandle,curlErr
local aHeader,cc1
cc1 := ""
endpointUrl := "https://www.sunat.gob.pe/ol-it-wsconscpegem/billConsultService"
aHeader := {}
AADD(aHeader,'Content-Type: text/xml' )
AADD(aHeader,'Content-Type: text/xml;charset=ISO-8859-1' )
AADD(aHeader,'Content-Length: '+STR(len(cxml)) )
AADD(aHeader,'SOAPAction: getStatus' )
curlHandle := curl_easy_init()
if ! empty(curlHandle)
/* Specify the Header data */
curl_easy_setopt(curlHandle,HB_CURLOPT_HTTPHEADER,aHeader)
/* Set the endpoint to send the POST to */
curl_easy_setopt(curlHandle, HB_CURLOPT_URL, endpointUrl)
/* Setup response data */
curl_easy_setopt( curlHandle, HB_CURLOPT_DOWNLOAD )
curl_easy_setopt( curlHandle, HB_CURLOPT_DL_BUFF_SETUP )
/* Specify the POST data */
curl_easy_setopt(curlHandle, HB_CURLOPT_POST, 1)
curl_easy_setopt(curlHandle, HB_CURLOPT_POSTFIELDS, cxml)
/* Do everything */
curlErr := curl_easy_perform(curlHandle)
/* Report any errors */
if empty(curlErr)
/* store response in variable */
cc1 := curl_easy_dl_buff_get( curlHandle )
else
msginfo( curl_easy_strerror(curlErr) )
endif
else
msginfo( "No handle" )
endif
if ! empty(curlHandle)
/* Clean-up libcurl */
curl_global_cleanup( curlHandle )
else
msginfo( "Error" )
endif
if empty(cc1)
msginfo( "Error" )
endif
return cc1
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
PROC CPE_Send
LOCAL cxml
cxml := '<soapenv:Envelope xmlns:ser="http://service.sunat.gob.pe" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">'+chr(13)+chr(10)
cxml += ' <soapenv:Header>'+chr(13)+chr(10)
cxml += ' <wsse:Security>'+chr(13)+chr(10)
cxml += ' <wsse:UsernameToken>'+chr(13)+chr(10)
cxml += ' <wsse:Username>20600992571MODDATOS</wsse:Username>'+chr(13)+chr(10)
cxml += ' <wsse:Password>moddatos</wsse:Password>'+chr(13)+chr(10)
cxml += ' </wsse:UsernameToken>'+chr(13)+chr(10)
cxml += ' </wsse:Security>'+chr(13)+chr(10)
cxml += ' </soapenv:Header>'+chr(13)+chr(10)
cxml += ' <soapenv:Body>'+chr(13)+chr(10)
cxml += ' <ser:sendBill>'+chr(13)+chr(10)
cxml += ' <fileName>20600992571-01-F001-00000001.zip</fileName>'+chr(13)+chr(10)
cxml += ' <contentFile>cid:20600992571-01-F001-00000001.zip</contentFile>'+chr(13)+chr(10)
cxml += ' </ser:sendBill>'+chr(13)+chr(10)
cxml += ' </soapenv:Body>'+chr(13)+chr(10)
cxml += '</soapenv:Envelope>'+chr(13)+chr(10)
canswer := SunatEnviar(cxml)
canswer := strtran(canswer,"><",">"+chr(10)+"<")
memowrit( "sunat_cpe_respta.txt" , canswer )
RETURN
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
FUNC SunatEnviar(cxml)
local endpointUrl,curlHandle,curlErr
local aHeader,cc1
cc1 := ""
endpointUrl := "https://e-beta.sunat.gob.pe/ol-ti-itcpfegem-beta/billService"
aHeader := {}
AADD(aHeader,'Content-Type: text/xml' )
AADD(aHeader,'Content-Type: text/xml;charset=ISO-8859-1' )
AADD(aHeader,'Content-Length: '+STR(len(cxml)) )
AADD(aHeader,'SOAPAction: sendBill' )
curlHandle := curl_easy_init()
if ! empty(curlHandle)
/* Specify the Header data */
curl_easy_setopt(curlHandle,HB_CURLOPT_HTTPHEADER,aHeader)
/* Set the endpoint to send the POST to */
curl_easy_setopt(curlHandle, HB_CURLOPT_URL, endpointUrl)
/* Setup response data */
curl_easy_setopt( curlHandle, HB_CURLOPT_DOWNLOAD )
curl_easy_setopt( curlHandle, HB_CURLOPT_DL_BUFF_SETUP )
/* Specify the POST data */
curl_easy_setopt(curlHandle, HB_CURLOPT_POST, 1)
curl_easy_setopt(curlHandle, HB_CURLOPT_POSTFIELDS, cxml)
/* Do everything */
curlErr := curl_easy_perform(curlHandle)
/* Report any errors */
if empty(curlErr)
/* store response in variable */
cc1 := curl_easy_dl_buff_get( curlHandle )
else
msginfo( curl_easy_strerror(curlErr) )
endif
else
msginfo( "No handle" )
endif
if ! empty(curlHandle)
/* Clean-up libcurl */
curl_global_cleanup( curlHandle )
else
msginfo( "Error" )
endif
if empty(cc1)
msginfo( "Error" )
endif
return cc1
Ya probé instalando varios certificados, 2 de google y uno más de una empresa Llama.pe sin resultado.
Alguién que me eche una mano por fa.
Cordiales saludos.