VM暫存
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

8 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. /*
  3. file: qcar.php 查車系統
  4. */
  5. if (!defined('BASEPATH')) exit('No direct script access allowed');
  6. class Qcar extends CI_Controller
  7. {
  8. var $vars = array(); // 共用變數
  9. function __construct()
  10. {
  11. parent::__construct();
  12. // ----- 程式開發階段log設定 -----
  13. if (@ENVIRONMENT == 'development')
  14. {
  15. ini_set('display_errors', '1');
  16. //error_reporting(E_ALL ^ E_NOTICE);
  17. error_reporting(E_ALL);
  18. }
  19. set_error_handler(array($this, 'error_handler'), E_ALL); // 資料庫異動需做log
  20. /*
  21. // 共用記憶體
  22. $this->vars['mcache'] = new Memcache;
  23. $this->vars['mcache']->connect(MEMCACHE_HOST, MEMCACHE_POST) or die ('Could not connect memcache');
  24. // mqtt subscribe
  25. $this->vars['mqtt'] = new phpMQTT(MQ_HOST, MQ_POST, 'cario');
  26. if(!$this->vars['mqtt']->connect()){ die ('Could not connect mqtt'); }
  27. */
  28. // ----- 定義常數(路徑, cache秒數) -----
  29. define('APP_VERSION', '100'); // 版本號
  30. define('MAX_AGE', 604800); // cache秒數, 此定義1個月
  31. define('APP_NAME', 'qcar'); // 應用系統名稱
  32. define('PAGE_PATH', APP_BASE.'ci_application/views/'.APP_NAME.'/'); // path of views
  33. define('SERVER_URL', 'http://'.(isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost').'/'); // URL
  34. define('APP_URL', SERVER_URL.APP_NAME.'.html/'); // controller路徑
  35. define('WEB_URL', SERVER_URL.APP_NAME.'/'); // 網頁路徑
  36. define('WEB_LIB', SERVER_URL.'libs/'); // 網頁lib
  37. define('BOOTSTRAPS', WEB_LIB.'bootstrap_sb/'); // bootstrap lib
  38. define('LOG_PATH', FILE_BASE.APP_NAME.'/logs/'); // log path
  39. $this->load->model('qcar_model');
  40. $this->load->model('payment_ats_model'); // 繳費
  41. $this->load->model('allpay_invoice_model'); // 歐付寶電子發票
  42. define('MAIN_PAGE', "main_page");
  43. define('RESULT_PAGE', "result_page");
  44. // ----- 行動支付, 繳費機告知已付款 -----
  45. define('ALTOB_ATS2PAYED', "http://localhost/carpayment.html/ats2payed");
  46. // ----- 行動支付, 繳費機告知已付款 (end) -----
  47. // ----- 歐付寶金流 -----
  48. define('ALLPAY_PAYMENT_TX_BILL_ATS', SERVER_URL."allpay_payment.html/transfer_money_tx_bill_ats"); // 歐付寶付款系統連結
  49. define('ALLPAY_ClientBackURL', APP_URL."client_back/"); // 您要歐付寶返回按鈕導向的瀏覽器端網址";
  50. define('ALLPAY_OrderResultURL', APP_URL."order_result/"); // 您要收到付款完成通知的瀏覽器端網址(browser) ps. WebATM大部份銀行都回不來;
  51. define('ALLPAY_AltobServiceURL', APP_URL."payment_completed_handler/"); // 付款完成後被通知的位址
  52. // ----- 歐付寶金流 (end) -----
  53. }
  54. // 發生錯誤時集中在此處理
  55. public function error_handler($errno, $errstr, $errfile, $errline, $errcontext)
  56. {
  57. // ex: car_err://message....
  58. //$log_msg = explode('://', $errstr);
  59. /*
  60. if (count($log_msg) > 1)
  61. {
  62. $log_file = LOG_PATH.$log_msg[0];
  63. $str = date('H:i:s')."|{$log_msg[1]}|{$errfile}|{$errline}|{$errno}\n";
  64. }
  65. else
  66. {
  67. $log_file = LOG_PATH.APP_NAME;
  68. $str = date('H:i:s')."|{$errstr}|{$errfile}|{$errline}|{$errno}\n";
  69. }
  70. */
  71. $str = date('H:i:s')."|{$errstr}|{$errfile}|{$errline}|{$errno}\n";
  72. //error_log($str, 3, $log_file . '.' . date('Ymd').'.log.txt'); // 3代表參考後面的檔名
  73. error_log($str, 3, LOG_PATH.APP_NAME . '.' . date('Ymd').'.log.txt'); // 3代表參考後面的檔名
  74. }
  75. // 顯示靜態網頁(html檔)
  76. protected function show_page($page_name, $data = null)
  77. {
  78. $page_file = PAGE_PATH.$page_name.'.php';
  79. $last_modified_time = filemtime($page_file);
  80. // 若檔案修改時間沒有異動, 或版本無異動, 通知瀏覽器使用cache, 不再下傳網頁
  81. header('Cache-Control:max-age='.MAX_AGE); // cache 1個月
  82. header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_modified_time).' GMT');
  83. header('Etag: '. APP_VERSION);
  84. header('Cache-Control: public');
  85. if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == APP_VERSION && @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time)
  86. {
  87. header('HTTP/1.1 304 Not Modified');
  88. }
  89. else
  90. {
  91. $this->load->view(APP_NAME.'/'.$page_name, $data);
  92. }
  93. }
  94. public function index()
  95. {
  96. $this->show_page('main_page');
  97. }
  98. // 顯示logs
  99. public function show_logs()
  100. {
  101. $lines = $this->uri->segment(3); // 顯示行數
  102. if (empty($lines)) $lines = 40; // 無行數參數, 預設為40行
  103. // echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><pre style="white-space: pre-wrap;">';
  104. echo '<html lang="zh-TW"><body><pre style="white-space: pre-wrap;">';
  105. passthru('/usr/bin/tail -n ' . $lines . ' ' . LOG_FILE); // 利用linux指令顯示倒數幾行的logs內容
  106. echo "\n----- " . LOG_FILE . ' -----';
  107. echo '</pre></body></html>';
  108. }
  109. // 付款 - 1.繳月租
  110. public function payment_lpr()
  111. {
  112. $payment_lpr = $this->input->post('payment_lpr', true);
  113. $data = $this->payment_ats_model->create_member_bill($payment_lpr);
  114. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  115. }
  116. // 付款 - 2.確定繳費
  117. public function transfer_money()
  118. {
  119. $order_no = strtoupper($this->uri->segment(3)); // 交易序號
  120. $invoice_receiver = urldecode($this->uri->segment(4)); // 載具編號 (可有可無)
  121. $company_no = urldecode($this->uri->segment(5)); // 公司統編 (可有可無)
  122. $email_base64 = $this->uri->segment(6); // 電子信箱
  123. $mobile = $this->uri->segment(7); // 手機號碼
  124. // decode email
  125. if(strlen($email_base64) > 0){
  126. $email = base64_decode($email_base64.'='); // base64字串尾端的'='還原
  127. }else{
  128. $email = email_base64;
  129. }
  130. $this->payment_ats_model-> // 開始進行繳交帳單
  131. pay_bill($order_no, $invoice_receiver, $company_no, $email, $mobile,
  132. ALLPAY_ClientBackURL,
  133. ALLPAY_OrderResultURL,
  134. ALLPAY_AltobServiceURL,
  135. 52); // 交易種類: 0:未定義, 1:現金, 40:博辰人工模組, 41:博辰自動繳費機, 50:歐付寶轉址刷卡, 51:歐付寶APP, 52:歐付寶轉址WebATM, 60:中國信託刷卡轉址
  136. // 轉址歐付寶付款系統
  137. echo file_get_contents(ALLPAY_PAYMENT_TX_BILL_ATS."/{$order_no}");
  138. }
  139. // L.1 付款完成 (限制存取)
  140. public function payment_completed_handler()
  141. {
  142. $order_no = $this->uri->segment(3); // 交易序號
  143. $data = $this->payment_ats_model->get_tx_bill($order_no);
  144. if (! empty($data))
  145. {
  146. $order_no = $data['order_no'];
  147. $station_no = $data['station_no'];
  148. $lpr = $data['lpr'];
  149. $amt = $data['amt'];
  150. $status = $data['status'];
  151. switch($status){
  152. case 1: // 狀態: 0:剛建立, 1:結帳完成, 2:錢沒對上, 3:發票沒建立, 4:手動調整, 99:訂單逾期作廢, 100:交易進行中, 111:產品已領取
  153. // 開立歐付寶電子發票
  154. $this->allpay_invoice_model->invoice_issue_for_tx_bill_ats($order_no, $amt);
  155. // 記錄為已領取
  156. $this->payment_ats_model->transfer_money_done_and_finished($order_no);
  157. // 繳費機告知已付款
  158. // http://localhost/carpayment.html/ats2payed/車牌/金額/場站編號/序號/MD5
  159. // md5(車牌.金額.場站編號.序號)
  160. $md5 = md5($lpr.$amt.$station_no.$order_no);
  161. file_get_contents(ALTOB_ATS2PAYED."/{$lpr}/{$amt}/{$station_no}/{$order_no}/{$md5}");
  162. default:
  163. // 尚未結帳完成, 或是已領取
  164. trigger_error(APP_NAME.', '.__FUNCTION__.', order_no=>' . $order_no.'<br>'.' status != 1');
  165. }
  166. }
  167. }
  168. // 歐付寶返回按鈕導向的瀏覽器端網址
  169. public function client_back()
  170. {
  171. $this->show_page(MAIN_PAGE);
  172. }
  173. // 收到付款完成通知的瀏覽器端網址(browser) ps. WebATM大部份銀行都回不來
  174. public function order_result()
  175. {
  176. $this->show_page(RESULT_PAGE);
  177. }
  178. // 車位查詢
  179. public function q_pks()
  180. {
  181. $lpr = $this->input->post('lpr', true);
  182. $data = $this->qcar_model->q_pks($lpr);
  183. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  184. }
  185. // 取得進場資訊 (模糊比對)
  186. public function q_fuzzy_pks()
  187. {
  188. $input = $this->input->post('fuzzy_input', true);
  189. $data = $this->qcar_model->q_fuzzy_pks($input);
  190. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  191. }
  192. }