| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- <?php
- include_once($_SERVER['DOCUMENT_ROOT']."/common/lib/KISA_SEED_CBC.php");
- class CarHistory {
- var $url = 'http://www.carhistory.or.kr:8810/dataTrans/carhistoryAPI3.car'; //운영
- // var $url = "http://www.carhistory.or.kr:8810/dataTrans/carhistoryAPI3Test.car"; //테스트
- var $joinCode = "2023013191";
- var $result_json = array();
- var $is_momile = "";
- var $rType = "J";
- var $devices = array();
- var $cd_car_history = 0;
- /*
- Constructor
- @param $apiKeyIn the server API key
- */
- function __construct($joinCode = "") {
- if($_SERVER['REMOTE_ADDR'] == '220.86.24.199') {
- // $this->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];
- }
- }
|