VM暫存
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

255 rindas
9.8KB

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