VM暫存
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

243 řádky
9.2KB

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /*
  3. file: Carpayment.php 停車計費
  4. http://192.168.10.201/carpayment.html/query_in/ (查詢入場時間)
  5. http://192.168.10.201/carpayment.html/p2payed/
  6. */
  7. // ----- 定義常數(路徑, cache秒數) -----
  8. define('APP_VERSION', '100'); // 版本號
  9. define('MAX_AGE', 604800); // cache秒數, 此定義1個月
  10. define('APP_NAME', 'carpayment'); // 應用系統名稱
  11. define('PAGE_PATH', APP_BASE.'ci_application/views/'.APP_NAME.'/'); // path of views
  12. define('SERVER_URL', 'http://'.(isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost').'/'); // URL
  13. define('APP_URL', SERVER_URL.APP_NAME.'.html/'); // controller路徑
  14. define('WEB_URL', SERVER_URL.APP_NAME.'/'); // 網頁路徑
  15. define('WEB_LIB', SERVER_URL.'/libs/'); // 網頁lib
  16. define('BOOTSTRAPS', WEB_LIB.'bootstrap_sb/'); // bootstrap lib
  17. define('LOG_PATH', FILE_BASE.APP_NAME.'/logs/'); // log path name
  18. define('LOG_FILE', FILE_BASE.APP_NAME.'/logs/carpayment.'); // log file name
  19. class Carpayment extends CI_Controller
  20. {
  21. var $vars = array();
  22. function __construct()
  23. {
  24. // $this->time_start = microtime(true);
  25. parent::__construct();
  26. ignore_user_abort(); // 接受client斷線, 繼續run
  27. $this->vars['date_time'] = date('Y-m-d H:i:s'); // 格式化時間(2015-10-12 14:36:21)
  28. $this->vars['time_num'] = str_replace(array('-', ':', ' '), '', $this->vars['date_time']); //數字化時間(20151012143621)
  29. $this->vars['date_num'] = substr($this->vars['time_num'], 0, 8); // 數字化日期(20151012)
  30. //$this->vars['station_no'] = STATION_NO; // 本站編號
  31. // session_id(ip2long($_SERVER['REMOTE_ADDR'])); // 設定同一device為同一個session
  32. session_start();
  33. // ----- 程式開發階段log設定 -----
  34. if (@ENVIRONMENT == 'development')
  35. {
  36. ini_set('display_errors', '1');
  37. //error_reporting(E_ALL ^ E_NOTICE);
  38. error_reporting(E_ALL);
  39. }
  40. set_error_handler(array($this, 'error_handler'), E_ALL); // 資料庫異動需做log
  41. /*
  42. // 共用記憶體
  43. $this->vars['mcache'] = new Memcache;
  44. $this->vars['mcache']->pconnect(MEMCACHE_HOST, MEMCACHE_POST) or die ('Could not connect memcache');
  45. // mqtt subscribe
  46. $this->vars['mqtt'] = new phpMQTT(MQ_HOST, MQ_PORT, uniqid());
  47. if(!$this->vars['mqtt']->connect()){ die ('Could not connect mqtt'); }
  48. */
  49. $this->load->model('carpayment_model');
  50. $this->carpayment_model->init($this->vars);
  51. }
  52. // 發生錯誤時集中在此處理
  53. public function error_handler($errno, $errstr, $errfile, $errline, $errcontext)
  54. {
  55. $log_msg = explode('://', $errstr);
  56. if (count($log_msg) > 1)
  57. {
  58. $log_file = $log_msg[0];
  59. $str = date('H:i:s')."|{$log_msg[1]}|{$errfile}|{$errline}|{$errno}\n";
  60. }
  61. else
  62. {
  63. $log_file = APP_NAME;
  64. $str = date('H:i:s')."|{$errstr}|{$errfile}|{$errline}|{$errno}\n";
  65. }
  66. error_log($str, 3, LOG_PATH.$log_file . '.' . date('Ymd').'.log.txt'); // 3代表參考後面的檔名
  67. }
  68. // 顯示logs
  69. public function show_logs()
  70. {
  71. $lines = $this->uri->segment(3); // 顯示行數
  72. if (empty($lines)) $lines = 100; // 無行數參數, 預設為40行
  73. // echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><pre style="white-space: pre-wrap;">';
  74. echo '<html lang="zh-TW"><body><pre style="white-space: pre-wrap;">';
  75. passthru('/usr/bin/tail -n ' . $lines . ' ' . LOG_PATH.APP_NAME . '.' . date('Ymd').'.log.txt'); // 利用linux指令顯示倒數幾行的logs內容
  76. echo "\n----- " . LOG_PATH.APP_NAME . '.' . date('Ymd').'.log.txt' . ' -----';
  77. echo '</pre></body></html>';
  78. }
  79. // http://localhost/carpayment.html/p2payed/ (post method)
  80. // 可用$this->input->is_cli_request()判斷是否在cli之下執行
  81. // 博辰aps已付款
  82. public function p2payed()
  83. {
  84. $parms['ticket_no'] = $this->input->post('ticket_no', true);
  85. $parms['lpr'] = trim($this->input->post('lpr', true));
  86. $parms['in_time'] = $this->input->post('in_time', true);
  87. $parms['pay_time'] = $this->input->post('pay_time', true);
  88. $parms['pay_type'] = $this->input->post('pay_type', true);
  89. trigger_error('博辰付款參數:' . print_r($parms, true));
  90. $this->carpayment_model->p2payed($parms);
  91. }
  92. // MITAC 付款
  93. public function mitac2payed()
  94. {
  95. $cario_no = $this->input->post('cario_no', true); // 通訊序號
  96. $lpr = $this->input->post('lpr', true); // 車牌
  97. $amt = $this->input->post('amt', true); // 金額
  98. $amt_discount = $this->input->post('amt_discount', true); // 折扣
  99. $amt_real = $this->input->post('amt_real', true); // 實收
  100. $in_time = $this->input->post('in_time', true); // 入場時間
  101. $pay_time = $this->input->post('pay_time', true); // 付款時間
  102. $ck = $this->input->post('ck', true); // 驗証碼
  103. // 通訊內容
  104. $parms = array(
  105. 'cario_no' => $cario_no,
  106. 'lpr' => $lpr,
  107. 'amt' => $amt,
  108. 'amt_discount' => $amt_discount,
  109. 'amt_real' => $amt_real,
  110. 'in_time' => $in_time,
  111. 'pay_time' => $pay_time);
  112. if($ck != md5($parms['cario_no']. 'a' . date('dmh') . 'l' . $parms['lpr'] . 't'. $parms['amt']. 'o'. $parms['amt_discount'] . 'b'. $parms['amt_real'] . __FUNCTION__))
  113. {
  114. trigger_error(__FUNCTION__ . '..ck_error..' . print_r($parms, true));
  115. exit; // 中斷
  116. }
  117. $parms['pay_type'] = 93; // MITAC 專用
  118. trigger_error('MITAC 付款:' . print_r($parms, true));
  119. // 註記已離場
  120. $this->carpayment_model->p2payed($parms, false, true);
  121. }
  122. // 行動支付, 手機告知已付款
  123. // http://203.75.167.89/carpayment.html/m2payed/ABC1234/120/12112/12345/1f3870be274f6c49b3e31a0c6728957f
  124. // http://203.75.167.89/carpayment.html/m2payed/車牌/金額/場站編號/序號/MD5
  125. // md5(車牌.金額.場站編號.序號)
  126. public function m2payed()
  127. {
  128. $parms['lpr'] = $lines = $this->uri->segment(3);
  129. $parms['amt'] = $lines = $this->uri->segment(4);
  130. $parms['station_no'] = $lines = $this->uri->segment(5);
  131. $parms['seqno'] = $lines = $this->uri->segment(6);
  132. $md5 = $this->uri->segment(7);
  133. trigger_error(__FUNCTION__ . '..' . print_r($parms, true));
  134. echo $this->carpayment_model->m2payed($parms);
  135. }
  136. // 查詢入場時間
  137. public function query_in()
  138. {
  139. $lpr = $this->input->post('lpr', true);
  140. $data = $this->carpayment_model->query_in($lpr);
  141. echo json_encode($data);
  142. }
  143. // 查詢入場時間 (fuzzy)
  144. public function query_in_fuzzy()
  145. {
  146. $lpr = $this->input->post('lpr', true);
  147. $data = $this->carpayment_model->query_in_fuzzy($lpr);
  148. echo json_encode($data);
  149. }
  150. // 行動設備查詢入場時間
  151. // http://203.75.167.89/carpayment.html/m2query_in/ABC1234/12112/1f3870be274f6c49b3e31a0c6728957f
  152. // http://203.75.167.89/carpayment.html/m2query_in/車牌/場站編號/MD5
  153. // 回傳0: 失敗, 成功: 12345,60(第一欄位非0數字代表成功, 第二欄位為金額), 此值在付款時必需傳回, 否則視為非法
  154. public function m2query_in()
  155. {
  156. $parms['lpr'] = $lines = $this->uri->segment(3);
  157. $parms['station_no'] = $lines = $this->uri->segment(4);
  158. $md5 = $this->uri->segment(5);
  159. // 驗證md5
  160. if (md5($parms['lpr'].$parms['station_no']) === $md5)
  161. {
  162. $data = $this->carpayment_model->m2query_in($parms);
  163. }
  164. else
  165. {
  166. $data = 0;
  167. }
  168. $_SESSEION['seqno'] = $data;
  169. echo $data;
  170. }
  171. // 測試:回傳 seat_no
  172. // http://192.168.0.199/carpayment.html/test_seat_no/B2/123
  173. public function test_seat_no()
  174. {
  175. $rows['group_id'] = $this->uri->segment(3);
  176. $rows['pksno'] = $this->uri->segment(4);
  177. //echo substr($rows['group_id'], 0, 1);
  178. echo (substr($rows['group_id'], 0, 1) == 'B' ? '-' : '0') . substr($rows['group_id'], 1, 1) . '_' . substr($rows['pksno'], -3);
  179. }
  180. }