VM暫存
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

205 рядки
8.1KB

  1. <?php
  2. /*
  3. file: Payment.php 付費系統
  4. */
  5. if (!defined('BASEPATH')) exit('No direct script access allowed');
  6. class Payment 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. // ----- 定義常數(路徑, cache秒數) -----
  21. define('APP_VERSION', '100'); // 版本號
  22. define('MAX_AGE', 604800); // cache秒數, 此定義1個月
  23. define('APP_NAME', 'payment'); // 應用系統名稱
  24. define('PAGE_PATH', APP_BASE.'ci_application/views/'.APP_NAME.'/'); // path of views
  25. define('SERVER_URL', 'http://'.(isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost').'/'); // URL
  26. define('APP_URL', SERVER_URL.APP_NAME.'.html/'); // controller路徑
  27. define('WEB_URL', SERVER_URL.APP_NAME.'/'); // 網頁路徑
  28. define('WEB_LIB', SERVER_URL.'libs/'); // 網頁lib
  29. define('BOOTSTRAPS', WEB_LIB.'bootstrap_sb/'); // bootstrap lib
  30. define('LOG_PATH', FILE_BASE.APP_NAME.'/logs/'); // log path
  31. $this->load->model('payment_model'); // 臨停繳費
  32. $this->load->model('allpay_invoice_model'); // 歐付寶電子發票
  33. $this->load->model('security_model'); // 鎖車
  34. define('MAIN_PAGE', "main_page");
  35. define('RESULT_PAGE', "result_page");
  36. // ----- 行動支付, 手機告知已付款 -----
  37. define('ALTOB_M2PAYED', "http://localhost/carpayment.html/m2payed");
  38. // ----- 行動支付, 手機告知已付款 (end) -----
  39. // ----- 歐付寶金流 -----
  40. define('ALLPAY_PAYMENT_TX_BILL', SERVER_URL."allpay_payment.html/transfer_money_tx_bill"); // 歐付寶付款系統連結
  41. define('ALLPAY_ClientBackURL', APP_URL."client_back/"); // 您要歐付寶返回按鈕導向的瀏覽器端網址";
  42. define('ALLPAY_OrderResultURL', APP_URL."order_result/"); // 您要收到付款完成通知的瀏覽器端網址(browser) ps. WebATM大部份銀行都回不來;
  43. define('ALLPAY_AltobServiceURL', APP_URL."payment_completed_handler/"); // 付款完成後被通知的位址
  44. // ----- 歐付寶金流 (end) -----
  45. }
  46. // 發生錯誤時集中在此處理
  47. public function error_handler($errno, $errstr, $errfile, $errline, $errcontext)
  48. {
  49. $str = date('H:i:s')."|{$errstr}|{$errfile}|{$errline}|{$errno}\n";
  50. //error_log($str, 3, $log_file . '.' . date('Ymd').'.log.txt'); // 3代表參考後面的檔名
  51. error_log($str, 3, LOG_PATH.APP_NAME . '.' . date('Ymd').'.log.txt'); // 3代表參考後面的檔名
  52. }
  53. // 顯示靜態網頁(html檔)
  54. protected function show_page($page_name, $data = null)
  55. {
  56. $page_file = PAGE_PATH.$page_name.'.php';
  57. $last_modified_time = filemtime($page_file);
  58. // 若檔案修改時間沒有異動, 或版本無異動, 通知瀏覽器使用cache, 不再下傳網頁
  59. // header('Cache-Control:max-age='.MAX_AGE); // cache 1個月
  60. header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_modified_time).' GMT');
  61. header('Etag: '. APP_VERSION);
  62. header('Cache-Control: public');
  63. if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == APP_VERSION && @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time)
  64. {
  65. header('HTTP/1.1 304 Not Modified');
  66. }
  67. else
  68. {
  69. $this->load->view(APP_NAME.'/'.$page_name, $data);
  70. }
  71. }
  72. // 首頁
  73. public function index()
  74. {
  75. $this->show_page(MAIN_PAGE);
  76. }
  77. // 查車付款 - 1.查車拿帳單
  78. public function payment_lpr()
  79. {
  80. $payment_lpr = $this->input->post('payment_lpr', true);
  81. $data = $this->payment_model->create_cario_bill($payment_lpr);
  82. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  83. }
  84. // 查車付款 - 2.確定繳交帳單
  85. public function transfer_money()
  86. {
  87. $order_no = strtoupper($this->uri->segment(3)); // 交易序號
  88. $invoice_receiver = urldecode($this->uri->segment(4)); // 載具編號 (可有可無)
  89. $company_no = urldecode($this->uri->segment(5)); // 公司統編 (可有可無)
  90. $email_base64 = $this->uri->segment(6); // 電子信箱
  91. $mobile = $this->uri->segment(7); // 手機號碼
  92. // decode email
  93. if(strlen($email_base64) > 0){
  94. $email = base64_decode($email_base64.'='); // base64字串尾端的'='還原
  95. }else{
  96. $email = email_base64;
  97. }
  98. $this->payment_model-> // 開始進行繳交帳單
  99. pay_bill($order_no, $invoice_receiver, $company_no, $email, $mobile,
  100. ALLPAY_ClientBackURL,
  101. ALLPAY_OrderResultURL,
  102. ALLPAY_AltobServiceURL,
  103. 50); // 交易種類: 0:未定義, 1:現金, 40:博辰人工模組, 41:博辰自動繳費機, 50:歐付寶轉址刷卡, 51:歐付寶APP, 52:歐付寶轉址WebATM, 60:中國信託刷卡轉址
  104. // 轉址歐付寶付款系統
  105. echo file_get_contents(ALLPAY_PAYMENT_TX_BILL."/{$order_no}");
  106. }
  107. // L.1 付款完成 (限制存取)
  108. public function payment_completed_handler()
  109. {
  110. $order_no = $this->uri->segment(3); // 交易序號
  111. $data = $this->payment_model->get_tx_bill($order_no);
  112. if (! empty($data))
  113. {
  114. $cario_no = $data['cario_no'];
  115. $station_no = $data['station_no'];
  116. $lpr = $data['lpr'];
  117. $amt = $data['amt'];
  118. $status = $data['status'];
  119. switch($status){
  120. case 1: // 狀態: 0:剛建立, 1:結帳完成, 2:錢沒對上, 3:發票沒建立, 4:手動調整, 99:訂單逾期作廢, 100:交易進行中, 111:產品已領取
  121. // 開立歐付寶電子發票
  122. $this->allpay_invoice_model->invoice_issue_for_tx_bill($order_no, $amt);
  123. // 記錄為已領取
  124. $this->payment_model->transfer_money_done_and_finished($order_no);
  125. // 行動支付, 手機告知已付款
  126. // http://203.75.167.89/carpayment.html/m2payed/車牌/金額/場站編號/序號/MD5
  127. // md5(車牌.金額.場站編號.序號)
  128. $md5 = md5($lpr.$amt.$station_no.$cario_no);
  129. file_get_contents(ALTOB_M2PAYED."/{$lpr}/{$amt}/{$station_no}/{$cario_no}/{$md5}");
  130. default:
  131. // 尚未結帳完成, 或是已領取
  132. trigger_error(APP_NAME.', '.__FUNCTION__.', order_no=>' . $order_no.'<br>'.'tx_bill.status != 1');
  133. }
  134. }
  135. }
  136. // 歐付寶返回按鈕導向的瀏覽器端網址
  137. public function client_back()
  138. {
  139. $this->show_page(MAIN_PAGE);
  140. }
  141. // 收到付款完成通知的瀏覽器端網址(browser) ps. WebATM大部份銀行都回不來
  142. public function order_result()
  143. {
  144. $this->show_page(RESULT_PAGE);
  145. }
  146. // 其它功能 1: 更改會員密碼
  147. public function change_pswd()
  148. {
  149. $lpr = $this->input->post('lpr', true);
  150. $new_pswd = $this->input->post('new_pswd', true);
  151. $data = $this->security_model->change_pswd($lpr, $new_pswd);
  152. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  153. }
  154. // 其它功能 2: 防盜鎖車
  155. public function security_action()
  156. {
  157. $lpr = $this->uri->segment(3);
  158. $pswd = $this->uri->segment(4);
  159. $action = $this->uri->segment(5);
  160. $data = $this->security_model->security_action($lpr, $pswd, $action);
  161. echo json_encode($data, JSON_UNESCAPED_UNICODE);
  162. }
  163. // show image
  164. public function pics()
  165. {
  166. readfile(PKS_PIC. $this->uri->segment(3).'.jpg');
  167. }
  168. }