time_start = microtime(true); parent::__construct(); ignore_user_abort(); // 接受client斷線, 繼續run $this->vars['date_time'] = date('Y-m-d H:i:s'); // 格式化時間(2015-10-12 14:36:21) $this->vars['time_num'] = str_replace(array('-', ':', ' '), '', $this->vars['date_time']); //數字化時間(20151012143621) $this->vars['date_num'] = substr($this->vars['time_num'], 0, 8); // 數字化日期(20151012) //$this->vars['station_no'] = STATION_NO; // 本站編號 // session_id(ip2long($_SERVER['REMOTE_ADDR'])); // 設定同一device為同一個session session_start(); // ----- 程式開發階段log設定 ----- if (@ENVIRONMENT == 'development') { ini_set('display_errors', '1'); //error_reporting(E_ALL ^ E_NOTICE); error_reporting(E_ALL); } set_error_handler(array($this, 'error_handler'), E_ALL); // 資料庫異動需做log /* // 共用記憶體 $this->vars['mcache'] = new Memcache; $this->vars['mcache']->pconnect(MEMCACHE_HOST, MEMCACHE_POST) or die ('Could not connect memcache'); // mqtt subscribe $this->vars['mqtt'] = new phpMQTT(MQ_HOST, MQ_PORT, uniqid()); if(!$this->vars['mqtt']->connect()){ die ('Could not connect mqtt'); } */ $this->load->model('carpayment_model'); $this->carpayment_model->init($this->vars); } // 發生錯誤時集中在此處理 public function error_handler($errno, $errstr, $errfile, $errline, $errcontext) { $log_msg = explode('://', $errstr); if (count($log_msg) > 1) { $log_file = $log_msg[0]; $str = date('H:i:s')."|{$log_msg[1]}|{$errfile}|{$errline}|{$errno}\n"; } else { $log_file = APP_NAME; $str = date('H:i:s')."|{$errstr}|{$errfile}|{$errline}|{$errno}\n"; } error_log($str, 3, LOG_PATH.$log_file . '.' . date('Ymd').'.log.txt'); // 3代表參考後面的檔名 } // 顯示logs public function show_logs() { $lines = $this->uri->segment(3); // 顯示行數 if (empty($lines)) $lines = 100; // 無行數參數, 預設為40行 // echo '
';
        echo '
';      
       
		passthru('/usr/bin/tail -n ' . $lines . '  ' . LOG_PATH.APP_NAME . '.' . date('Ymd').'.log.txt');	// 利用linux指令顯示倒數幾行的logs內容 
        echo "\n----- " . LOG_PATH.APP_NAME . '.' . date('Ymd').'.log.txt' . ' -----';   
        echo '
