-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtcKimlikDogrulama.js
52 lines (47 loc) · 1.44 KB
/
tcKimlikDogrulama.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
48
49
50
51
52
const https = require('https')
const post = ({ options, body }) => {
return new Promise((resolve, reject) => {
const req = https.request(options, res => {
let data = ''
res.on('data', (chunk) => {
data += chunk
})
res.on('end', () => {
resolve(data)
})
})
if (body) req.write(body)
req.on('error', e => reject(e))
req.end()
})
}
module.exports = async ({ tcKimlikNo, ad, soyad, dogumYili }) => {
try {
const body = `<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<TCKimlikNoDogrula xmlns="http://tckimlik.nvi.gov.tr/WS">
<TCKimlikNo>${tcKimlikNo}</TCKimlikNo>
<Ad>${ad}</Ad>
<Soyad>${soyad}</Soyad>
<DogumYili>${dogumYili}</DogumYili>
</TCKimlikNoDogrula>
</soap12:Body>
</soap12:Envelope>`
const request = await post({
body,
options: {
port: 443,
method: 'post',
path: '/Service/KPSPublic.asmx',
hostname: 'tckimlik.nvi.gov.tr',
headers: { 'Content-Type': 'application/soap+xml' }
}
})
const searchPattern = '<TCKimlikNoDogrulaResult>(.*)</TCKimlikNoDogrulaResult>'
const foundPart = request.match(new RegExp(searchPattern))
return foundPart[1] === 'true'
} catch (err) {
console.log(err)
}
}