VM暫存
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

239 行
10.0KB

  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. /*
  93. 月租繳款完成
  94. http://203.75.167.89/carpayment.html/memberpayed/12345/ABC1234/120/12112/1/2016-01-31/1f3870be274f6c49b3e31a0c6728957f
  95. http://203.75.167.89/carpayment.html/memberpayed/會員號碼/車牌/金額/場站編號/月繳/本期到期日/md5
  96. md5(會員號碼.車牌.金額.場站編號.月繳.本期到期日)
  97. public function memberpayed()
  98. {
  99. $parms['member_no'] = $lines = $this->uri->segment(3);
  100. $parms['lpr'] = $lines = $this->uri->segment(4);
  101. $parms['amt'] = $lines = $this->uri->segment(5);
  102. $parms['station_no'] = $lines = $this->uri->segment(6);
  103. $parms['period_type'] = $lines = $this->uri->segment(7);
  104. $parms['expire_date'] = $lines = $this->uri->segment(8);
  105. $md5 = $this->uri->segment(9);
  106. if (md5($parms['member_no'].$parms['lpr'].$parms['amt'].$parms['station_no'].$parms['seqno'].$parms['period_type'].$parms['expire_date']) === $md5)
  107. {
  108. $this->carpayment_model->memberpayed($parms);
  109. }
  110. }
  111. */
  112. // 繳費機告知已付款 (new 2016/07/15)
  113. // http://localhost/carpayment.html/ats2payed/車牌/金額/場站編號/序號/MD5
  114. // md5(車牌.金額.場站編號.序號)
  115. public function ats2payed()
  116. {
  117. $result = [];
  118. $parms['lpr'] = $lines = $this->uri->segment(3);
  119. $parms['amt'] = $lines = $this->uri->segment(4);
  120. $parms['station_no'] = $lines = $this->uri->segment(5);
  121. $parms['order_no'] = $lines = $this->uri->segment(6);
  122. $md5 = $this->uri->segment(7);
  123. if (md5($parms['lpr'].$parms['amt'].$parms['station_no'].$parms['order_no']) === $md5)
  124. {
  125. $this->carpayment_model->ats2payed($parms);
  126. }
  127. }
  128. // 行動支付, 手機告知已付款
  129. // http://203.75.167.89/carpayment.html/m2payed/ABC1234/120/12112/12345/1f3870be274f6c49b3e31a0c6728957f
  130. // http://203.75.167.89/carpayment.html/m2payed/車牌/金額/場站編號/序號/MD5
  131. // md5(車牌.金額.場站編號.序號)
  132. public function m2payed()
  133. {
  134. $parms['lpr'] = $lines = $this->uri->segment(3);
  135. $parms['amt'] = $lines = $this->uri->segment(4);
  136. $parms['station_no'] = $lines = $this->uri->segment(5);
  137. $parms['seqno'] = $lines = $this->uri->segment(6);
  138. $md5 = $this->uri->segment(7);
  139. echo $this->carpayment_model->m2payed($parms);
  140. /*
  141. $seqno = !empty($_SESSION['seqno']) ? $_SESSION['seqno'] : 0;
  142. unset($_SESSION['seqno']);
  143. if ($parms['seqno'] != 0 && $parms['seqno'] == $seqno && md5($parms['lpr'].$parms['amt'].$parms['station_no'].$parms['seqno']) === $md5)
  144. {
  145. echo $this->carpayment_model->m2payed($parms);
  146. }
  147. else
  148. echo 'fail';
  149. */
  150. }
  151. // 查詢入場時間
  152. public function query_in()
  153. {
  154. $lpr = $this->input->post('lpr', true);
  155. $data = $this->carpayment_model->query_in($lpr);
  156. echo json_encode($data);
  157. }
  158. // 查詢入場時間 (fuzzy)
  159. public function query_in_fuzzy()
  160. {
  161. $lpr = $this->input->post('lpr', true);
  162. $data = $this->carpayment_model->query_in_fuzzy($lpr);
  163. echo json_encode($data);
  164. }
  165. // 行動設備查詢入場時間
  166. // http://203.75.167.89/carpayment.html/m2query_in/ABC1234/12112/1f3870be274f6c49b3e31a0c6728957f
  167. // http://203.75.167.89/carpayment.html/m2query_in/車牌/場站編號/MD5
  168. // 回傳0: 失敗, 成功: 12345,60(第一欄位非0數字代表成功, 第二欄位為金額), 此值在付款時必需傳回, 否則視為非法
  169. public function m2query_in()
  170. {
  171. $parms['lpr'] = $lines = $this->uri->segment(3);
  172. $parms['station_no'] = $lines = $this->uri->segment(4);
  173. $md5 = $this->uri->segment(5);
  174. // 驗證md5
  175. if (md5($parms['lpr'].$parms['station_no']) === $md5)
  176. {
  177. $data = $this->carpayment_model->m2query_in($parms);
  178. }
  179. else
  180. {
  181. $data = 0;
  182. }
  183. $_SESSEION['seqno'] = $data;
  184. echo $data;
  185. }
  186. // 測試:回傳 seat_no
  187. // http://192.168.0.199/carpayment.html/test_seat_no/B2/123
  188. public function test_seat_no()
  189. {
  190. $rows['group_id'] = $this->uri->segment(3);
  191. $rows['pksno'] = $this->uri->segment(4);
  192. //echo substr($rows['group_id'], 0, 1);
  193. echo (substr($rows['group_id'], 0, 1) == 'B' ? '-' : '0') . substr($rows['group_id'], 1, 1) . '_' . substr($rows['pksno'], -3);
  194. }
  195. }