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.

91 lines
3.6KB

  1. <?php
  2. /*
  3. file: cars.php 宏奇 API 車輛進出場處理
  4. */
  5. class Alt_acarps extends CI_Controller
  6. {
  7. function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. public function index() //出場車辨 送 API 至宏奇
  12. {
  13. $post_data= $this->input->get(NULL, TRUE);
  14. $lpr="ALT6222";//$post_data["lpr"];LT6222
  15. //print_r($lpr);exit;
  16. $this->load->model('api/Master_db_model','master_db');
  17. $sel_cario=$this->master_db->sel_cario($lpr);
  18. //print_r($sel_cario);exit;
  19. if(count($sel_cario)>0){
  20. $cario_no=$sel_cario[0]['cario_no']; //入場流水號
  21. $station_no=$sel_cario[0]['station_no']; //場站代碼
  22. $member_no=$sel_cario[0]['member_no']; //會員代碼
  23. $obj_id=$sel_cario[0]['obj_id']; //會員代碼
  24. $in_out=$sel_cario[0]['in_out'];
  25. $in_time=$sel_cario[0]['in_time']; //入場時間
  26. $Get_billing_fee= "http://altapi.altob.com.tw/fee_api/Get_billing_fee"; //檢查現場入場時間
  27. $start_time=$in_time;
  28. $end_time=date('Y-m-d H:i:s');
  29. $ch0 = curl_init();
  30. curl_setopt($ch0, CURLOPT_HEADER, 0);
  31. curl_setopt($ch0, CURLOPT_RETURNTRANSFER, 1);
  32. curl_setopt($ch0, CURLOPT_URL, $Get_billing_fee);
  33. curl_setopt($ch0, CURLOPT_POST, true);
  34. curl_setopt($ch0, CURLOPT_POSTFIELDS, http_build_query(array("station_no"=>$station_no, "start_time"=>$start_time, "end_time"=>$end_time)));
  35. $totalfee0 = curl_exec($ch0);
  36. curl_close($ch0);
  37. $totalfee=isset($totalfee0) ? $totalfee0:0 ;
  38. $acarps_ip="192.168.10.82";
  39. $acarps_port=8081;
  40. $apijson= "http://".$acarps_ip.":".$acarps_port."/lprpayout"; //送宏奇API
  41. $i=1;
  42. $jsonarray=array("lpr"=>$obj_id, "start_time"=>$start_time, "end_time"=>$end_time, "totalfee"=>$totalfee);
  43. $json=json_encode($jsonarray,true);
  44. //print_r($json);
  45. while(true){
  46. $ch = curl_init();
  47. curl_setopt($ch, CURLOPT_HEADER, 0);
  48. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  49. curl_setopt($ch, CURLOPT_URL, $apijson);
  50. curl_setopt($ch, CURLOPT_POST, true);
  51. curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
  52. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8','Content-Length: ' . strlen($json)));
  53. $output = curl_exec($ch);
  54. //print_r($output);exit;
  55. if($i==10 or $output=="OK"){
  56. if($output=="OK"){
  57. $data=date('Y-m-d H:i:s')." Alt_acarps OK ".$obj_id."\n";
  58. $this->save_setting($data);
  59. }
  60. break;
  61. }
  62. $i++;
  63. }
  64. }
  65. }
  66. public function save_setting($data){
  67. $myfile = fopen("/home/data/alt_acarps_log.json", "a+") or die("Unable to open file!");
  68. fwrite($myfile, $data);
  69. fclose($myfile);
  70. }
  71. }