VM暫存
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

216 líneas
7.8KB

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /*
  3. file: Acer_service.php 與 acer 介接相關都放這支
  4. */
  5. // ----- 定義常數(路徑, cache秒數) -----
  6. define('APP_VERSION', '100'); // 版本號
  7. define('MAX_AGE', 604800); // cache秒數, 此定義1個月
  8. define('APP_NAME', 'acer_service'); // 應用系統名稱
  9. define('PAGE_PATH', APP_BASE.'ci_application/views/'.APP_NAME.'/'); // path of views
  10. define('SERVER_URL', 'http://'.(isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost').'/'); // URL
  11. define('APP_URL', SERVER_URL.APP_NAME.'.html/'); // controller路徑
  12. define('WEB_URL', SERVER_URL.APP_NAME.'/'); // 網頁路徑
  13. define('WEB_LIB', SERVER_URL.'/libs/'); // 網頁lib
  14. define('BOOTSTRAPS', WEB_LIB.'bootstrap_sb/'); // bootstrap lib
  15. define('LOG_PATH', FILE_BASE.APP_NAME.'/logs/'); // log path name
  16. define('LOG_FILE', FILE_BASE.APP_NAME.'/logs/acer_service.'); // log file name
  17. class Acer_service extends CI_Controller
  18. {
  19. var $vars = array();
  20. function __construct()
  21. {
  22. parent::__construct();
  23. $method_name = $this->router->fetch_method();
  24. if (in_array($method_name, array('cmd_101', 'cmd_102')))
  25. {
  26. ob_end_clean();
  27. ignore_user_abort();
  28. ob_start();
  29. header('Connection: close');
  30. header('Content-Length: ' . ob_get_length());
  31. ob_end_flush();
  32. flush();
  33. }
  34. ignore_user_abort(); // 接受client斷線, 繼續run
  35. $this->vars['date_time'] = date('Y-m-d H:i:s'); // 格式化時間(2015-10-12 14:36:21)
  36. $this->vars['time_num'] = str_replace(array('-', ':', ' '), '', $this->vars['date_time']); //數字化時間(20151012143621)
  37. $this->vars['date_num'] = substr($this->vars['time_num'], 0, 8); // 數字化日期(20151012)
  38. $this->vars['station_no'] = STATION_NO; // 本站編號
  39. // session_id(ip2long($_SERVER['REMOTE_ADDR'])); // 設定同一device為同一個session
  40. session_start();
  41. // ----- 程式開發階段log設定 -----
  42. if (@ENVIRONMENT == 'development')
  43. {
  44. ini_set('display_errors', '1');
  45. //error_reporting(E_ALL ^ E_NOTICE);
  46. error_reporting(E_ALL);
  47. }
  48. set_error_handler(array($this, 'error_handler'), E_ALL); // 資料庫異動需做log
  49. $this->load->model('acer_service_model');
  50. $this->acer_service_model->init($this->vars);
  51. // 阻檔未知的 IP
  52. if(!in_array($_SERVER['HTTP_X_REAL_IP'], array('127.0.0.1')))
  53. {
  54. trigger_error('refused://from:'.$_SERVER['HTTP_X_REAL_IP'].'..refused..');
  55. exit;
  56. }
  57. }
  58. // 發生錯誤時集中在此處理
  59. public function error_handler($errno, $errstr, $errfile, $errline, $errcontext)
  60. {
  61. $log_msg = explode('://', $errstr);
  62. if (count($log_msg) > 1)
  63. {
  64. $log_file = $log_msg[0];
  65. $str = date('H:i:s')."|{$log_msg[1]}|{$errfile}|{$errline}|{$errno}\n";
  66. }
  67. else
  68. {
  69. $log_file = APP_NAME;
  70. $str = date('H:i:s')."|{$errstr}|{$errfile}|{$errline}|{$errno}\n";
  71. }
  72. error_log($str, 3, LOG_PATH.$log_file . '.' . date('Ymd').'.log.txt'); // 3代表參考後面的檔名
  73. }
  74. // 顯示logs
  75. public function show_logs()
  76. {
  77. $lines = $this->uri->segment(3); // 顯示行數
  78. if (empty($lines)) $lines = 100; // 無行數參數, 預設為40行
  79. // echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><pre style="white-space: pre-wrap;">';
  80. echo '<html lang="zh-TW"><body><pre style="white-space: pre-wrap;">';
  81. passthru('/usr/bin/tail -n ' . $lines . ' ' . LOG_PATH.APP_NAME . '.' . date('Ymd').'.log.txt'); // 利用linux指令顯示倒數幾行的logs內容
  82. echo "\n----- " . LOG_PATH.APP_NAME . '.' . date('Ymd').'.log.txt' . ' -----';
  83. echo '</pre></body></html>';
  84. }
  85. // 票卡入場訊號,供 ALTOB 登記
  86. public function cmd_001()
  87. {
  88. $card_no = $this->input->post('card_no', true);
  89. $cario_no = $this->input->post('cario_no', true);
  90. $card_type = $this->input->post('card_type', true);
  91. trigger_error(__FUNCTION__ . ", card_no:{$card_no}, cario_no:{$cario_no}, card_type:{$card_type}");
  92. $data = $this->acer_service_model->cmd_001($card_no, $cario_no, $card_type);
  93. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  94. }
  95. // 票卡離場訊號,供 ALTOB 登記
  96. public function cmd_002()
  97. {
  98. $card_no = $this->input->post('card_no', true);
  99. $pay_time = $this->input->post('pay_time', true);
  100. $card_type = $this->input->post('card_type', true);
  101. trigger_error(__FUNCTION__ . ", card_no:{$card_no}, pay_time:{$pay_time}, card_type:{$card_type}");
  102. $data = $this->acer_service_model->cmd_002($card_no, $pay_time, $card_type);
  103. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  104. }
  105. // 票號離場訊號,回傳若成功觸發 ACER 開門
  106. public function cmd_003()
  107. {
  108. $ticket_no = $this->input->post('ticket_no', true);
  109. trigger_error(__FUNCTION__ . ", ticket_no:{$ticket_no}");
  110. $data = $this->acer_service_model->cmd_003($ticket_no);
  111. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  112. }
  113. // 車辨入場訊號,觸發 ACER 開門
  114. public function cmd_101()
  115. {
  116. $cario_no = $this->input->post('cario_no', true);
  117. $in_time = $this->input->post('in_time', true);
  118. $ticket_no = $this->input->post('ticket_no', true);
  119. $lpr = $this->input->post('lpr', true);
  120. $ivs_no = $this->input->post('ivs_no', true);
  121. trigger_error(__FUNCTION__ . ", cario_no:{$cario_no}, in_time:{$in_time}, ticket_no:{$ticket_no}, lpr:{$lpr}, ivs_no:{$ivs_no}");
  122. $data = $this->acer_service_model->cmd_101($cario_no, $in_time, $ticket_no, $lpr, $ivs_no);
  123. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  124. }
  125. // 車辨離場訊號,觸發 ACER 開門 (若入場編號為 0, 表示車辨失敗)
  126. public function cmd_102()
  127. {
  128. $cario_no = $this->input->post('cario_no', true);
  129. $ivs_no = $this->input->post('ivs_no', true);
  130. $msg_code = $this->input->post('msg_code', true);
  131. /* msg_code:
  132. 1 離場車辨失敗
  133. 2 離場會員鎖車
  134. 5 會員車離場
  135. 6 臨停車離場 (時間內離場, 已繳費)
  136. 7 臨停車離場 (超過離場時限, 歐pa卡繳費)
  137. 8 臨停車未付款 (時間內離場, 無繳費)
  138. 9 臨停車未付款 (超過離場時限, 非歐pa卡會員)
  139. 10 會員車離場 (無入場資料)
  140. 12 臨停車未付款 (超過離場時限, 歐pa卡餘額不足)
  141. 13 無入場記錄
  142. 16 時段月租戶超時(月租)
  143. */
  144. trigger_error(__FUNCTION__ . ", cario_no:{$cario_no}, ivs_no:{$ivs_no}, msg_code:{$msg_code}");
  145. $data = $this->acer_service_model->cmd_102($cario_no, $ivs_no, $msg_code);
  146. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  147. }
  148. // 測試 acer cmd 101
  149. public function test_acer_cmd_101()
  150. {
  151. // input
  152. $cario_no = '1234567890'; // 入場編號: 10 碼
  153. $in_time = '2017-04-25 15:15:15'; // 入場時間: 19碼
  154. $ticket_no = '123456'; // 六碼數字
  155. $lpr = 'ABC123';
  156. $ivsno = 1; // 車道編號
  157. $data = $this->acer_service_model->cmd_101($cario_no, $in_time, $ticket_no, $lpr, $ivsno);
  158. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  159. }
  160. // 測試 acer cmd 102
  161. public function test_acer_cmd_102()
  162. {
  163. // input
  164. $cario_no = '1234567890'; // 入場編號: 10 碼
  165. $ivsno = 1; // 車道編號
  166. $data = $this->acer_service_model->cmd_102($cario_no, $ivsno);
  167. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  168. }
  169. }