class.carhistory.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <?php
  2. include_once($_SERVER['DOCUMENT_ROOT']."/common/lib/KISA_SEED_CBC.php");
  3. class CarHistory {
  4. var $url = 'http://www.carhistory.or.kr:8810/dataTrans/carhistoryAPI3.car'; //운영
  5. // var $url = "http://www.carhistory.or.kr:8810/dataTrans/carhistoryAPI3Test.car"; //테스트
  6. var $joinCode = "2023013191";
  7. var $result_json = array();
  8. var $is_momile = "";
  9. var $rType = "J";
  10. var $devices = array();
  11. var $cd_car_history = 0;
  12. /*
  13. Constructor
  14. @param $apiKeyIn the server API key
  15. */
  16. function __construct($joinCode = "") {
  17. if($_SERVER['REMOTE_ADDR'] == '220.86.24.199') {
  18. // $this->url = 'http://www.carhistory.or.kr:8810/dataTrans/carhistoryAPI3Test.car';
  19. }
  20. // $this->joinCode = $joinCode;
  21. }
  22. function CarHistory($joinCode = ""){
  23. if($_SERVER['REMOTE_ADDR'] == '220.86.24.199') {
  24. // $this->url = 'http://www.carhistory.or.kr:8810/dataTrans/carhistoryAPI3Test.car';
  25. }
  26. // $this->joinCode = $joinCode;
  27. }
  28. function setIsMobile($is_mobile) {
  29. $this->is_mobile = $is_mobile;
  30. }
  31. function getIsMobile() {
  32. return $this->is_mobile;
  33. }
  34. function setrType($rType) {
  35. $this->rType = $rType;
  36. }
  37. function getrType() {
  38. return $this->rType;
  39. }
  40. function conv($str) {
  41. $str = strtolower(str_replace(",", "", $str));
  42. return $str;
  43. }
  44. function binhex($str) {
  45. // var_dump(unpack("C*", $str));
  46. $str = bin2hex($str);
  47. $r = round(strlen($str)/2);
  48. $ret = '';
  49. for($i=0;$i< $r;$i++) {
  50. $num = $i*2;
  51. $end = $num+2;
  52. if(!empty($ret)) {
  53. $ret.=",";
  54. }
  55. $ret.= substr($str, $num, 2);
  56. }
  57. return $ret;
  58. }
  59. function hexbin($str) {
  60. // var_dump(unpack("C*", $str));
  61. $str = str_replace(",", "", $str);
  62. $ret = hex2bin($str);
  63. return $ret;
  64. }
  65. function encrypt($bszIV, $bszUser_key, $str) {
  66. $str = $this->binhex($str);
  67. $planBytes = explode(",",$str);
  68. $keyBytes = explode(",",$bszUser_key);
  69. $IVBytes = explode(",",$bszIV);
  70. for($i = 0; $i < 16; $i++)
  71. {
  72. $keyBytes[$i] = hexdec($keyBytes[$i]);
  73. $IVBytes[$i] = hexdec($IVBytes[$i]);
  74. }
  75. for ($i = 0; $i < count($planBytes); $i++) {
  76. $planBytes[$i] = hexdec($planBytes[$i]);
  77. }
  78. if (count($planBytes) == 0) {
  79. return $str;
  80. }
  81. $ret = null;
  82. $bszChiperText = null;
  83. $pdwRoundKey = array_pad(array(),32,0);
  84. //방법 1
  85. $bszChiperText = KISA_SEED_CBC::SEED_CBC_Encrypt($keyBytes, $IVBytes, $planBytes, 0, count($planBytes));
  86. $r = count($bszChiperText);
  87. for($i=0;$i< $r;$i++) {
  88. $ret .= sprintf("%02X", $bszChiperText[$i]).",";
  89. }
  90. return substr($ret,0,strlen($ret)-1);
  91. }
  92. function decrypt($bszIV, $bszUser_key, $str) {
  93. $planBytes = explode(",",$str);
  94. $keyBytes = explode(",",$bszUser_key);
  95. $IVBytes = explode(",",$bszIV);
  96. for($i = 0; $i < 16; $i++)
  97. {
  98. $keyBytes[$i] = hexdec($keyBytes[$i]);
  99. $IVBytes[$i] = hexdec($IVBytes[$i]);
  100. }
  101. for ($i = 0; $i < count($planBytes); $i++) {
  102. $planBytes[$i] = hexdec($planBytes[$i]);
  103. }
  104. if (count($planBytes) == 0) {
  105. return $str;
  106. }
  107. $pdwRoundKey = array_pad(array(),32,0);
  108. $bszPlainText = null;
  109. $planBytresMessage = "";
  110. // 방법 1
  111. $bszPlainText = KISA_SEED_CBC::SEED_CBC_Decrypt($keyBytes, $IVBytes, $planBytes, 0, count($planBytes));
  112. for($i=0;$i< sizeof($bszPlainText);$i++) {
  113. $planBytresMessage .= sprintf("%02X", $bszPlainText[$i]).",";
  114. }
  115. $decHex = substr($planBytresMessage,0,strlen($planBytresMessage)-1);
  116. return $this->hexbin($decHex);
  117. }
  118. function strToHex($string){
  119. $hex='';
  120. for ($i=0; $i < strlen($string); $i++){
  121. $hex .= "," . dechex(ord($string[$i]));
  122. }
  123. return $hex;
  124. }
  125. function hexToStr($hex){
  126. $string='';
  127. for ($i=0; $i < strlen($hex)-1; $i+=2){
  128. $string .= chr(hexdec($hex[$i].$hex[$i+1]));
  129. }
  130. return $string;
  131. }
  132. function getHistory($data){
  133. $fields = array(
  134. 'joinCode' => $this->joinCode,
  135. 'sType' => $this->conv($data['sType']),
  136. 'memberID' => $this->conv($data['memberId']),
  137. 'carnum' => $this->conv($data['carNum']),
  138. 'carNumType' => $data['carNumType'],
  139. 'stdDate' => $data['stdDate'],
  140. 'rType' => $this->rType,
  141. );
  142. // print_r($fields);
  143. // Open connection
  144. $ch = curl_init();
  145. // Set the url, number of POST vars, POST data
  146. // curl_setopt( $ch, CURLOPT_URL, $this->url );
  147. curl_setopt( $ch, CURLOPT_URL, $this->url );
  148. curl_setopt( $ch, CURLOPT_POST, true );
  149. // curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
  150. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
  151. curl_setopt( $ch, CURLOPT_POSTFIELDS, $fields);
  152. // Execute post
  153. $result = curl_exec($ch);
  154. $info = curl_getinfo($ch);
  155. // print_r($info);
  156. $curl_error = curl_error($ch);
  157. // echo "$curl_error";
  158. // Close connection
  159. curl_close($ch);
  160. //response의 charset 이 UTF-8 + BOM 으로 추측되어 json_decode 를 두번으로 품
  161. $result = json_decode(str_replace("\ufeff", '', json_encode($result)));
  162. $result_json = json_decode($result, true);
  163. // print_r($result);
  164. // $result_json = json_decode($result, true);
  165. // print_r($result_json);
  166. // exit;
  167. if($_SERVER['REMOTE_ADDR'] == '220.86.24.199') {
  168. // print_r($result);
  169. // exit;
  170. }
  171. $result_json['r102_text'] = $this->get_r102($result_json['r102']);
  172. $result_json['r103_text'] = $this->get_r103($result_json['r103']);
  173. $this->result_json = $result_json;
  174. return $result_json;
  175. }
  176. function db_update($cd_car, $data, $ds_type = 'user') {
  177. //차량 정보는 사용자와 관리자가 나뉨
  178. //사용자의 경우에는 최종 하나의 row 만 ds_delind = 'N'이여야 하므로
  179. if($ds_type == 'user') {
  180. // $sql = "update car_history_master set
  181. // ds_delind = 'Y'
  182. // where cd_car = '$cd_car'
  183. // and ds_delind = 'N'
  184. // ";
  185. // $result = mysql_query($sql,$connect);
  186. }
  187. $sql="insert into car_history_master
  188. set
  189. cd_car = '$cd_car'
  190. , ds_type = '$ds_type'
  191. ,r000 = '".$this->result_json['r000']."'
  192. ,r001 = '".$this->result_json['r001']."'
  193. ,r002 = '".$this->result_json['r002']."'
  194. ,r003 = '".$this->result_json['r003']."'
  195. ,r004 = '".$this->result_json['r004']."'
  196. ,r005 = '".$this->result_json['r005']."'
  197. ,r101 = '".$this->result_json['r101']."'
  198. ,r102 = '".$this->result_json['r102']."'
  199. ,r103 = '".$this->result_json['r103']."'
  200. ,r104 = '".$this->result_json['r104']."'
  201. ,r105 = '".$this->result_json['r105']."'
  202. ,r106 = '".$this->result_json['r106']."'
  203. ,r107 = '".$this->result_json['r107']."'
  204. ,r108 = '".$this->result_json['r108']."'
  205. ,r109 = '".$this->result_json['r109']."'
  206. ,r111 = '".$this->result_json['r111']."'
  207. ,r401 = '".$this->result_json['r401']."'
  208. ,r402 = '".$this->result_json['r402']."'
  209. ,r403 = '".$this->result_json['r403']."'
  210. ,r404 = '".$this->result_json['r404']."'
  211. ,r405 = '".$this->result_json['r405']."'
  212. ,r406_01 = '".$this->result_json['r406-01']."'
  213. ,r407 = '".$this->result_json['r407']."'
  214. ,r408_01 = '".$this->result_json['r408-01']."'
  215. ,r409 = '".$this->result_json['r409']."'
  216. ,r410_01 = '".$this->result_json['r410-01']."'
  217. ,r201 = '".$this->result_json['r201']."'
  218. ,r202 = '".json_encode($this->result_json['r202'], JSON_UNESCAPED_UNICODE)."'
  219. ,r203 = '".json_encode($this->result_json['r203'], JSON_UNESCAPED_UNICODE)."'
  220. ,r204 = '".$this->result_json['r204']."'
  221. ,r205 = '".json_encode($this->result_json['r205'], JSON_UNESCAPED_UNICODE)."'
  222. ,r510 = '".$this->result_json['r510']."'
  223. ,r511_01 = '".$this->result_json['r511-01']."'
  224. ,r501 = '".$this->result_json['r501']."'
  225. ,r502 = '".addslashes(json_encode($this->result_json['r502'], JSON_UNESCAPED_UNICODE))."'
  226. ,r301 = '".$this->result_json['r301']."'
  227. ,r302 = '".$this->result_json['r302']."'
  228. ,r303 = '".$this->result_json['r303']."'
  229. ,r601 = '".$this->result_json['r601']."'
  230. ,r602 = '".json_encode($this->result_json['r602'], JSON_UNESCAPED_UNICODE)."'
  231. ,r701 = '".$this->result_json['r701']."'
  232. ,dt_insert = '".$data['dt_insert']."'
  233. ,nm_insert = '".$data['nm_insert']."'
  234. ,dt_update = '".$data['dt_update']."'
  235. ,nm_update = '".$data['nm_update']."'
  236. ,ds_delind = 'N'";
  237. $result = mysql_query($sql,$connect);
  238. $this->cd_car_history = mysql_insert_id();
  239. // echo $sql;
  240. // exit;
  241. if($_SERVER['REMOTE_ADDR'] == '220.86.24.199') {
  242. // echo $sql;
  243. // exit;
  244. }
  245. return $result;
  246. }
  247. function error($msg){
  248. echo "Android send notification failed with error:";
  249. echo "\t" . $msg;
  250. exit(1);
  251. }
  252. //차종 코드
  253. function get_r102($val) {
  254. $arr = array(
  255. '1' => "승용",
  256. '2' => "승합",
  257. '3' => "화물",
  258. '4' => "특수",
  259. );
  260. return $arr[$val];
  261. }
  262. //차종 코드
  263. function get_r103($val) {
  264. $arr = array(
  265. '1' => "관용",
  266. '2' => "자가용",
  267. '3' => "영업용",
  268. '4' => "특수",
  269. );
  270. return $arr[$val];
  271. }
  272. }