'; } // http://localhost/carpayment.html/p2payed/ (post method) // 可用$this->input->is_cli_request()判斷是否在cli之下執行 // 博辰aps已付款 public function p2payed() { $parms['ticket_no'] = $this->input->post('ticket_no', true); $parms['lpr'] = trim($this->input->post('lpr', true)); $parms['in_time'] = $this->input->post('in_time', true); $parms['pay_time'] = $this->input->post('pay_time', true); $parms['pay_type'] = $this->input->post('pay_type', true); trigger_error('博辰付款參數:' . print_r($parms, true)); $this->carpayment_model->p2payed($parms); } /* 月租繳款完成 http://203.75.167.89/carpayment.html/memberpayed/12345/ABC1234/120/12112/1/2016-01-31/1f3870be274f6c49b3e31a0c6728957f http://203.75.167.89/carpayment.html/memberpayed/會員號碼/車牌/金額/場站編號/月繳/本期到期日/md5 md5(會員號碼.車牌.金額.場站編號.月繳.本期到期日) public function memberpayed() { $parms['member_no'] = $lines = $this->uri->segment(3); $parms['lpr'] = $lines = $this->uri->segment(4); $parms['amt'] = $lines = $this->uri->segment(5); $parms['station_no'] = $lines = $this->uri->segment(6); $parms['period_type'] = $lines = $this->uri->segment(7); $parms['expire_date'] = $lines = $this->uri->segment(8); $md5 = $this->uri->segment(9); if (md5($parms['member_no'].$parms['lpr'].$parms['amt'].$parms['station_no'].$parms['seqno'].$parms['period_type'].$parms['expire_date']) === $md5) { $this->carpayment_model->memberpayed($parms); } } */ // 繳費機告知已付款 (new 2016/07/15) // http://localhost/carpayment.html/ats2payed/車牌/金額/場站編號/序號/MD5 // md5(車牌.金額.場站編號.序號) public function ats2payed() { $result = []; $parms['lpr'] = $lines = $this->uri->segment(3); $parms['amt'] = $lines = $this->uri->segment(4); $parms['station_no'] = $lines = $this->uri->segment(5); $parms['order_no'] = $lines = $this->uri->segment(6); $md5 = $this->uri->segment(7); if (md5($parms['lpr'].$parms['amt'].$parms['station_no'].$parms['order_no']) === $md5) { $this->carpayment_model->ats2payed($parms); } } // 行動支付, 手機告知已付款 // http://203.75.167.89/carpayment.html/m2payed/ABC1234/120/12112/12345/1f3870be274f6c49b3e31a0c6728957f // http://203.75.167.89/carpayment.html/m2payed/車牌/金額/場站編號/序號/MD5 // md5(車牌.金額.場站編號.序號) public function m2payed() { $parms['lpr'] = $lines = $this->uri->segment(3); $parms['amt'] = $lines = $this->uri->segment(4); $parms['station_no'] = $lines = $this->uri->segment(5); $parms['seqno'] = $lines = $this->uri->segment(6); $md5 = $this->uri->segment(7); echo $this->carpayment_model->m2payed($parms); /* $seqno = !empty($_SESSION['seqno']) ? $_SESSION['seqno'] : 0; unset($_SESSION['seqno']); if ($parms['seqno'] != 0 && $parms['seqno'] == $seqno && md5($parms['lpr'].$parms['amt'].$parms['station_no'].$parms['seqno']) === $md5) { echo $this->carpayment_model->m2payed($parms); } else echo 'fail'; */ } // 查詢入場時間 public function query_in() { $lpr = $this->input->post('lpr', true); $data = $this->carpayment_model->query_in($lpr); echo json_encode($data); } // 查詢入場時間 (fuzzy) public function query_in_fuzzy() { $lpr = $this->input->post('lpr', true); $data = $this->carpayment_model->query_in_fuzzy($lpr); echo json_encode($data); } // 行動設備查詢入場時間 // http://203.75.167.89/carpayment.html/m2query_in/ABC1234/12112/1f3870be274f6c49b3e31a0c6728957f // http://203.75.167.89/carpayment.html/m2query_in/車牌/場站編號/MD5 // 回傳0: 失敗, 成功: 12345,60(第一欄位非0數字代表成功, 第二欄位為金額), 此值在付款時必需傳回, 否則視為非法 public function m2query_in() { $parms['lpr'] = $lines = $this->uri->segment(3); $parms['station_no'] = $lines = $this->uri->segment(4); $md5 = $this->uri->segment(5); // 驗證md5 if (md5($parms['lpr'].$parms['station_no']) === $md5) { $data = $this->carpayment_model->m2query_in($parms); } else { $data = 0; } $_SESSEION['seqno'] = $data; echo $data; } // 測試:回傳 seat_no // http://192.168.0.199/carpayment.html/test_seat_no/B2/123 public function test_seat_no() { $rows['group_id'] = $this->uri->segment(3); $rows['pksno'] = $this->uri->segment(4); //echo substr($rows['group_id'], 0, 1); echo (substr($rows['group_id'], 0, 1) == 'B' ? '-' : '0') . substr($rows['group_id'], 1, 1) . '_' . substr($rows['pksno'], -3); } }