-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (40 loc) · 1.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const express = require('express')
const app = express()
const cors = require('cors')
const convert = require('xml-js');
const soapRequest = require('easy-soap-request');
app.use(cors())
app.use(express.json())
app.get("/:re&&:rr&&:tt&&:id", (request, res) => {
let { re, rr, tt, id } = request.params
re=re.replace(/&/gi, '&')
rr=rr.replace(/&/gi, '&')
console.log(re, rr, tt, id)
const url = 'https://consultaqr.facturaelectronica.sat.gob.mx/ConsultaCFDIService.svc';
const sampleHeaders = {
'user-agent': 'sampleTest',
'Content-Type': 'text/xml;charset=UTF-8',
'soapAction': 'http://tempuri.org/IConsultaCFDIService/Consulta',
};
const xml = `<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:Consulta>
<!--Optional:-->
<tem:expresionImpresa><![CDATA[?re=${re}?rr=${rr}?tt=${tt}?id=${id}]]>
</tem:expresionImpresa>
</tem:Consulta>
</soapenv:Body>
</soapenv:Envelope>`;
const data = async () => {
const { response } = await soapRequest({ url: url, headers: sampleHeaders, xml: xml });
const { body } = response;
res.send(convert.xml2json(body, { compact: true, spaces: 4 }))
}
data()
})
const PORT = process.env.PORT || 3000;
app.listen(PORT, (err) => {
if (err) throw err;
console.log("server corriendo en el puerto", PORT);
});