url = 'http://www.carhistory.or.kr:8810/dataTrans/carhistoryAPI3Test.car'; } // $this->joinCode = $joinCode; } function CarHistory($joinCode = ""){ if($_SERVER['REMOTE_ADDR'] == '220.86.24.199') { // $this->url = 'http://www.carhistory.or.kr:8810/dataTrans/carhistoryAPI3Test.car'; } // $this->joinCode = $joinCode; } function setIsMobile($is_mobile) { $this->is_mobile = $is_mobile; } function getIsMobile() { return $this->is_mobile; } function setrType($rType) { $this->rType = $rType; } function getrType() { return $this->rType; } function conv($str) { $str = strtolower(str_replace(",", "", $str)); return $str; } function binhex($str) { // var_dump(unpack("C*", $str)); $str = bin2hex($str); $r = round(strlen($str)/2); $ret = ''; for($i=0;$i< $r;$i++) { $num = $i*2; $end = $num+2; if(!empty($ret)) { $ret.=","; } $ret.= substr($str, $num, 2); } return $ret; } function hexbin($str) { // var_dump(unpack("C*", $str)); $str = str_replace(",", "", $str); $ret = hex2bin($str); return $ret; } function encrypt($bszIV, $bszUser_key, $str) { $str = $this->binhex($str); $planBytes = explode(",",$str); $keyBytes = explode(",",$bszUser_key); $IVBytes = explode(",",$bszIV); for($i = 0; $i < 16; $i++) { $keyBytes[$i] = hexdec($keyBytes[$i]); $IVBytes[$i] = hexdec($IVBytes[$i]); } for ($i = 0; $i < count($planBytes); $i++) { $planBytes[$i] = hexdec($planBytes[$i]); } if (count($planBytes) == 0) { return $str; } $ret = null; $bszChiperText = null; $pdwRoundKey = array_pad(array(),32,0); //방법 1 $bszChiperText = KISA_SEED_CBC::SEED_CBC_Encrypt($keyBytes, $IVBytes, $planBytes, 0, count($planBytes)); $r = count($bszChiperText); for($i=0;$i< $r;$i++) { $ret .= sprintf("%02X", $bszChiperText[$i]).","; } return substr($ret,0,strlen($ret)-1); } function decrypt($bszIV, $bszUser_key, $str) { $planBytes = explode(",",$str); $keyBytes = explode(",",$bszUser_key); $IVBytes = explode(",",$bszIV); for($i = 0; $i < 16; $i++) { $keyBytes[$i] = hexdec($keyBytes[$i]); $IVBytes[$i] = hexdec($IVBytes[$i]); } for ($i = 0; $i < count($planBytes); $i++) { $planBytes[$i] = hexdec($planBytes[$i]); } if (count($planBytes) == 0) { return $str; } $pdwRoundKey = array_pad(array(),32,0); $bszPlainText = null; $planBytresMessage = ""; // 방법 1 $bszPlainText = KISA_SEED_CBC::SEED_CBC_Decrypt($keyBytes, $IVBytes, $planBytes, 0, count($planBytes)); for($i=0;$i< sizeof($bszPlainText);$i++) { $planBytresMessage .= sprintf("%02X", $bszPlainText[$i]).","; } $decHex = substr($planBytresMessage,0,strlen($planBytresMessage)-1); return $this->hexbin($decHex); } function strToHex($string){ $hex=''; for ($i=0; $i < strlen($string); $i++){ $hex .= "," . dechex(ord($string[$i])); } return $hex; } function hexToStr($hex){ $string=''; for ($i=0; $i < strlen($hex)-1; $i+=2){ $string .= chr(hexdec($hex[$i].$hex[$i+1])); } return $string; } function getHistory($data){ $fields = array( 'joinCode' => $this->joinCode, 'sType' => $this->conv($data['sType']), 'memberID' => $this->conv($data['memberId']), 'carnum' => $this->conv($data['carNum']), 'carNumType' => $data['carNumType'], 'stdDate' => $data['stdDate'], 'rType' => $this->rType, ); // print_r($fields); // Open connection $ch = curl_init(); // Set the url, number of POST vars, POST data // curl_setopt( $ch, CURLOPT_URL, $this->url ); curl_setopt( $ch, CURLOPT_URL, $this->url ); curl_setopt( $ch, CURLOPT_POST, true ); // curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $fields); // Execute post $result = curl_exec($ch); $info = curl_getinfo($ch); // print_r($info); $curl_error = curl_error($ch); // echo "$curl_error"; // Close connection curl_close($ch); //response의 charset 이 UTF-8 + BOM 으로 추측되어 json_decode 를 두번으로 품 $result = json_decode(str_replace("\ufeff", '', json_encode($result))); $result_json = json_decode($result, true); // print_r($result); // $result_json = json_decode($result, true); // print_r($result_json); // exit; if($_SERVER['REMOTE_ADDR'] == '220.86.24.199') { // print_r($result); // exit; } $result_json['r102_text'] = $this->get_r102($result_json['r102']); $result_json['r103_text'] = $this->get_r103($result_json['r103']); $this->result_json = $result_json; return $result_json; } function db_update($cd_car, $data, $ds_type = 'user') { //차량 정보는 사용자와 관리자가 나뉨 //사용자의 경우에는 최종 하나의 row 만 ds_delind = 'N'이여야 하므로 if($ds_type == 'user') { // $sql = "update car_history_master set // ds_delind = 'Y' // where cd_car = '$cd_car' // and ds_delind = 'N' // "; // $result = mysql_query($sql,$connect); } $sql="insert into car_history_master set cd_car = '$cd_car' , ds_type = '$ds_type' ,r000 = '".$this->result_json['r000']."' ,r001 = '".$this->result_json['r001']."' ,r002 = '".$this->result_json['r002']."' ,r003 = '".$this->result_json['r003']."' ,r004 = '".$this->result_json['r004']."' ,r005 = '".$this->result_json['r005']."' ,r101 = '".$this->result_json['r101']."' ,r102 = '".$this->result_json['r102']."' ,r103 = '".$this->result_json['r103']."' ,r104 = '".$this->result_json['r104']."' ,r105 = '".$this->result_json['r105']."' ,r106 = '".$this->result_json['r106']."' ,r107 = '".$this->result_json['r107']."' ,r108 = '".$this->result_json['r108']."' ,r109 = '".$this->result_json['r109']."' ,r111 = '".$this->result_json['r111']."' ,r401 = '".$this->result_json['r401']."' ,r402 = '".$this->result_json['r402']."' ,r403 = '".$this->result_json['r403']."' ,r404 = '".$this->result_json['r404']."' ,r405 = '".$this->result_json['r405']."' ,r406_01 = '".$this->result_json['r406-01']."' ,r407 = '".$this->result_json['r407']."' ,r408_01 = '".$this->result_json['r408-01']."' ,r409 = '".$this->result_json['r409']."' ,r410_01 = '".$this->result_json['r410-01']."' ,r201 = '".$this->result_json['r201']."' ,r202 = '".json_encode($this->result_json['r202'], JSON_UNESCAPED_UNICODE)."' ,r203 = '".json_encode($this->result_json['r203'], JSON_UNESCAPED_UNICODE)."' ,r204 = '".$this->result_json['r204']."' ,r205 = '".json_encode($this->result_json['r205'], JSON_UNESCAPED_UNICODE)."' ,r510 = '".$this->result_json['r510']."' ,r511_01 = '".$this->result_json['r511-01']."' ,r501 = '".$this->result_json['r501']."' ,r502 = '".addslashes(json_encode($this->result_json['r502'], JSON_UNESCAPED_UNICODE))."' ,r301 = '".$this->result_json['r301']."' ,r302 = '".$this->result_json['r302']."' ,r303 = '".$this->result_json['r303']."' ,r601 = '".$this->result_json['r601']."' ,r602 = '".json_encode($this->result_json['r602'], JSON_UNESCAPED_UNICODE)."' ,r701 = '".$this->result_json['r701']."' ,dt_insert = '".$data['dt_insert']."' ,nm_insert = '".$data['nm_insert']."' ,dt_update = '".$data['dt_update']."' ,nm_update = '".$data['nm_update']."' ,ds_delind = 'N'"; $result = mysql_query($sql,$connect); $this->cd_car_history = mysql_insert_id(); // echo $sql; // exit; if($_SERVER['REMOTE_ADDR'] == '220.86.24.199') { // echo $sql; // exit; } return $result; } function error($msg){ echo "Android send notification failed with error:"; echo "\t" . $msg; exit(1); } //차종 코드 function get_r102($val) { $arr = array( '1' => "승용", '2' => "승합", '3' => "화물", '4' => "특수", ); return $arr[$val]; } //차종 코드 function get_r103($val) { $arr = array( '1' => "관용", '2' => "자가용", '3' => "영업용", '4' => "특수", ); return $arr[$val]; } }