diff --git a/controllers/Cars.php b/controllers/Cars.php index 48823c5..f2774f2 100644 --- a/controllers/Cars.php +++ b/controllers/Cars.php @@ -57,7 +57,7 @@ class Cars extends CI_Controller ob_end_flush(); flush(); } - else if($method_name == 'opendoor') + else if($method_name == 'opendoor' || $method_name == 'temp_opendoors' || $method_name == 'member_opendoors') { ob_end_clean(); ignore_user_abort(); @@ -237,6 +237,38 @@ http://192.168.10.201/cars.html/ipcam/sno/12119/ivsno/0/io/O/type/C/lpr/4750YC/c $this->cars_model->check_lpr_etag($lpr, $etag); exit; } + + // 開門 (臨停) + public function temp_opendoors() + { + $parms['ivsno'] = $this->uri->segment(3); + $parms['lpr'] = $this->uri->segment(4); + $parms['ck'] = $this->uri->segment(5); + + // 載入 + $this->load->model('cars_model'); + $this->cars_model->init($this->vars); + $result = $this->cars_model->do_temp_opendoor($parms); + trigger_error(__FUNCTION__ . "..{$result}.." . print_r($parms, true)); + $this->cars_model->stop(); + exit; + } + + // 開門 (臨停) + public function member_opendoors() + { + $parms['ivsno'] = $this->uri->segment(3); + $parms['lpr'] = $this->uri->segment(4); + $parms['ck'] = $this->uri->segment(5); + + // 載入 + $this->load->model('cars_model'); + $this->cars_model->init($this->vars); + $result = $this->cars_model->do_member_opendoor($parms); + trigger_error(__FUNCTION__ . "..{$result}.." . print_r($parms, true)); + $this->cars_model->stop(); + exit; + } public function test_now() { diff --git a/models/Cars_model.php b/models/Cars_model.php index 49a0d69..927f18a 100644 --- a/models/Cars_model.php +++ b/models/Cars_model.php @@ -845,6 +845,7 @@ class Cars_model extends CI_Model return $rows; } + /* // 開門 (月租) public function member_opendoors($parms) { @@ -858,7 +859,7 @@ class Cars_model extends CI_Model $this->mq_send(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},TICKET,{$parms['lpr']}"); return true; } - + */ // 用eTag讀出車號 public function etag2lpr_2($etag) @@ -1168,6 +1169,54 @@ class Cars_model extends CI_Model $this->vars['mqtt']->publish($topic, $msg, 0); trigger_error("mqtt:{$topic}|{$msg}"); } + + // 產生 CK + public function gen_opendoor_ck($parms) + { + return md5($parms['ivsno']. 'alt' . date('dmh') . 'ob' . $parms['lpr']); + } + + // 開門 (月租) + public function member_opendoors($parms) + { + //$this->mq_send_opendoor(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},OPEN,{$parms['lpr']}"); + $ck = $this->gen_opendoor_ck($parms); + get_headers("http://localhost/cars.html/member_opendoors/{$parms['ivsno']}/{$parms['lpr']}/{$ck}"); + return true; + } + + // 開門 (臨停) + public function temp_opendoors($parms) + { + //$this->mq_send_opendoor(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},TICKET,{$parms['lpr']}"); + $ck = $this->gen_opendoor_ck($parms); + get_headers("http://localhost/cars.html/temp_opendoors/{$parms['ivsno']}/{$parms['lpr']}/{$ck}"); + return true; + } + + // 開門 (月租) + public function do_member_opendoor($parms) + { + if($parms['ck'] != $this->cars_model->gen_opendoor_ck($parms)) + { + return 'ck_error'; // 中斷 + } + + $this->mq_send(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},OPEN,{$parms['lpr']}"); + return 'ok'; + } + + // 開門 (臨停) + public function do_temp_opendoor($parms) + { + if($parms['ck'] != $this->cars_model->gen_opendoor_ck($parms)) + { + return 'ck_error'; // 中斷 + } + + $this->mq_send(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},TICKET,{$parms['lpr']}"); + return 'ok'; + } // 指派車位