키스콘 건설업체 정보 서비스 (javascript, php)
html / javascript / php
<!-- 건설업체 검색 모달 시작 -->
<div class="modal fade" id="searchModal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">건설업 조회 서비스</h4>
<button type="button" class="close btn-sm" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<div class="row border-1 border-bottom pb-2">
<div class="col-2 small">기간설정</div>
<div class="col-10">
<div class="input-group input-group-sm">
<input type="date" name="s_date" id="s_date" class="form-control form-control-sm" value="">
<input type="date" name="e_date" id="e_date" class="form-control form-control-sm" value="">
</div>
</div>
</div>
<div class="row pt-2">
<div class="col-2 small">시도</div>
<div class="col-4">
<select class="form-control form-control-sm" name="ddl_sido" id="ddl_sido">
<option value=''></option>
<option value='서울특별시'>서울특별시</option>
<option value='부산광역시'>부산광역시</option>
<option value='대구광역시'>대구광역시</option>
<option value='인천광역시'>인천광역시</option>
<option value='광주광역시'>광주광역시</option>
<option value='대전광역시'>대전광역시</option>
<option value='울산광역시'>울산광역시</option>
<option value='세종특별자치시'>세종특별자치시</option>
<option value='경기도'>경기도</option>
<option value='강원도'>강원도</option>
<option value='충청북도'>충청북도</option>
<option value='충청남도'>충청남도</option>
<option value='전라북도'>전라북도</option>
<option value='전라남도'>전라남도</option>
<option value='경상북도'>경상북도</option>
<option value='경상남도'>경상남도</option>
<option value='제주특별자치도'>제주특별자치도</option>
</select>
</div>
<div class="col-2 small">시구군</div>
<div class="col-4">
<select class="form-control form-control-sm" name="ddl_gugun" id="ddl_gugun">
<option value=''></option>
</select>
</div>
</div>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" id="searchCompany" class="btn btn-info btn-sm">검색</button>
</div>
</div>
</div>
</div>
<!-- 건설업체 검색 모달 끝 -->
<script>
var sido = document.getElementById('ddl_sido');
var gugun = document.getElementById('ddl_gugun');
var btn = document.getElementById('searchCompany');
sido.addEventListener('change',function(){
$.ajax({
url:'./Db/get_gugun.php',
type:'post',
data:{sido : sido.value}
}).done(function(data){
while (gugun.firstChild) {
gugun.removeChild(gugun.firstChild);
}
var item = data.split('/');
for(var i =0;i<item.length;i++){
var opt = document.createElement('option');
opt.value= item[i];
opt.innerText= item[i];
gugun.appendChild(opt);
gugun.focus();
}
});
});
//건설업체 버튼 클릭시
btn.addEventListener('click',function(){
var sd = document.getElementById('s_date');
var ed = document.getElementById('e_date');
var si = document.getElementById('ddl_sido');
var gu = document.getElementById('ddl_gugun');
if(sd.value == ""){
alert('시작날짜를 입력하세요.');
sd.focus();
return false;
}
if(ed.value == ""){
alert('끝날짜를 입력하세요.');
ed.focus();
return false;
}
if(si.value == ""){
alert('시도를 선택해주세요.');
si.focus();
return false;
}
if(gu.value == ""){
alert('시군구를 선택해주세요.');
gu.focus();
return false;
}
var postData = {
page:'1',
pageperrow:'10',
s_date:sd.value,
e_date:ed.value,
sido:getSido(si.value),
gugun:gu.value
}
$.ajax({
url: './Db/get_gunsulsa_list.php',
type: 'POST',
data: postData,
success:function(data){
console.log('type of data = ' + typeof(data));
var obj = JSON.parse(data)
console.log('type of data = ' + typeof(obj));
console.log(obj);
console.log(obj.response.body.items.item);
for(var i=0;i<10;i++){
console.log(obj.response.body.items.item[i]);
}
}
});
});
function getSido(sido_name){
//Map 설정
var sido_arr = new Map();
sido_arr.set('서울특별시' , '서울');
sido_arr.set('부산광역시' , '부산');
sido_arr.set('대구광역시' , '대구');
sido_arr.set('인천광역시' , '인천');
sido_arr.set('광주광역시' , '광주');
sido_arr.set('대전광역시' , '대전');
sido_arr.set('울산광역시' , '울산');
sido_arr.set('세종특별자치시' , '세종시');
sido_arr.set('경기도' , '경기');
sido_arr.set('강원도' , '강원');
sido_arr.set('충청북도' , '충북');
sido_arr.set('충청남도' , '충남');
sido_arr.set('전라북도' , '전북');
sido_arr.set('전라남도' , '전남');
sido_arr.set('경상북도' , '경북');
sido_arr.set('경상남도' , '경남');
sido_arr.set('제주특별자치도' , '제주');
//console.log(sido_arr.size);
for(let [key, value] of sido_arr){
if(key == sido_name){
console.log(sido_name + " = " + key + " : " + value);
return value;
break;
}
}
}
var s_date = document.getElementById('s_date');
s_date.value = '2010-01-01';
var e_date = document.getElementById('e_date');
e_date.value = _today();
function _today(){
var date = new Date();
var yy = date.getFullYear();
var mm = date.getMonth()+1;
if(mm<10){
mm = '0' + mm;
}
var dd = date.getDate();
var result = yy + '-' + mm + '-' + dd;
return result;
}
</script>
<?php
$page = $_POST['page'];
$pageperrow = $_POST['pageperrow'];
$s_date = $_POST['s_date'];
$e_date = $_POST['e_date'];
$companyName = $_POST['company_name'];
$BizCode = $_POST['bizcode'];
$api_root = GetApiRoot($page, $pageperrow, $s_date, $e_date, $sido, $gugun);
$res = GetApiData($api_root);
//echo $api_root;
echo $res;
function parseData($response){
$xml = simplexml_load_string($response);
$json = json_encode($xml);
$arr_data = json_decode($json,TRUE);
return $arr_data;
}
function GetApiData($apiRoot){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiRoot);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
//curl_setopt($ch, CURLOPT_TIMEOUT, 30); // 타임아웃 추가
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
function GetApiRoot($_page, $_pageperrow, $_s_date, $_e_date, $_sido, $_gugun)
{
$apiKey = "K4A%2F3lJX6spsv%2Bxqcmzk8mxU53Fn4jOyb8VHPMl7HFVBm7JxrkMdp329vhtuGX4CFQAPoz0D6BrfmY5PM3yd3w%3D%3D";
/**
* &numOfRows=10
* &inqryDiv=1
* &inqryBgnDt=200101010000
* &inqryEndDt=200112312359
* &corpNm=주식회사청마토건
* &bizno=6168122531
* &type=json&pageNo=1
*/
$apiRoot = "http://apis.data.go.kr/1230000/UsrInfoService/getPrcrmntCorpBasicInfo";
$apiRoot .= "?serviceKey=".$apiKey;
$apiRoot .= "&pageNo=".$_page;
$apiRoot .= "&numOfRows=".$_pageperrow;
$apiRoot .= "&inqryDiv=".'3'; //1: 등록기준일 / 2: 변경기준일 3: 사업자등록번호 기준검색
$apiRoot .= '&inqryBgnDt='.$_s_date;
$apiRoot .= '&inqryEndDt='.$_e_date;
$apiRoot .= '&type='.'json' ;
$apiRoot .= '&corpNm='.urlencode($_sido);
$apiRoot .= '&bizno='.urlencode($_gugun);
return $apiRoot;
}
?>
댓글
댓글 쓰기