VM暫存
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

Carpayment.php 9.8KB

8 lat temu
6 lat temu
8 lat temu
6 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
8 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. */
  46. // mqtt subscribe
  47. $this->vars['mqtt'] = new phpMQTT(MQ_HOST, MQ_PORT, uniqid());
  48. if(!$this->vars['mqtt']->connect()){ die ('Could not connect mqtt'); }
  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/parktron001/ (post method)
  80. // 博辰進場通知
  81. public function parktron001()
  82. {
  83. $parms['devno'] = $this->input->post('devno', true);
  84. $parms['token'] = $this->input->post('token', true);
  85. $parms['lpr'] = trim($this->input->post('lpr', true));
  86. $parms['in_time'] = $this->input->post('in_time', true);
  87. $parms['type'] = $this->input->post('type', true);
  88. trigger_error('博辰進場參數:' . print_r($parms, true));
  89. $this->carpayment_model->parktron001($parms);
  90. }
  91. // http://localhost/carpayment.html/p2payed/ (post method)
  92. // 可用$this->input->is_cli_request()判斷是否在cli之下執行
  93. // 博辰aps已付款
  94. public function p2payed()
  95. {
  96. $parms['ticket_no'] = $this->input->post('ticket_no', true);
  97. $parms['lpr'] = trim($this->input->post('lpr', true));
  98. $parms['in_time'] = $this->input->post('in_time', true);
  99. $parms['pay_time'] = $this->input->post('pay_time', true);
  100. $parms['pay_type'] = $this->input->post('pay_type', true);
  101. trigger_error('博辰付款參數:' . print_r($parms, true));
  102. $this->carpayment_model->p2payed($parms);
  103. }
  104. // MITAC 付款
  105. public function mitac2payed()
  106. {
  107. $cario_no = $this->input->post('cario_no', true); // 通訊序號
  108. $lpr = $this->input->post('lpr', true); // 車牌
  109. $amt = $this->input->post('amt', true); // 金額
  110. $amt_discount = $this->input->post('amt_discount', true); // 折扣
  111. $amt_real = $this->input->post('amt_real', true); // 實收
  112. $in_time = $this->input->post('in_time', true); // 入場時間
  113. $pay_time = $this->input->post('pay_time', true); // 付款時間
  114. $ck = $this->input->post('ck', true); // 驗証碼
  115. // 通訊內容
  116. $parms = array(
  117. 'cario_no' => $cario_no,
  118. 'lpr' => $lpr,
  119. 'amt' => $amt,
  120. 'amt_discount' => $amt_discount,
  121. 'amt_real' => $amt_real,
  122. 'in_time' => $in_time,
  123. 'pay_time' => $pay_time);
  124. if($ck != md5($parms['cario_no']. 'a' . date('dmh') . 'l' . $parms['lpr'] . 't'. $parms['amt']. 'o'. $parms['amt_discount'] . 'b'. $parms['amt_real'] . __FUNCTION__))
  125. {
  126. trigger_error(__FUNCTION__ . '..ck_error..' . print_r($parms, true));
  127. exit; // 中斷
  128. }
  129. $parms['pay_type'] = 93; // MITAC 專用
  130. trigger_error('MITAC 付款:' . print_r($parms, true));
  131. // 註記已離場
  132. $this->carpayment_model->p2payed($parms, false, true);
  133. }
  134. // 行動支付, 手機告知已付款
  135. // http://203.75.167.89/carpayment.html/m2payed/ABC1234/120/12112/12345/1f3870be274f6c49b3e31a0c6728957f
  136. // http://203.75.167.89/carpayment.html/m2payed/車牌/金額/場站編號/序號/MD5
  137. // md5(車牌.金額.場站編號.序號)
  138. public function m2payed()
  139. {
  140. $parms['lpr'] = $lines = $this->uri->segment(3);
  141. $parms['amt'] = $lines = $this->uri->segment(4);
  142. $parms['station_no'] = $lines = $this->uri->segment(5);
  143. $parms['seqno'] = $lines = $this->uri->segment(6);
  144. $md5 = $this->uri->segment(7);
  145. trigger_error(__FUNCTION__ . '..' . print_r($parms, true));
  146. echo $this->carpayment_model->m2payed($parms);
  147. }
  148. // 查詢入場時間
  149. public function query_in()
  150. {
  151. $lpr = $this->input->post('lpr', true);
  152. $data = $this->carpayment_model->query_in($lpr);
  153. echo json_encode($data);
  154. }
  155. // 查詢入場時間 (fuzzy)
  156. public function query_in_fuzzy()
  157. {
  158. $lpr = $this->input->post('lpr', true);
  159. $data = $this->carpayment_model->query_in_fuzzy($lpr);
  160. echo json_encode($data);
  161. }
  162. // 行動設備查詢入場時間
  163. // http://203.75.167.89/carpayment.html/m2query_in/ABC1234/12112/1f3870be274f6c49b3e31a0c6728957f
  164. // http://203.75.167.89/carpayment.html/m2query_in/車牌/場站編號/MD5
  165. // 回傳0: 失敗, 成功: 12345,60(第一欄位非0數字代表成功, 第二欄位為金額), 此值在付款時必需傳回, 否則視為非法
  166. public function m2query_in()
  167. {
  168. $parms['lpr'] = $lines = $this->uri->segment(3);
  169. $parms['station_no'] = $lines = $this->uri->segment(4);
  170. $md5 = $this->uri->segment(5);
  171. // 驗證md5
  172. if (md5($parms['lpr'].$parms['station_no']) === $md5)
  173. {
  174. $data = $this->carpayment_model->m2query_in($parms);
  175. }
  176. else
  177. {
  178. $data = 0;
  179. }
  180. $_SESSEION['seqno'] = $data;
  181. echo $data;
  182. }
  183. // 測試:回傳 seat_no
  184. // http://192.168.0.199/carpayment.html/test_seat_no/B2/123
  185. public function test_seat_no()
  186. {
  187. $rows['group_id'] = $this->uri->segment(3);
  188. $rows['pksno'] = $this->uri->segment(4);
  189. //echo substr($rows['group_id'], 0, 1);
  190. echo (substr($rows['group_id'], 0, 1) == 'B' ? '-' : '0') . substr($rows['group_id'], 1, 1) . '_' . substr($rows['pksno'], -3);
  191. }
  192. }