우편번호 검색 소스를 공개하고자 한다.

우편번호 검색은 data.go.kr에서 제공하는 openapi를 이용하여 제작하였다

사용된 언어는 ASP와 자바스크립트로 구성되어 있다

먼저 asp소스를 공개한다.

 

 

 

<% @CodePage = "65001" %>
<%
'************************************************************************************
' 단위업무명 : 우편번호 검색화면
' 작  성  자 : 가치노을(pobiplus@gmail.com) http://www.newnnow.co.kr
' 작  성  일  : 2011-12-01
' 수  정  자  :
' 수  정  일 :
' 내   용 : data.go.kr에서 우편번호 API를 이용한 우편번호 검색화면
' 주의  사항 :
'************************************************************************************
response.buffer = True
Response.Charset = "UTF-8"
%>
<%
 gubun = request("gubun") 'road - 도로명과 건물번호로 검색 dong- 동(읍/면/리)명과 지번으로 검색 , oldpost-구 지번 검색
 if (IsNULL(gubun) OR len(gubun) < 1) then
  gubun = "road"
 end if

 searchKey = trim(request("searchKey")) '도로명
 MainNo = trim(request("MainNo")) '건물 주번호
 SubNo = trim(request("SubNo")) '건물 부번호
 inSearch = searchKey
 if len(MainNo) > 0 then
  inSearch = inSearch & " " & MainNo
 end if
 if len(SubNo) > 0 then
  inSearch = inSearch & "-" & SubNo
 end if
 
 rows = 0

 if not IsNULL(inSearch) and len(inSearch) then
  '도로명 주소 중 한글 처리를 위한 변환 루틴
  Session.CodePage=949
  Response.CharSet = "euc-kr"
  
  cngSearch = server.URLEncode(inSearch)
  
  Session.CodePage=28591
  Response.CharSet = "ISO-8859-1"
  
  cngSearch = URLDecode(cngSearch)
  
  Session.CodePage=65001
  Response.CharSet = "utf-8"
  
  cngSearch = server.URLEncode(cngSearch)
  
  '주소 정보 가져오기
  if gubun = "oldpost" then
   sPath ="http://openapi.epost.go.kr/postal/retrieveLotNumberAdressService/retrieveLotNumberAdressService/getDetailList?searchSe=dong&srchwrd="&cngSearch&"&serviceKey="&server.URLEncode("인증키")&""
  else
   sPath = "http://openapi.epost.go.kr/postal/retrieveNewAdressService/retrieveNewAdressService/getNewAddressList?searchSe="&gubun&"&srchwrd="&cngSearch&"&serviceKey=인증키"
  end if

  Set oDOM = Server.CreateObject("Microsoft.XMLDOM")
  with oDOM
      .async = False ' 동기식 호출
      .setProperty "ServerHTTPRequest", True ' HTTP로 XML 데이터 가져옴
      .Load(sPath)
  end with  
    
  successYN = "Y"
  
  Set ResultNodes = oDOM.selectNodes("//cmmMsgHeader")
  
  if ResultNodes.Length > 0 then
   For each ResultSubNodes in ResultNodes
    successYN = ResultSubNodes.getElementsByTagName("successYN")(0).Text
   next
  end if
  Set ResultNodes = nothing
  
  ' XML 에서 반복적인 상위키를 기준으로 가져옵니다.
  if successYN = "Y" then
   if gubun = "oldpost" then
    Set Nodes = oDOM.selectNodes("//detailList")
   else
    Set Nodes = oDOM.selectNodes("//newAddressList")
   end if
   
   rows = Nodes.Length
  else
   rows = 0
  end if
  
 end if

 

'특수문자 변환작업
 Function URLDecode(sConvert)
     Dim aSplit
     Dim sOutput
     Dim I
     If IsNull(sConvert) Then
        URLDecode = ""
        Exit Function
     End If
 
     ' convert all pluses to spaces
     sOutput = REPLACE(sConvert, "+", " ")
 
     ' next convert %hexdigits to the character
     aSplit = Split(sOutput, "%")
 
     If IsArray(aSplit) Then
       sOutput = aSplit(0)
       For I = 0 to UBound(aSplit) - 1
         sOutput = sOutput & _
           Chr("&H" & Left(aSplit(i + 1), 2)) &_
           Right(aSplit(i + 1), Len(aSplit(i + 1)) - 2)
       Next
     End If
 
     URLDecode = sOutput
 End Function

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
<title>우편번호 검색</title>
<link rel="stylesheet" type="text/css" href="/css/__style.css" />
<link type="text/css" rel="stylesheet" href="/css/__post.css" />
<script type="text/javascript" language="javascript" charset="utf-8" src="postxml.js"></script>

</head>
<body onload="fnInit('<%=gubun%>')">
 
