FUNCTION RDOCLPT(TS_TOKEN)
LOCAL oHttp,Doc,cxmLbody,oIni,nHandle
LOCAL ts_exit:=.t.,tw_servidor:='',ts_mj1:='',ts_modulo:=.f.
LOCAL ts_servidor:="
https://sveqa.zofri.cl/sveProcDocWSN/Emision?WSDL"
if empty(ts_token)
msginfo('Debe Obtener un Token de Inicio para Autentificarse en Web Service','Token de Sesion')
return .f.
endif
cXmlBody:= '' +;
'<?xml version="1.0" encoding="utf-8"?>' + ;
'<soapenv:Envelope xmlns:soapenv="
http://schemas.xmlsoap.org/soap/envelope/" xmlns:cl="cl.zofri.sve" xmlns:wsn="
http://cl/zofri/sve/prd/wsn">'+;
' <soapenv:Header>'+;
' <cl:token>'+ts_token+'</cl:token>'+;
' </soapenv:Header>'+;
' <soapenv:Body>'+;
' <wsn:emisionDocumento>'+;
' <wsn:codigoAduaneroDoc>101-25-051206</wsn:codigoAduaneroDoc>'+;
' <wsn:tipoEmision>E</wsn:tipoEmision>'+;
' </wsn:emisionDocumento>'+;
' </soapenv:Body>'+;
'</soapenv:Envelope>'
TRY
oHttp := CreateObject( 'MSXML2.XMLHTTP.6.0' )
CATCH
oHttp := CreateObject( 'Microsoft.XMLHTTP' )
END
doc = CreateObject("MSXML2.DOMDocument.6.0")
oHttp:Open( "POST" , ts_servidor, .F. )
ohttp:SetRequestHeader( "Content-Type" , "text/xml; charset=utf-8" )
oHttp:SetRequestHeader( "Connection:", "Keep-Alive" )
doc:LoadXML( cXmlbody )
TRY
ohttp:Send( doc:xml )
CATCH
cErrorMsg:='No Se Pudo Enviar Documento XML...'+CRLF+CRLF+;
'Sin Conexion a Internet o Servidor Con Problemas'
msginfo(cErrorMsg,"Intente Nuevamente")
return .t.
END
// ?ohttp:status
//status 200 = OK
// 500 = ERROR
response = ohttp:responsetext
hb_memoWrit( "fileout.pdf", oHttp:ResponseBody )
//crear un archivo para leer tag
cFilename:="texto.xml"
MEMOWRIT( cfilename, response, .F. )
//leer archivo para extraer el factura pdf
CTXT:=MEMOREAD(CFILENAME)
pdfin:=at("%PDF-1.4",CTXT)
pdfend:=At("%EOF",CTXT)
largo:=pdfend-pdfin
Cresp:=substr(CTXT,pdfin,largo+4)
//SE CREA EL ARCHIVO PDF
CPDF:="TEXTO.PDF"
MEMOWRIT( cPdf, CRESP, .F. )
RETURN .T.