정부24 Korean ID Verification
// 주의 !! - 주민등록번호는 아래에 해당하지 않는 경우 수집 불가
// 1. 법률, 대통령령, 국회규칙, 대법원규칙, 헌법재판소규칙, 중앙선거관리위원회 규칙 및 감사원규칙에서 구체적으로 주민번호의 처리를 요구하거나 허용한 경우
// 2. 정보주체 또는 제3자의 급박한 생명, 신체, 재산의 이익을 위해 명백히 필요하다고 인정되는 경우
// 3. 제1호 및 제2호에 준하여 주민번호 처리가 불가피한 경우로서 행정안전부령으로 정하는 경우
const https = require('https')
const axios = require('axios')
const success = { valid: true }
const fail = { valid: false }
exports.endpoint = function (req, res) {
const options = {
name: req.url.split('/?name=')[1].split('&')[0], // 이름
rrn1: req.url.split('&rrn1=')[1].split('&')[0], // 주민등록번호 앞자리
rrn2: req.url.split('&rrn2=')[1].split('&')[0] //주민등록번호 뒷자리
}
const urlparams = '?userDtlSectCd=101&userNm=' + options.name + '&userNm_unicd=' + setEncode(options.name) + '&rrn1=' + options.rrn1 + '&rrn2=' + options.rrn2 + '&gpinAuthRetPage=https://www.gov.kr/nlogin/usr/identifyUser&isTouchYn=&'
axios({
url: encodeURI('https://www.gov.kr/nlogin/usr/identifyUser' + urlparams),
responseType: 'arraybuffer',
reponseEncoding: 'binary',
httpsAgent: new https.Agent({
rejectUnauthorized: false,
}),
method: 'POST',
}).then((response) => {
const html = new TextDecoder('euc-kr').decode(response.data)
try {
if (html.split('$(window).load(function() {')[1].split('var msg = "')[1].split('"')[0] == '실명인증이 완료되었습니다.') {
res.end(JSON.stringify(success))
}
} catch (e) {
try {
if (html.split('// i-pin 실명인증 오류시 i-pin tab으로 이동')[1].split('var msg = "')[1].split('"')[0] == '이미 가입되어 있는 정보입니다. 로그인이나 아이디 찾기를 진행하여 주시기 바랍니다.') {
res.end(JSON.stringify(success))
} else {
res.end(JSON.stringify(fail))
}
} catch (e) {
console.log(e)
res.end(e)
return
}
}
})
}
// 아래는 정부24 홈페이지에서 가져온 코드.
function setEncode(value) {
return encodeURIComponent(charToUnicd(value))
}
function charToUnicd(str) {
var unicode = ""
var realCode = []
for (var i = 0; i < str.length; i++) {
realCode[i] = str.charCodeAt(i)
var unicd = "&#" + realCode[i] + ""
unicode += unicd
}
return unicode
}
no comments