<div id="wrap_pop">
 <h1><img src="/images/tit_post.jpg" alt="우편번호 검색" /></h1>
 <p id="btnClose"><a href="javascript:self.close();" title="팝업창 닫기"><img src="/images/close.gif" alt="CLOSE" /></a></p>
 
 <div id="popBox" class="pd-inF">
     <!-- contents --> 
  
  <fieldset>
   <div class="zip_srchbox" id="srch1">
          <form action="zipcode.asp" method="post" class="zip_w" name="srch_f" onsubmit="return fnCheckForm(this);">
     <input type="hidden" name="searchKey" value="" />
     <input type="hidden" name="MainNo" value="" />
     <input type="hidden" name="SubNo" value="" />
    <legend>우편번호 상세검색</legend>
    <!-- 검색구분 선택 -->
     <dl class="dlline">
      <dt><strong><label for="sido">검색 구분</label></strong></dt>
      <dd>
       <select id="gubun" title="검색 구분" name="gubun" onchange="fnGubun(this)">
        <option value="road">도로명+건물번호</option>
        <option value="dong">동(읍/면/리)명+지번</option>
        <option value="oldpost">구 지번</option>
       </select>
      </dd>
 
      <dt><strong><label for="gugun">검색어</label></strong></dt>
      <dd>
       <input id="keyword" type="text" class="srch_btn" title="검색어를 입력하세요!" style="IME-MODE:active;" value="<%=inSearch%>"  onclick="this.style.backgroundImage='';" onkeydown="this.style.backgroundImage='';" onblur="eventonblur(this);" size="25" name="keyword" />
       <input type="image" alt="검색" src="/images/zip_srch.gif" />
      </dd>
     </dl>
          </form>

   </div>
   
   <!-- 검색안내 -->
   <div class="zip_info">
    <p id="notitab3_list"><span class="first">*</span> 검색방법 : 도로명(~로,~길)+건물번호<br />
     ☞ 서울시 중구 <em>소공로  70</em>일 경우<br />
       예) <em>소공로</em>(도로명)&nbsp;<em>70</em>(건물번호)
    </p>
    <p id="notitab4_list">
    <span class="first">※</span> 도로명인 "성남대로997번길"인 경우 한 단어이므로 다음과 같이 띄워쓰기 없이 쓰셔야 합니다. <br />
       ☞성남대로, 성남대로997번, 성남대로997번길
    </p>
    
    <p id="notitab5_list" style="display:none"><span class="first">*</span> 검색방법 : 도로명(~로,~길)+건물번호<br />
     ☞ 서울시 중구 <em>충무로1가 20-1</em> 일 경우<br />
      예) <em>충무로1가</em>(동명)&nbsp;<em>20-1</em>(지번)
    </p>

    <p id="notitab6_list" style="display:none"><span class="first">*</span> 검색방법 : 읍/면/동/건물명 등 검색어 입력<br />
     ☞ 서울시 중구 <em>충무로1가</em> 일 경우<br />
      예) <em>충무로1가</em>(검색어)
    </p>

    <p>
    <span class="first">※</span> 도로명주소가 검색되지 않는 경우는 <strong>행정안전부 새주소 안내시스템 (<a href="http://juso.go.kr" target="_blank" title="새창열림">http://juso.go.kr</a>) 에서 <br />
     확인</strong>하시기 바랍니다
    </p>
   </div>
   <!-- //검색안내 -->

   <!-- 검색결과 -->
   <div class="srch_result">
    <table class="zip_t" summary="우편번호, 도로명주소, 지번주소">
     <caption>우편번호 검색결과</caption>
     <colgroup>
      <col width="14%"></col>
      <col width="86%"></col>
     </colgroup>
     <thead>
      <tr>
       <th>우편번호</th>
       <th>주소</th>
      </tr>
     </thead>
     <tbody>
   <%
   if rows > 0 then
    For each SubNodes in Nodes
     if gubun = "oldpost" then
      zipcode = SubNodes.getElementsByTagName("zipNo")(0).Text
      post_address = SubNodes.getElementsByTagName("adres")(0).Text
      strPostAddr = post_address
     else
      zipcode = SubNodes.getElementsByTagName("zipNo")(0).Text
      post_address = SubNodes.getElementsByTagName("lnmAdres")(0).Text
      dong_address = SubNodes.getElementsByTagName("rnAdres")(0).Text
      strPostAddr = post_address & "<BR />(" & dong_address & ")"
     end if
   %>
      <tr>
       <td><strong><a href="#" onclick="use_post('<%=zipcode%>','<%=post_address%>');"><%=zipcode%></a></strong></td>
       <td style="text-align:left;"><%=strPostAddr%></td>
      </tr> 
    <%Next%>
   <%Else%>
      <tr>
       <td colspan="2" class="none"><strong>- 검색결과가 없습니다. -</strong></td>
      </tr>
   <%End If%>
     </tbody>
    </table>
   </div>
   <!-- //검색결과 -->

  </fieldset>
  
        <!-- // contents -->
    </div>
</div>
<%
set oDOM = nothing
set Nodes = nothing
%>
</body>
</html>
 

top