VM暫存
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

Cars_model.php 55KB

8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
7 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
7 yıl önce
8 yıl önce
7 yıl önce
8 yıl önce
7 yıl önce
8 yıl önce
7 yıl önce
8 yıl önce
7 yıl önce
8 yıl önce
7 yıl önce
8 yıl önce
7 yıl önce
8 yıl önce
7 yıl önce
8 yıl önce
7 yıl önce
8 yıl önce
7 yıl önce
8 yıl önce
7 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
7 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655
  1. <?php
  2. /*
  3. file: cars_model.php
  4. */
  5. require_once(ALTOB_SYNC_FILE) ;
  6. define('CARS_TMP_LOG', 'cars_tmp_log'); // 暫存進出車號
  7. class Cars_model extends CI_Model
  8. {
  9. var $vars = array();
  10. var $io_name = array('I' => '車入', 'O' => '車出', 'MI' => '機入', 'MO' => '機出', 'FI' => '樓入', 'FO' => '樓出');
  11. var $now_str;
  12. function __construct()
  13. {
  14. parent::__construct();
  15. $this->load->database();
  16. $this->now_str = date('Y-m-d H:i:s');
  17. }
  18. public function init($vars)
  19. {
  20. $this->vars = $vars;
  21. }
  22. // 產生回傳訊息
  23. function gen_return_msg($msg_id, $open_or_not=false)
  24. {
  25. $open_id = $open_or_not ? 1 : 0;
  26. return $open_id . ',' . str_pad($msg_id, 5, '0', STR_PAD_LEFT);
  27. }
  28. // 修改車辨記錄
  29. public function upd_cario($parms)
  30. {
  31. trigger_error(__FUNCTION__ . '|修改車辨記錄:' . print_r($parms, true));
  32. // 更新入場記錄
  33. $data = array('obj_id' => $parms['lpr']);
  34. $this->db->update('cario', $data, array('station_no' => $parms['sno'], 'cario_no' => $parms['cno'], 'obj_id' => $parms['old_lpr'], 'err' => 0, 'finished' => 0));
  35. if ($this->db->affected_rows() <= 0)
  36. {
  37. trigger_error(__FUNCTION__ . '|fail|' . $this->db->last_query());
  38. return 'fail';
  39. }
  40. /* 20171226 車辨失敗暫不同步
  41. // 傳送更新記錄
  42. $sync_agent = new AltobSyncAgent();
  43. $sync_agent->init($parms['sno'], $this->now_str);
  44. $sync_agent->cario_no = $parms['cno']; // 進出編號
  45. $sync_result = $sync_agent->sync_st_io_meta($data);
  46. trigger_error( __FUNCTION__ . "..sync_st_io_meta|{$sync_agent->cario_no}|$sync_result|..". print_r($data, true));
  47. */
  48. return 'ok';
  49. }
  50. // 特殊方式進出註記
  51. public function ipcam_meta($parms)
  52. {
  53. trigger_error(__FUNCTION__ . '|特殊註記:' . print_r($parms, true));
  54. if($parms['token'] != 1)
  55. {
  56. trigger_error(__FUNCTION__ . '|未定義|' . print_r($parms, true));
  57. return false;
  58. }
  59. // 讀取最近一筆入場資料
  60. $rows_cario = $this->db->select('cario_no, obj_id, in_time, out_before_time')
  61. ->from('cario')
  62. ->where(array(
  63. 'station_no' => $parms['sno'],
  64. 'obj_id' => $parms['lpr'],
  65. 'err' => 0
  66. ))
  67. ->order_by('cario_no', 'desc')
  68. ->limit(1)
  69. ->get()
  70. ->row_array();
  71. if (!isset($rows_cario['cario_no']))
  72. {
  73. trigger_error(__FUNCTION__ . '|查無入場記錄|' . print_r($parms, true));
  74. return false;
  75. }
  76. // 更新入場記錄
  77. if(strtotime($rows_cario['out_before_time']) - strtotime($rows_cario['in_time']) > 600)
  78. $data = array('ticket_type' => 3, 'out_before_time' => $rows_cario['in_time']); // 刷進刷出需過卡
  79. else
  80. $data = array('ticket_type' => 3);
  81. $this->db->update('cario', $data, array('cario_no' => $rows_cario['cario_no']));
  82. trigger_error(__FUNCTION__ . '|悠遊卡,更新入場記錄|');
  83. $affect_rows = $this->db->affected_rows();
  84. if ($affect_rows > 0)
  85. {
  86. // 傳送更新記錄
  87. $sync_agent = new AltobSyncAgent();
  88. $sync_agent->init($parms['sno'], $this->now_str);
  89. $sync_agent->cario_no = $rows_cario['cario_no']; // 進出編號
  90. $sync_result = $sync_agent->sync_st_io_meta($data);
  91. trigger_error( __FUNCTION__ . "..sync_st_io_meta|{$sync_agent->cario_no}|$sync_result|..". print_r($data, true));
  92. }
  93. }
  94. // 車輛進出傳入車牌號碼 (2016/07/27)
  95. public function opendoor_lprio($parms)
  96. {
  97. $parms['lpr'] = urldecode($parms['lpr']);
  98. $rows = array();
  99. // $parms['ts'] = date('Y-m-d H:i:s', $parms['ts']);
  100. trigger_error(__FUNCTION__ . '|車牌傳入:' . print_r($parms, true));
  101. if ($parms['etag'] != 'NONE')
  102. {
  103. if ($parms['lpr'] != 'NONE')
  104. {
  105. // do nothing
  106. }
  107. else // 車辨失敗但有eTag, 查詢是否有車號
  108. {
  109. //$parms['lpr'] = $this->etag2lpr_2($parms['etag']); // 2017/01/10 預設都不用 ETAG 找車牌
  110. }
  111. }
  112. $rows = $this->get_member($parms['lpr']);
  113. return $this->save_db_io($parms, $rows, true);
  114. }
  115. // 車輛進出傳入車牌號碼
  116. public function lprio($parms)
  117. {
  118. //$parms['lpr'] = urldecode($parms['lpr']);
  119. $rows = array();
  120. // $parms['ts'] = date('Y-m-d H:i:s', $parms['ts']);
  121. trigger_error('車牌傳入:' . print_r($parms, true));
  122. if ($parms['etag'] != 'NONE')
  123. {
  124. if ($parms['lpr'] != 'NONE')
  125. {
  126. // 有車牌有eTag, 檢查資料庫是否double驗證
  127. //get_headers("http://192.168.10.201/cars.html/check_lpr_etag/{$parms['lpr']}/{$parms['etag']}");
  128. get_headers("http://localhost/cars.html/check_lpr_etag/{$parms['lpr']}/{$parms['etag']}"); // update 2016/07/26
  129. }
  130. else // 車辨失敗但有eTag, 查詢是否有車號
  131. {
  132. // $parms['lpr'] = $this->etag2lpr_2($parms['etag']); // 2017/01/10 預設都不用 ETAG 找車牌
  133. }
  134. }
  135. $rows = $this->get_member($parms['lpr']);
  136. return $this->save_db_io($parms, $rows);
  137. }
  138. // 入出口異動cario
  139. public function save_db_io($parms, $rows, $opendoor=false)
  140. {
  141. $msg_id = 0; // 訊息代碼
  142. if (!empty($rows['lpr_correct'])) $parms['lpr'] = $rows['lpr_correct'];
  143. // [START] 擋重覆
  144. $skip_or_not = false;
  145. $new_cars_tmp = array
  146. (
  147. 'timestamp' => time(),
  148. 'sno_io' => $parms['sno'] . $parms['io'],
  149. 'lpr' => $parms['lpr'],
  150. 'opendoor' => $opendoor // 20180118 開門與否訊號都過濾
  151. );
  152. $cars_tmp_arr = array();
  153. $cars_tmp_log_arr = $this->vars['mcache']->get(CARS_TMP_LOG);
  154. if(!empty($cars_tmp_log_arr))
  155. {
  156. foreach($cars_tmp_log_arr as $tmp)
  157. {
  158. if(isset($tmp['timestamp']) && $tmp['timestamp'] > time() - 3) // 時限內才判斷 (3 sec)
  159. {
  160. array_push($cars_tmp_arr, $tmp);
  161. }
  162. }
  163. }
  164. // 判斷是否繼續
  165. foreach($cars_tmp_arr as $tmp)
  166. {
  167. if( $new_cars_tmp['lpr'] == $tmp['lpr'] &&
  168. $new_cars_tmp['sno_io'] == $tmp['sno_io'] &&
  169. $new_cars_tmp['opendoor'] == $tmp['opendoor'] // 20180118 開門與否訊號都過濾
  170. )
  171. {
  172. $skip_or_not = true;
  173. }
  174. }
  175. // 更新 CARS_TMP_LOG
  176. array_push($cars_tmp_arr, $new_cars_tmp);
  177. $this->vars['mcache']->set(CARS_TMP_LOG, $cars_tmp_arr);
  178. trigger_error(__FUNCTION__ . '..new ' . CARS_TMP_LOG . " |s:{$skip_or_not}|" . print_r($cars_tmp_arr, true));
  179. // 跳過
  180. if($skip_or_not)
  181. {
  182. trigger_error(__FUNCTION__ . '..skip..');
  183. // [msg] 0: 不處理
  184. $msg_id = 0;
  185. return $this->gen_return_msg($msg_id);
  186. }
  187. // [END] 擋重覆
  188. // 車辨失敗, 結束
  189. if ($parms['lpr'] == 'NONE')
  190. {
  191. if($opendoor)
  192. {
  193. // [msg] 1: 車辨失敗
  194. $msg_id = 1;
  195. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']}".MQ_ALTOB_MSG_END_TAG);
  196. return $this->gen_return_msg($msg_id);
  197. }
  198. else
  199. {
  200. if(substr($parms['io'], -strlen('I')) === 'I')
  201. {
  202. $data = array
  203. (
  204. 'station_no' => $parms['sno'],
  205. 'obj_type' => 1,
  206. 'obj_id' => $parms['lpr'],
  207. 'etag' => $parms['etag'] == 'NONE' ? '' : $parms['etag'],
  208. 'in_out' => $parms['io'],
  209. 'member_no' => 0,
  210. 'finished' => 0,
  211. 'in_time' => $this->now_str,
  212. 'in_lane' => $parms['ivsno'],
  213. 'in_pic_name' => empty($parms['pic_name']) ? '' : $parms['pic_name'],
  214. 'out_before_time' => date("Y-m-d H:i:s"),
  215. 'ticket_no' => $this->gen_pass_code()
  216. );
  217. $this->db->insert('cario', $data);
  218. trigger_error("[車辨失敗] 新增入場資料:".print_r($parms, true));
  219. }
  220. }
  221. return false;
  222. }
  223. $msg = $rows['member_no'] != 0 ? "{$parms['lpr']}." : $parms['lpr']; // 月租車號加.符號
  224. // 月租鎖車, 結束
  225. if ((substr($parms['io'], -strlen('O')) === 'O') && $rows['member_no'] != 0 && !empty($rows['locked']) && $rows['locked'] == 1)
  226. {
  227. if($opendoor)
  228. {
  229. // [msg] 2: 已鎖車
  230. $msg_id = 2;
  231. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']}".MQ_ALTOB_MSG_END_TAG);
  232. return $this->gen_return_msg($msg_id);
  233. }
  234. return false;
  235. }
  236. // 取得會員資訊
  237. $parms['member_no'] = $rows['member_no'];
  238. switch($parms['io'])
  239. {
  240. case 'CI':
  241. case 'MI':
  242. if($opendoor)
  243. {
  244. // 空車位導引
  245. $pks_arr = $this->get_valid_seat();
  246. if ($pks_arr['result']['location_no'] != 0)
  247. {
  248. $pks_loc_name = $pks_arr['loc_name'];
  249. $pks_loc_no = $pks_arr['result']['location_no'];
  250. $pks_floors = $pks_arr['floors'];
  251. }
  252. else
  253. {
  254. $pks_loc_name = 0;
  255. $pks_loc_no = 0;
  256. $pks_floors = 0;
  257. }
  258. // 訊息
  259. if ($rows['member_no'] == 0)
  260. {
  261. $ck = md5($parms['lpr']);
  262. $jdata = file_get_contents("http://localhost/allpa_service.html/get_allpa_valid_user/{$parms['lpr']}/{$ck}");
  263. $results = json_decode($jdata, true);
  264. if($results['result_code'] == 0)
  265. {
  266. // [msg] 3: 歐pa卡, 開門
  267. $msg_id = 3;
  268. // 會員開門
  269. $this->member_opendoors($parms);
  270. }
  271. else
  272. {
  273. // [msg] 11: 臨停車, 開門
  274. $msg_id = 11;
  275. // 臨停開門
  276. $this->temp_opendoors($parms);
  277. }
  278. }
  279. else
  280. {
  281. // [msg] 4: 會員, 開門
  282. $msg_id = 4;
  283. // 會員開門
  284. $this->member_opendoors($parms);
  285. }
  286. // 字幕
  287. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']},{$pks_floors},{$pks_loc_no}".MQ_ALTOB_MSG_END_TAG);
  288. // 產生回傳
  289. return $this->gen_return_msg($msg_id, true);
  290. }
  291. else
  292. // 資料流
  293. {
  294. if ($parms['lpr'] != 'NONE')
  295. {
  296. $data = array
  297. (
  298. 'err' => 1,
  299. 'finished' => 1
  300. );
  301. // 原有歷史記錄, 設定錯誤碼為1(入場不應該有歷史記錄)
  302. $this->db->update('cario', $data, array('obj_id' => $parms['lpr'], 'finished' => 0, 'err' => 0, 'obj_type' => 1));
  303. $affect_rows = $this->db->affected_rows();
  304. if ($affect_rows > 0)
  305. {
  306. trigger_error("err://入場郤已有歷史進場記錄[{$affect_rows}]筆,已設成錯誤並結清記錄".print_r($parms, true));
  307. }
  308. }
  309. $data = array
  310. (
  311. 'station_no' => $parms['sno'],
  312. 'obj_type' => 1,
  313. 'obj_id' => $parms['lpr'],
  314. 'etag' => $parms['etag'] == 'NONE' ? '' : $parms['etag'],
  315. 'in_out' => $parms['io'],
  316. 'member_no' => $rows['member_no'],
  317. 'finished' => 0,
  318. 'in_time' => $this->now_str,
  319. 'in_lane' => $parms['ivsno'],
  320. 'in_pic_name' => empty($parms['pic_name']) ? '' : $parms['pic_name'],
  321. //'out_before_time' => date("Y-m-d H:i:s"),
  322. 'out_before_time' => date('Y-m-d H:i:s', strtotime(" + 15 minutes")), // 15分鐘內, 可直接離場 (刷進刷出需過卡修正)
  323. 'ticket_no' => $this->gen_pass_code()
  324. );
  325. $this->db->insert('cario', $data);
  326. trigger_error("新增入場資料:".print_r($parms, true));
  327. // 傳送進場記錄
  328. $sync_agent = new AltobSyncAgent();
  329. $sync_agent->init($parms['sno'], $this->now_str);
  330. $sync_agent->cario_no = $this->db->insert_id(); // 進出編號
  331. $sync_agent->member_no = $rows['member_no']; // 會員編號
  332. $sync_result = $sync_agent->sync_st_in($parms);
  333. trigger_error( "..sync_st_in.." . $sync_result);
  334. }
  335. return true;
  336. break;
  337. // 出場
  338. case 'CO':
  339. case 'MO':
  340. // 讀取最近一筆入場資料
  341. $rows_cario = $this->db
  342. ->select('cario_no, payed, in_time, pay_time, out_before_time')
  343. ->from('cario')
  344. //->where(array('in_out' => 'CI', 'obj_id' => $parms['lpr'], 'finished' => 0, 'err' => 0))
  345. ->where(array('obj_id' => $parms['lpr'], 'finished' => 0, 'err' => 0))
  346. ->order_by('cario_no', 'desc')
  347. ->limit(1)
  348. ->get()
  349. ->row_array();
  350. trigger_error("opendoor={$opendoor}| 出場讀到資料:{$rows['member_no']}|".time().'|'.print_r($rows_cario, true));
  351. if (!empty($rows_cario['cario_no'])) // 在限時內可出場
  352. {
  353. $co_time_minutes = floor((strtotime($this->now_str) - strtotime($rows_cario['in_time'])) / 60); // 停車時數 (分鐘)
  354. // 合規定者開門放行
  355. switch(true)
  356. {
  357. case $rows['member_no'] != 0:
  358. // CO.A.1 會員車
  359. // 判斷時段租是否超時 (超過 12 小時)
  360. if($rows['park_time'] != 'RE' && $co_time_minutes > 720)
  361. {
  362. if($opendoor)
  363. {
  364. // [msg] 16: 時段租超時字幕
  365. $msg_id = 16;
  366. // 字幕
  367. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']}".MQ_ALTOB_MSG_END_TAG);
  368. // 產生回傳
  369. return $this->gen_return_msg($msg_id);
  370. }
  371. else
  372. {
  373. $data = array
  374. (
  375. 'out_time' => $this->now_str,
  376. 'out_lane' => $parms['ivsno'],
  377. 'minutes' => $co_time_minutes,
  378. 'out_pic_name' => $parms['pic_name']
  379. );
  380. $this->db->update('cario', $data, array('cario_no' => $rows_cario['cario_no'])); // 記錄出場
  381. trigger_error("{$parms['lpr']}|時段租超時" . print_r($rows_cario, true));
  382. // 傳送離場記錄
  383. $sync_agent = new AltobSyncAgent();
  384. $sync_agent->init($parms['sno'], $this->now_str);
  385. $sync_agent->cario_no = $rows_cario['cario_no']; // 進出編號
  386. $sync_agent->member_no = $rows['member_no']; // 會員編號
  387. $sync_agent->in_time = $rows_cario['in_time']; // 入場時間
  388. $sync_result = $sync_agent->sync_st_out($parms);
  389. trigger_error( "..sync_st_out.." . $sync_result);
  390. }
  391. return true;
  392. }
  393. if($opendoor)
  394. {
  395. // [msg] 5: 會員離場開門
  396. $msg_id = 5;
  397. // 會員開門
  398. $this->member_opendoors($parms);
  399. // 字幕
  400. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']}".MQ_ALTOB_MSG_END_TAG);
  401. // 產生回傳
  402. return $this->gen_return_msg($msg_id, true);
  403. }
  404. else
  405. {
  406. $data = array
  407. (
  408. 'in_out' => $parms['io'],
  409. 'finished' => 1,
  410. 'out_time' => $this->now_str,
  411. 'out_lane' => $parms['ivsno'],
  412. 'minutes' => $co_time_minutes,
  413. 'out_pic_name' => $parms['pic_name']
  414. );
  415. $this->db->update('cario', $data, array('cario_no' => $rows_cario['cario_no']));
  416. trigger_error('會員車離場:' . print_r($rows, true));
  417. // 傳送離場記錄
  418. $sync_agent = new AltobSyncAgent();
  419. $sync_agent->init($parms['sno'], $this->now_str);
  420. $sync_agent->cario_no = $rows_cario['cario_no']; // 進出編號
  421. $sync_agent->member_no = $rows['member_no']; // 會員編號
  422. $sync_agent->in_time = $rows_cario['in_time']; // 入場時間
  423. $sync_agent->finished = 1; // 已離場
  424. $sync_result = $sync_agent->sync_st_out($parms);
  425. trigger_error( "..sync_st_out.." . $sync_result);
  426. }
  427. return true;
  428. break;
  429. case strtotime($rows_cario['out_before_time']) >= time():
  430. if ($rows_cario['payed'])
  431. {
  432. // CO.B.1 臨停車已付款
  433. if($opendoor)
  434. {
  435. // [msg] 6: 臨停車已付款
  436. $msg_id = 6;
  437. // 臨停開門
  438. $this->temp_opendoors($parms);
  439. // 字幕
  440. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']}".MQ_ALTOB_MSG_END_TAG);
  441. // 產生回傳
  442. return $this->gen_return_msg($msg_id, true);
  443. }
  444. else
  445. {
  446. $data = array
  447. (
  448. 'in_out' => $parms['io'],
  449. 'finished' => 1,
  450. 'out_time' => $this->now_str,
  451. 'out_lane' => $parms['ivsno'],
  452. 'minutes' => $co_time_minutes,
  453. 'out_pic_name' => $parms['pic_name']
  454. );
  455. $this->db->update('cario', $data, array('cario_no' => $rows_cario['cario_no']));
  456. trigger_error('臨停車已付款:' . print_r($rows, true));
  457. // 傳送離場記錄
  458. $sync_agent = new AltobSyncAgent();
  459. $sync_agent->init($parms['sno'], $this->now_str);
  460. $sync_agent->cario_no = $rows_cario['cario_no']; // 進出編號
  461. $sync_agent->in_time = $rows_cario['in_time']; // 入場時間
  462. $sync_agent->finished = 1; // 已離場
  463. $sync_result = $sync_agent->sync_st_out($parms);
  464. trigger_error( "..sync_st_out.." . $sync_result);
  465. }
  466. return true;
  467. }
  468. else
  469. {
  470. // CO.B.2 臨停車未付款
  471. if($opendoor)
  472. {
  473. // [msg] 8: 臨停車未付款
  474. $msg_id = 8;
  475. // 字幕
  476. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']}".MQ_ALTOB_MSG_END_TAG);
  477. // 產生回傳
  478. return $this->gen_return_msg($msg_id);
  479. }
  480. else
  481. {
  482. // TODO: 歐pa卡離場記錄和臨停未付款一樣, 待更正
  483. $data = array
  484. (
  485. 'out_time' => $this->now_str,
  486. 'out_lane' => $parms['ivsno'],
  487. 'minutes' => $co_time_minutes,
  488. 'out_pic_name' => $parms['pic_name']
  489. );
  490. $this->db->update('cario', $data, array('cario_no' => $rows_cario['cario_no'])); // 記錄出場
  491. trigger_error('臨停未付款:' . print_r($rows, true));
  492. // 傳送離場記錄
  493. $sync_agent = new AltobSyncAgent();
  494. $sync_agent->init($parms['sno'], $this->now_str);
  495. $sync_agent->cario_no = $rows_cario['cario_no']; // 進出編號
  496. $sync_agent->in_time = $rows_cario['in_time']; // 入場時間
  497. $sync_result = $sync_agent->sync_st_out($parms);
  498. trigger_error( "..sync_st_out.." . $sync_result);
  499. // [mitac] 要求 mitac 扣款 START
  500. $this->call_mitac_pay($parms['lpr'], $parms['ivsno'], $rows_cario);
  501. // [mitac] 要求 mitac 扣款 END
  502. }
  503. return true;
  504. }
  505. break;
  506. default:
  507. // CO.C.1 其它付款方式
  508. if($opendoor)
  509. {
  510. $in_time = strtotime($rows_cario['out_before_time']);
  511. $ck = md5($in_time. $parms['lpr'] . $parms['sno']);
  512. //$jdata = file_get_contents("http://localhost/allpa_service.html/allpa_go/{$in_time}/{$parms['lpr']}/{$parms['sno']}/{$ck}");
  513. $jdata = file_get_contents("http://localhost/allpa_service.html/allpa_go_remote/{$in_time}/{$parms['lpr']}/{$parms['sno']}/{$ck}");
  514. trigger_error("allpa回傳:{$jdata}|{$in_time}/{$parms['lpr']}/{$parms['sno']}/{$ck}");
  515. $results = json_decode($jdata, true);
  516. if (isset($results['result_code'])) // 歐pa卡, 點數足夠扣
  517. {
  518. if($results['result_code'] == 0)
  519. {
  520. // [msg] 7: 歐pa卡付款
  521. $msg_id = 7;
  522. // 臨停開門
  523. $this->temp_opendoors($parms);
  524. // 歐pa卡, 字幕
  525. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']},{$results['amt']}".MQ_ALTOB_MSG_END_TAG);
  526. $data = array(
  527. 'out_before_time' => date('Y-m-d H:i:s', strtotime(" + 15 minutes")),
  528. 'pay_time' => $this->now_str,
  529. 'pay_type' => 9, // 歐pa卡
  530. 'payed' => 1
  531. );
  532. $this->db->update('cario', $data, array('cario_no' => $rows_cario['cario_no'])); // 記錄出場
  533. // 產生回傳
  534. return $this->gen_return_msg($msg_id, true);
  535. }
  536. else if ($results['result_code'] == 12) // 歐pa卡, 餘額不足
  537. {
  538. // [msg] 12: 歐pa卡, 餘額不足
  539. $msg_id = 12;
  540. }
  541. else if ($results['result_code'] == 11) // 歐pa卡, 查無會員
  542. {
  543. // [msg] 9: 其它付款方式
  544. $msg_id = 9;
  545. }
  546. else
  547. {
  548. // [msg] 9: 其它付款方式
  549. $msg_id = 9;
  550. }
  551. }
  552. else
  553. {
  554. // [msg] 9: 其它付款方式
  555. $msg_id = 9;
  556. }
  557. // 字幕
  558. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']}".MQ_ALTOB_MSG_END_TAG);
  559. // 產生回傳
  560. return $this->gen_return_msg($msg_id);
  561. }
  562. else
  563. {
  564. $data = array
  565. (
  566. 'out_time' => $this->now_str,
  567. 'out_lane' => $parms['ivsno'],
  568. 'minutes' => $co_time_minutes,
  569. 'out_pic_name' => $parms['pic_name']
  570. );
  571. $this->db->update('cario', $data, array('cario_no' => $rows_cario['cario_no'])); // 記錄出場
  572. trigger_error("{$parms['lpr']}|其它付款方式:" . print_r($rows_cario, true));
  573. // 傳送離場記錄
  574. $sync_agent = new AltobSyncAgent();
  575. $sync_agent->init($parms['sno'], $this->now_str);
  576. $sync_agent->cario_no = $rows_cario['cario_no']; // 進出編號
  577. $sync_agent->in_time = $rows_cario['in_time']; // 入場時間
  578. $sync_result = $sync_agent->sync_st_out($parms);
  579. trigger_error( "..sync_st_out.." . $sync_result);
  580. // [mitac] 要求 mitac 扣款 START
  581. $this->call_mitac_pay($parms['lpr'], $parms['ivsno'], $rows_cario);
  582. // [mitac] 要求 mitac 扣款 END
  583. }
  584. return true;
  585. break;
  586. }
  587. }
  588. else if ($rows['member_no'] != 0)
  589. {
  590. // CO.Z.1 月租車無入場資料
  591. if($opendoor)
  592. {
  593. // [msg] 10: 月租車無入場資料
  594. $msg_id = 10;
  595. // 會員開門
  596. $this->member_opendoors($parms);
  597. // 會員字幕
  598. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']}".MQ_ALTOB_MSG_END_TAG);
  599. // 產生回傳
  600. return $this->gen_return_msg($msg_id, true);
  601. }
  602. else
  603. {
  604. trigger_error('月租車無入場資料:' . print_r($rows, true));
  605. // 傳送離場記錄
  606. $sync_agent = new AltobSyncAgent();
  607. $sync_agent->init($parms['sno'], $this->now_str);
  608. $sync_agent->member_no = $rows['member_no']; // 會員編號
  609. $sync_agent->finished = 1; // 已離場
  610. $sync_result = $sync_agent->sync_st_out($parms);
  611. trigger_error( "..sync_st_out.." . $sync_result);
  612. }
  613. return true;
  614. }
  615. else
  616. {
  617. // CO.Z.Z 無入場資料
  618. if($opendoor)
  619. {
  620. // [msg] 13: 無入場資料
  621. $msg_id = 13;
  622. $this->mq_send(MQ_TOPIC_ALTOB, MQ_ALTOB_MSG.",{$msg_id},{$parms['ivsno']},{$parms['lpr']}".MQ_ALTOB_MSG_END_TAG);
  623. // 產生回傳
  624. return $this->gen_return_msg($msg_id);
  625. }
  626. else
  627. {
  628. trigger_error('無入場資料:' . print_r($rows, true));
  629. // 傳送離場記錄
  630. $sync_agent = new AltobSyncAgent();
  631. $sync_agent->init($parms['sno'], $this->now_str);
  632. $sync_result = $sync_agent->sync_st_out($parms);
  633. trigger_error( "..sync_st_out.." . $sync_result);
  634. }
  635. return true;
  636. }
  637. break;
  638. }
  639. }
  640. // 檢查是否合法會員或VIP資料
  641. public function get_member($lpr)
  642. {
  643. $where_arr = array
  644. (
  645. 'c.lpr' => $lpr,
  646. 'c.start_time <=' => $this->now_str,
  647. 'c.end_time >=' => $this->now_str
  648. );
  649. $sql = "select
  650. c.lpr_correct,
  651. c.member_no,
  652. m.member_name,
  653. m.member_type,
  654. m.locked,
  655. m.remarks,
  656. m.park_time,
  657. m.suspended,
  658. m.valid_time,
  659. c.etag,
  660. c.start_time,
  661. c.end_time
  662. from member_car c, members m
  663. where c.member_no = m.member_no
  664. and c.start_time <= '{$this->now_str}'
  665. and c.end_time >= '{$this->now_str}'
  666. and c.lpr = '{$lpr}'
  667. limit 1";
  668. $rows = $this->db->query($sql)->row_array();
  669. // 新增 park_time_check 2016/11/11
  670. $park_time_check = 0;
  671. if (!empty($rows['lpr_correct']))
  672. {
  673. $park_time = $rows['park_time'];
  674. $pt_arr = $this->vars['mcache']->get('pt');
  675. if(empty($pt_arr) || empty($park_time))
  676. {
  677. // ERROR: 無法驗証時段, 跳過時段限制判斷
  678. trigger_error("[ERROR] mcache.pt is empty !!");
  679. $park_time_check = 1;
  680. }
  681. else
  682. {
  683. $now_time = substr($this->now_str, 11); // 日期字串只取最後時間字串(13:25:32)
  684. $week_no = date('w',strtotime($this->now_str)); // 取星期幾
  685. $park_time_array = explode(',', $park_time); // 用 , 格開
  686. foreach($park_time_array as $idx => $park_time_value)
  687. {
  688. foreach($pt_arr[$park_time_value]['timex'] as $idx => $pt_rows)
  689. {
  690. if ($week_no >= $pt_rows['w_start'] &&
  691. $week_no <= $pt_rows['w_end'] &&
  692. $now_time >= $pt_rows['time_start'] &&
  693. $now_time <= $pt_rows['time_end'])
  694. {
  695. $park_time_check = 2;
  696. trigger_error("時段代碼:{$park_time_value} 星期:{$week_no}");
  697. break;
  698. }
  699. }
  700. }
  701. }
  702. }
  703. if (empty($rows['lpr_correct'])) // A. 非月租車
  704. {
  705. $rows = array
  706. (
  707. 'lpr_correct' => '',
  708. 'member_no' => 0,
  709. 'member_name' => '',
  710. 'member_type' => 9,
  711. 'etag' => '',
  712. 'start_time' => '',
  713. 'end_time' => '',
  714. );
  715. }
  716. else if(empty($park_time_check)) // B. 月租車, 時段無效
  717. {
  718. trigger_error("無效的時段!! " . print_r($rows, true));
  719. $rows = array
  720. (
  721. 'lpr_correct' => '',
  722. 'member_no' => 0,
  723. 'member_name' => '',
  724. 'member_type' => 9,
  725. 'etag' => '',
  726. 'start_time' => '',
  727. 'end_time' => '',
  728. );
  729. }
  730. else if(!empty($rows['suspended'])) // C. 月租車, 停權中
  731. {
  732. trigger_error("停權中!! " . print_r($rows, true));
  733. $rows = array
  734. (
  735. 'lpr_correct' => '',
  736. 'member_no' => 0,
  737. 'member_name' => '',
  738. 'member_type' => 9,
  739. 'etag' => '',
  740. 'start_time' => '',
  741. 'end_time' => '',
  742. );
  743. }
  744. else if(!empty($rows['valid_time']) && $rows['valid_time'] < $this->now_str) // D. 月租車, 已無效 (審核未通過)
  745. {
  746. trigger_error("已無效!! " . print_r($rows, true));
  747. $rows = array
  748. (
  749. 'lpr_correct' => '',
  750. 'member_no' => 0,
  751. 'member_name' => '',
  752. 'member_type' => 9,
  753. 'etag' => '',
  754. 'start_time' => '',
  755. 'end_time' => '',
  756. );
  757. }
  758. trigger_error('讀取會員:' . print_r($rows, true) . ", park_time_check: {$park_time_check}");
  759. /*
  760. // 20171025 強制先不導入會員
  761. $rows = array
  762. (
  763. 'lpr_correct' => '',
  764. 'member_no' => 0,
  765. 'member_name' => '',
  766. 'member_type' => 9,
  767. 'etag' => '',
  768. 'start_time' => '',
  769. 'end_time' => '',
  770. );
  771. trigger_error(__FUNCTION__ . '..force not found..');
  772. */
  773. return $rows;
  774. }
  775. /*
  776. // 開門 (月租)
  777. public function member_opendoors($parms)
  778. {
  779. $this->mq_send(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},OPEN,{$parms['lpr']}");
  780. return true;
  781. }
  782. // 開門 (臨停)
  783. public function temp_opendoors($parms)
  784. {
  785. $this->mq_send(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},TICKET,{$parms['lpr']}");
  786. return true;
  787. }
  788. */
  789. // 用eTag讀出車號
  790. public function etag2lpr_2($etag)
  791. {
  792. // 用讀取eTag記錄(有double驗證過)
  793. $rows = $this->db->select('lpr')
  794. ->from('etag_lpr')
  795. ->where(array('etag' => $etag, 'confirms >' => 0))
  796. ->limit(1)
  797. ->get()
  798. ->row_array();
  799. // 讀出eTag資料
  800. if (!empty($rows['lpr']))
  801. {
  802. trigger_error("+++車牌NONE,以eTag讀入車牌:{$etag}|{$rows['lpr']}");
  803. return $rows['lpr'];
  804. }
  805. return 'NONE';
  806. }
  807. // 有車牌與eTag, 檢查資料庫 (2017/03/22 new)
  808. public function check_lpr_etag($lpr, $etag)
  809. {
  810. $ETAG_LOG_TITLE = 'etag://';
  811. $ETAG_WARMIN_TITLE = 'etag-warning://';
  812. trigger_error($ETAG_LOG_TITLE. "輸入: {$lpr},{$etag}");
  813. // 手動值上下限
  814. $max_admin_confirms_value = 99;
  815. $min_admin_confirms_value = 50;
  816. // 自動值上下限
  817. $max_system_confirms_value = 33;
  818. $min_system_confirms_value = 0;
  819. // 判斷對應加權
  820. $etag_confirms_bias_plus = 11; // etag 找 車牌, 對上一次可扺 11次
  821. $etag_confirms_bias_minus = -1;
  822. $lpr_confirms_bias_plus = 3; // 車牌 找 etag, 對上一次可扺 3次
  823. $lpr_confirms_bias_minus = -1;
  824. // eTag 找 車牌
  825. $lpr_info_from_etag = $this->db->select('lpr, confirms')
  826. ->from('etag_lpr')
  827. ->where(array('etag' => $etag))
  828. ->limit(1)
  829. ->get()
  830. ->row_array();
  831. if (!empty($lpr_info_from_etag['lpr']))
  832. {
  833. // B. etag 有找到 車牌
  834. if ($lpr_info_from_etag['lpr'] == $lpr)
  835. {
  836. // B.1. etag 有找到 車牌, 且 車牌 相符, confirms 上升
  837. $confirms_bias = $etag_confirms_bias_plus;
  838. }
  839. else
  840. {
  841. // B.2. etag 有找到 車牌, 但 車牌 不符, confirms 下降
  842. $confirms_bias = $etag_confirms_bias_minus;
  843. trigger_error($ETAG_WARMIN_TITLE . "etag 找 lpr | lpr error : {$lpr},{$etag} | query:" . print_r($lpr_info_from_etag, true));
  844. }
  845. $next_confirms_value = $lpr_info_from_etag['confirms'] + $confirms_bias;
  846. trigger_error($ETAG_LOG_TITLE . "etag 找 lpr | {$lpr},{$etag}, next_confirms: {$next_confirms_value}, bias:{$confirms_bias}");
  847. // 更新 confirms 資訊
  848. if($next_confirms_value > $max_admin_confirms_value)
  849. {
  850. // B.3.0 confirms 超過 max_admin_confirms_value, skip
  851. //trigger_error($ETAG_LOG_TITLE . "etag 找 lpr | {$lpr},{$etag} next_confirms_value > max_admin_confirms_value : {$max_admin_confirms_value}");
  852. }
  853. else if ($next_confirms_value >= $min_admin_confirms_value)
  854. {
  855. // B.3.1 人工確認過的記錄, 誤判多次後會停留在 min_admin_confirms_value, 或加到 max_admin_confirms_value
  856. $this->db->where('etag', $etag)->update('etag_lpr', array('confirms' => $next_confirms_value));
  857. }
  858. else if ($next_confirms_value > $max_system_confirms_value)
  859. {
  860. // B.3.2 confirms 超過 max_system_confirms_value, skip
  861. //trigger_error($ETAG_LOG_TITLE . "etag 找 lpr | {$lpr},{$etag} next_confirms_value > max_system_confirms_value : {$max_system_confirms_value}");
  862. }
  863. else if ($next_confirms_value <= $max_system_confirms_value && $next_confirms_value >= $min_system_confirms_value)
  864. {
  865. // B.3.3 confirms 不到 max_system_confirms_value 為系統生成記錄, 誤判多次後 confirms 會扣到 min_system_confirms_value
  866. $this->db->where('etag', $etag)->update('etag_lpr', array('confirms' => $next_confirms_value));
  867. }
  868. else
  869. {
  870. // B.3.4 若低於 min_system_confirms_value,刪除
  871. $this->db->delete('etag_lpr', array('etag' => $etag));
  872. trigger_error($ETAG_LOG_TITLE . "etag 找 lpr | etag confirms fail and removed : {$lpr_info_from_etag['lpr']}, {$etag}");
  873. trigger_error($ETAG_WARMIN_TITLE . "etag 找 lpr | etag confirms fail and removed : {$lpr_info_from_etag['lpr']}, {$etag}");
  874. }
  875. }
  876. else
  877. {
  878. // 車牌 找 etag
  879. $etag_info_form_lpr = $this->db->select('etag, confirms, member_no')
  880. ->from('etag_lpr')
  881. ->where(array('lpr' => $lpr))
  882. ->limit(1)
  883. ->get()
  884. ->row_array();
  885. if (!empty($etag_info_form_lpr['etag']))
  886. {
  887. // A. 車牌 有找到 etag
  888. if ($etag_info_form_lpr['etag'] == $etag)
  889. {
  890. // A.1. 車牌 有找到 etag, 且 etag 相符, confirms 上升
  891. $confirms_bias = $lpr_confirms_bias_plus;
  892. // 若尚未登記為會員
  893. if(empty($etag_info_form_lpr['member_no']))
  894. {
  895. // 檢查是否會員
  896. $member_info_from_lpr = $this->db->select('member_no, member_name')
  897. ->from('members')
  898. ->where(array('lpr' => $lpr))
  899. ->limit(1)
  900. ->get()
  901. ->row_array();
  902. // 確認為會員, 建立 eTag 資訊
  903. if (!empty($member_info_from_lpr['member_no']))
  904. {
  905. $data['member_no'] = $member_info_from_lpr['member_no'];
  906. $data['member_name'] = $member_info_from_lpr['member_name'];
  907. $this->db->where('member_no', $member_info_from_lpr['member_no'])->update('member_car', array('etag' => $etag));
  908. $this->db->where('member_no', $member_info_from_lpr['member_no'])->update('members', array('etag' => $etag));
  909. // 更新 etag_lpr
  910. $this->db->where('etag', $etag)->update('etag_lpr', $data);
  911. }
  912. }
  913. }
  914. else
  915. {
  916. // A.2. 車牌 有找到 etag, 但 etag 不符, confirms 下降
  917. $confirms_bias = $lpr_confirms_bias_minus;
  918. trigger_error($ETAG_WARMIN_TITLE . "lpr 找 etag | etag error : {$lpr},{$etag} | query:" . print_r($etag_info_form_lpr, true));
  919. }
  920. $next_confirms_value = $lpr_info_from_etag['confirms'] + $confirms_bias;
  921. trigger_error($ETAG_LOG_TITLE . "lpr 找 etag | {$lpr},{$etag}, next_confirms: {$next_confirms_value}, bias:{$confirms_bias}");
  922. // 更新 confirms 資訊
  923. if($next_confirms_value > $max_admin_confirms_value)
  924. {
  925. // A.3.0 confirms 超過 max_admin_confirms_value, skip
  926. //trigger_error($ETAG_LOG_TITLE . "lpr 找 etag | {$lpr},{$etag} next_confirms_value > max_admin_confirms_value : {$max_admin_confirms_value}");
  927. }
  928. else if ($next_confirms_value >= $min_admin_confirms_value)
  929. {
  930. // A.3.1 人工確認過的記錄, 誤判多次後會停留在 min_admin_confirms_value, 或加到 max_admin_confirms_value
  931. $this->db->where('lpr', $lpr)->update('etag_lpr', array('confirms' => $next_confirms_value));
  932. }
  933. else if ($next_confirms_value > $max_system_confirms_value)
  934. {
  935. // A.3.2 confirms 超過 max_system_confirms_value, skip
  936. //trigger_error($ETAG_LOG_TITLE . "lpr 找 etag | {$lpr},{$etag} next_confirms_value > max_system_confirms_value : {$max_system_confirms_value}");
  937. }
  938. else if ($next_confirms_value <= $max_system_confirms_value && $next_confirms_value >= $min_system_confirms_value)
  939. {
  940. // A.3.3 confirms 不到 max_system_confirms_value 為系統生成記錄, 誤判多次後 confirms 會扣到 min_system_confirms_value
  941. $this->db->where('lpr', $lpr)->update('etag_lpr', array('confirms' => $next_confirms_value));
  942. }
  943. else
  944. {
  945. // A.3.4 若低於 min_system_confirms_value,刪除
  946. $this->db->delete('etag_lpr', array('lpr' => $lpr));
  947. trigger_error($ETAG_LOG_TITLE . "lpr 找 etag | lpr confirms fail and removed : {$lpr}, {$etag_info_form_lpr['etag']}");
  948. trigger_error($ETAG_WARMIN_TITLE . "lpr 找 etag | lpr confirms fail and removed : {$lpr}, {$etag_info_form_lpr['etag']}");
  949. }
  950. }
  951. else
  952. {
  953. // C. 車牌 與 etag 都找不到記錄
  954. $data = array
  955. (
  956. 'lpr' => $lpr,
  957. 'lpr_correct' => $lpr,
  958. 'etag' => $etag
  959. );
  960. // 檢查是否會員
  961. $member_info_from_lpr = $this->db->select('member_no, member_name')
  962. ->from('members')
  963. ->where(array('lpr' => $lpr))
  964. ->limit(1)
  965. ->get()
  966. ->row_array();
  967. // 會員者, 將eTag update回去
  968. if (!empty($member_info_from_lpr['member_no']))
  969. {
  970. $data['member_no'] = $member_info_from_lpr['member_no'];
  971. $data['member_name'] = $member_info_from_lpr['member_name'];
  972. $this->db->where('member_no', $member_info_from_lpr['member_no'])->update('member_car', array('etag' => $etag));
  973. $this->db->where('member_no', $member_info_from_lpr['member_no'])->update('members', array('etag' => $etag));
  974. }
  975. // 建立第一筆記錄
  976. $this->db->insert('etag_lpr', $data);
  977. $etag_lpr_seqno = $this->db->insert_id();
  978. trigger_error($ETAG_LOG_TITLE . "create | insert seqno = {$etag_lpr_seqno}". print_r($data, true));
  979. }
  980. }
  981. }
  982. /*
  983. // 有車牌與eTag, 檢查資料庫
  984. public function check_lpr_etag($lpr, $etag)
  985. {
  986. // 用讀取eTag記錄(有double驗證過)
  987. $rows = $this->db->select('etag, confirms')
  988. ->from('etag_lpr')
  989. ->where(array('lpr' => $lpr))
  990. ->limit(1)
  991. ->get()
  992. ->row_array();
  993. // 讀出eTag資料
  994. if (!empty($rows['etag']))
  995. {
  996. // 車牌與eTag皆相符, 檢查是否confirms欄位若為0, 設成1(double驗證)
  997. if ($rows['etag'] == $etag)
  998. {
  999. if ($rows['confirms'] == 0) $this->db->where('lpr', $lpr)->update('etag_lpr', array('confirms' => 1));
  1000. }
  1001. else // eTag不相符
  1002. {
  1003. if ($rows['confirms'] == 1)
  1004. {
  1005. $this->db->where('lpr', $lpr)->update('etag_lpr', array('confirms' => 0));
  1006. }
  1007. else // 原confirms為0者, 刪除之
  1008. {
  1009. $this->db->delete('etag_lpr', array('lpr' => $lpr));
  1010. }
  1011. }
  1012. }
  1013. else // 無資料, 新增一筆
  1014. {
  1015. // 再檢查一次是否有eTag ?
  1016. $rows_etag = $this->db->select('lpr, confirms')
  1017. ->from('etag_lpr')
  1018. ->where(array('etag' => $etag))
  1019. ->limit(1)
  1020. ->get()
  1021. ->row_array();
  1022. if (empty($rows_etag['lpr'])) // 無資料
  1023. {
  1024. $data = array
  1025. (
  1026. 'lpr' => $lpr,
  1027. 'lpr_correct' => $lpr,
  1028. 'etag' => $etag
  1029. );
  1030. // 檢查是否會員
  1031. $rows_members = $this->db->select('member_no, member_name')
  1032. ->from('members')
  1033. ->where(array('lpr' => $lpr))
  1034. ->limit(1)
  1035. ->get()
  1036. ->row_array();
  1037. // 會員者, 將eTag update回去
  1038. if (!empty($rows_members['member_no']))
  1039. {
  1040. $data['member_no'] = $rows_members['member_no'];
  1041. $data['member_name'] = $rows_members['member_name'];
  1042. $this->db->where('member_no', $rows_members['member_no'])->update('member_car', array('etag' => $etag));
  1043. $this->db->where('member_no', $rows_members['member_no'])->update('members', array('etag' => $etag));
  1044. }
  1045. $this->db->insert('etag_lpr', $data);
  1046. }
  1047. else
  1048. {
  1049. if ($rows_etag['confirms'] == 1)
  1050. {
  1051. $this->db->where('etag', $etag)->update('etag_lpr', array('confirms' => 0));
  1052. }
  1053. else // 原confirms為0者, 刪除之
  1054. {
  1055. $this->db->delete('etag_lpr', array('etag' => $etag));
  1056. }
  1057. }
  1058. }
  1059. }
  1060. */
  1061. // 送出至message queue(目前用mqtt)
  1062. public function mq_send($topic, $msg)
  1063. {
  1064. $this->vars['mqtt']->publish($topic, $msg, 0);
  1065. trigger_error("mqtt:{$topic}|{$msg}");
  1066. usleep(100000); // delay 0.1 sec (避免漏訊號)
  1067. }
  1068. // 產生 CK
  1069. public function gen_opendoor_ck($parms, $function_name)
  1070. {
  1071. return md5($parms['ivsno']. 'alt' . date('dmh') . 'o' . $parms['lpr'] . 'b' . $function_name);
  1072. }
  1073. // 開門 (月租)
  1074. public function member_opendoors($parms)
  1075. {
  1076. //$this->mq_send_opendoor(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},OPEN,{$parms['lpr']}");
  1077. $ck = $this->gen_opendoor_ck($parms, __FUNCTION__);
  1078. get_headers("http://localhost/cars.html/" . __FUNCTION__ . "/{$parms['ivsno']}/{$parms['lpr']}/{$ck}");
  1079. return true;
  1080. }
  1081. // 開門 (臨停)
  1082. public function temp_opendoors($parms)
  1083. {
  1084. //$this->mq_send_opendoor(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},TICKET,{$parms['lpr']}");
  1085. $ck = $this->gen_opendoor_ck($parms, __FUNCTION__);
  1086. get_headers("http://localhost/cars.html/" . __FUNCTION__ ."/{$parms['ivsno']}/{$parms['lpr']}/{$ck}");
  1087. return true;
  1088. }
  1089. // 開門 (月租)
  1090. public function do_member_opendoor($parms)
  1091. {
  1092. if($parms['ck'] != $this->gen_opendoor_ck($parms, 'member_opendoors'))
  1093. {
  1094. return 'ck_error'; // 中斷
  1095. }
  1096. $this->mq_send(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},OPEN,{$parms['lpr']}");
  1097. return 'ok';
  1098. }
  1099. // 開門 (臨停)
  1100. public function do_temp_opendoor($parms)
  1101. {
  1102. if($parms['ck'] != $this->gen_opendoor_ck($parms, 'temp_opendoors'))
  1103. {
  1104. return 'ck_error'; // 中斷
  1105. }
  1106. $this->mq_send(MQ_TOPIC_OPEN_DOOR, "DO{$parms['ivsno']},TICKET,{$parms['lpr']}");
  1107. return 'ok';
  1108. }
  1109. // 指派車位
  1110. // http://203.75.167.89/parkingquery.html/get_valid_seat
  1111. // 註記現在時間, 並保留10分鐘
  1112. public function get_valid_seat()
  1113. {
  1114. $data = array();
  1115. //$data['result']['location_no'] = '0';
  1116. //$data['result_code'] = 'FAIL';
  1117. //return $data;
  1118. // 撈 roger db
  1119. /*
  1120. $sql = "
  1121. SELECT ParkingNum AS pksno FROM table_carpark
  1122. WHERE LPR = '' AND DisableSeat = 0 AND
  1123. (SELECT COUNT(*) FROM table_carpark WHERE LPR = '' AND DisableSeat = 0) <= 10
  1124. ORDER BY RAND() LIMIT 1 FOR UPDATE;
  1125. ";
  1126. $dsn_old_db = $this->load->database('old_db', true);
  1127. // 2016/12/14 roger_db 掛了的可能
  1128. if ($dsn_old_db->initialize())
  1129. {
  1130. $retults = $dsn_old_db->query($sql)->result_array();
  1131. }
  1132. if(!empty($retults[0]))
  1133. {
  1134. $data['result']['location_no'] = substr($retults[0]['pksno'], 1);
  1135. $data['result_code'] = 'OK';
  1136. $data['loc_name'] = 'B'.substr($retults[0]['pksno'], 0, 1);
  1137. $data['floors'] = 'B'.substr($retults[0]['pksno'], 0, 1);
  1138. }
  1139. else
  1140. {
  1141. $data['result']['location_no'] = '0';
  1142. $data['result_code'] = 'FAIL';
  1143. }
  1144. */
  1145. $this->db->trans_start();
  1146. $sql = "select pksno from pks where status = 'VA' and prioritys != 0 and (book_time is null or book_time <= now()) order by prioritys asc limit 1 for update;";
  1147. $rows = $this->db->query($sql)->row_array();
  1148. if (!empty($rows['pksno']))
  1149. {
  1150. $data['result']['location_no'] = substr($rows['pksno'], -3);
  1151. $data['result_code'] = 'OK';
  1152. $sql = "update pks set book_time = addtime(now(), '00:10:00') where pksno = {$rows['pksno']};";
  1153. $this->db->query($sql);
  1154. $sql = "select g.group_name, g.floors from pks_groups g, pks_group_member m where m.pksno = {$rows['pksno']} and g.group_id = m.group_id and g.group_type = 1 limit 1";
  1155. $rows = $this->db->query($sql)->row_array();
  1156. $data['loc_name'] = $rows['group_name'];
  1157. $data['floors'] = $rows['floors'];
  1158. }
  1159. else
  1160. {
  1161. $data['result']['location_no'] = '0';
  1162. $data['result_code'] = 'FAIL';
  1163. }
  1164. $this->db->trans_complete();
  1165. return $data;
  1166. }
  1167. // 取得出入口 888 資訊
  1168. public function get_888_info($parms)
  1169. {
  1170. $data = array();
  1171. $sql = "select availables as availables, tot as tot from pks_groups where group_id = 'C888' and station_no = {$parms['sno']}";
  1172. $rows = $this->db->query($sql)->row_array();
  1173. if (!empty($rows) && array_key_exists('availables', $rows))
  1174. {
  1175. $data['result_code'] = 'OK';
  1176. $data['availables'] = $rows['availables'];
  1177. $data['tot'] = $rows['tot'];
  1178. }
  1179. else
  1180. {
  1181. trigger_error(__FUNCTION__ . "..not found..".print_r($parms, true));
  1182. $data['result_code'] = 'FAIL';
  1183. $data['availables'] = 9999; // 如果拿不到就忽略這個流程
  1184. $data['tot'] = 0;
  1185. }
  1186. return $data;
  1187. }
  1188. // ===============================================
  1189. // acer cmd
  1190. // ===============================================
  1191. // 產生通行碼
  1192. function gen_pass_code()
  1193. {
  1194. return rand(100000,999999);
  1195. }
  1196. // 呼叫acer
  1197. function call_acer($cmd, $parms)
  1198. {
  1199. return false; // 尚未啟用
  1200. try{
  1201. $ch = curl_init();
  1202. curl_setopt($ch, CURLOPT_URL, 'http://localhost/acer_service.html/cmd_'. $cmd);
  1203. curl_setopt($ch, CURLOPT_HEADER, FALSE);
  1204. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  1205. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  1206. curl_setopt($ch, CURLOPT_POST, TRUE);
  1207. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,3);
  1208. curl_setopt($ch, CURLOPT_TIMEOUT, 3); //timeout in seconds
  1209. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($parms));
  1210. $data = curl_exec($ch);
  1211. if(curl_errno($ch))
  1212. {
  1213. trigger_error(__FUNCTION__ . ', curl error: '. curl_error($ch));
  1214. }
  1215. curl_close($ch);
  1216. trigger_error(__FUNCTION__ . '..'. $data);
  1217. }catch (Exception $e){
  1218. trigger_error(__FUNCTION__ . 'error:'.$e->getMessage());
  1219. }
  1220. }
  1221. // ===============================================
  1222. // mitac cmd
  1223. // ===============================================
  1224. // 檢查指定時間是否介於停車時段區間
  1225. function check_park_time($park_time, $target_time)
  1226. {
  1227. $pt_arr = $this->vars['mcache']->get('pt');
  1228. $now_time = substr($target_time, 11); // 日期字串只取最後時間字串(13:25:32)
  1229. $week_no = date('w',strtotime($target_time)); // 取星期幾
  1230. $park_time_array = explode(',', $park_time); // 用 , 格開
  1231. foreach($park_time_array as $idx => $park_time_value)
  1232. {
  1233. foreach($pt_arr[$park_time_value]['timex'] as $idx => $pt_rows)
  1234. {
  1235. if ($week_no >= $pt_rows['w_start'] &&
  1236. $week_no <= $pt_rows['w_end'] &&
  1237. $now_time >= $pt_rows['time_start'] &&
  1238. $now_time <= $pt_rows['time_end'])
  1239. {
  1240. return true;
  1241. }
  1242. }
  1243. }
  1244. return false;
  1245. }
  1246. // 取得會員時段區間起點
  1247. function gen_park_time_first($park_time, $target_time)
  1248. {
  1249. $pt_arr = $this->vars['mcache']->get('pt');
  1250. $now_time = substr($target_time, 11); // 日期字串只取最後時間字串(13:25:32)
  1251. $week_no = date('w',strtotime($target_time)); // 取星期幾
  1252. $park_time_array = explode(',', $park_time); // 用 , 格開
  1253. $week_no_first = 0;
  1254. $time_end_first = '';
  1255. foreach($park_time_array as $idx => $park_time_value)
  1256. {
  1257. foreach($pt_arr[$park_time_value]['timex'] as $idx => $pt_rows)
  1258. {
  1259. if ($week_no >= $pt_rows['w_start'] &&
  1260. $week_no <= $pt_rows['w_end'] &&
  1261. $now_time >= $pt_rows['time_start'] &&
  1262. $now_time <= $pt_rows['time_end'])
  1263. {
  1264. $week_no_first = $pt_rows['w_start'];
  1265. $time_end_first = $pt_rows['time_start'];
  1266. trigger_error(__FUNCTION__ . "|$park_time, $target_time | $week_no_first, $time_end_first");
  1267. break;
  1268. }
  1269. }
  1270. }
  1271. $day_offset = $week_no - $week_no_first;
  1272. if($day_offset < 0)
  1273. {
  1274. trigger_error(__FUNCTION__ . '..error..offset..' . $day_offset);
  1275. $day_offset = 0;
  1276. }
  1277. return date('Y-m-d', strtotime("-$day_offset day", strtotime($target_time))). " $time_end_first";
  1278. }
  1279. // 取得會員時段區間終點
  1280. function gen_park_time_last($park_time, $target_time)
  1281. {
  1282. $pt_arr = $this->vars['mcache']->get('pt');
  1283. $now_time = substr($target_time, 11); // 日期字串只取最後時間字串(13:25:32)
  1284. $week_no = date('w',strtotime($target_time)); // 取星期幾
  1285. $park_time_array = explode(',', $park_time); // 用 , 格開
  1286. $week_no_last = 0;
  1287. $time_end_last = '';
  1288. foreach($park_time_array as $idx => $park_time_value)
  1289. {
  1290. foreach($pt_arr[$park_time_value]['timex'] as $idx => $pt_rows)
  1291. {
  1292. if ($week_no >= $pt_rows['w_start'] &&
  1293. $week_no <= $pt_rows['w_end'] &&
  1294. $now_time >= $pt_rows['time_start'] &&
  1295. $now_time <= $pt_rows['time_end'])
  1296. {
  1297. $week_no_last = $pt_rows['w_end'];
  1298. $time_end_last = $pt_rows['time_end'];
  1299. trigger_error(__FUNCTION__ . "|$park_time, $target_time | $week_no_last, $time_end_last");
  1300. break;
  1301. }
  1302. }
  1303. }
  1304. $day_offset = $week_no_last - $week_no;
  1305. if($day_offset < 0)
  1306. {
  1307. trigger_error(__FUNCTION__ . '..error..offset..' . $day_offset);
  1308. $day_offset = 0;
  1309. }
  1310. return date('Y-m-d', strtotime("+$day_offset day", strtotime($target_time))). " $time_end_last";
  1311. }
  1312. // 取得會員身份減免後的費用起算時間
  1313. function check_member_state($lpr, $in_time, $out_time)
  1314. {
  1315. // 檢查月租身份修正
  1316. $member_info = $this->get_member($lpr, false);
  1317. if ($member_info['member_no'] == 0)
  1318. {
  1319. // 查無會員身份
  1320. $member_state = 0;
  1321. $new_in_time = $in_time;
  1322. $new_out_time = $out_time;
  1323. }
  1324. else
  1325. {
  1326. $park_time = $member_info['park_time'];
  1327. $pt_arr = $this->vars['mcache']->get('pt');
  1328. if(empty($pt_arr) || empty($park_time))
  1329. {
  1330. // ERROR: 無法驗証時段, 跳過時段限制判斷
  1331. $member_state = 1;
  1332. $new_in_time = $in_time;
  1333. $new_out_time = $out_time;
  1334. }
  1335. else
  1336. {
  1337. $in_time_in_park_time = $this->check_park_time($park_time, $in_time);
  1338. $out_time_in_park_time = $this->check_park_time($park_time, $out_time);
  1339. trigger_error(__FUNCTION__ . "|$lpr, $in_time, $out_time|..check_park_time: {$in_time_in_park_time}, {$out_time_in_park_time}..");
  1340. if($in_time_in_park_time && $out_time_in_park_time)
  1341. {
  1342. // 進出時間都在會員區間內: 費用起算時間改為出場時間
  1343. $member_state = 2;
  1344. $new_in_time = $out_time;
  1345. $new_out_time = $out_time;
  1346. }
  1347. else if($in_time_in_park_time)
  1348. {
  1349. // 入場時間在會員區間內: 費用起算時間改為, 會員時段區間終點
  1350. $member_state = 3;
  1351. $new_in_time = $this->gen_park_time_last($park_time, $in_time);
  1352. $new_out_time = $out_time;
  1353. if(strtotime($new_in_time) > strtotime($out_time))
  1354. {
  1355. trigger_error(__FUNCTION__ . "|$lpr, $in_time, $out_time|new_in_time error >> out_time..");
  1356. $new_in_time = $out_time;
  1357. }
  1358. }
  1359. else if($out_time_in_park_time)
  1360. {
  1361. // 出場時間在會員區間內: 費用起算時間改為, 會員時段區間起點
  1362. $member_state = 4;
  1363. $new_in_time = $in_time;
  1364. $new_out_time = $this->gen_park_time_first($park_time, $out_time);
  1365. if(strtotime($in_time) > strtotime($new_out_time))
  1366. {
  1367. trigger_error(__FUNCTION__ . "|$lpr, $in_time, $out_time|new_in_time error >> out_time..");
  1368. $new_out_time = $out_time;
  1369. }
  1370. }
  1371. }
  1372. }
  1373. $member_result = array('state' => $member_state, 'in_time' => $new_in_time, 'out_time' => $new_out_time);
  1374. trigger_error(__FUNCTION__ . "|$lpr, $in_time, $out_time|..". print_r($member_result, true));
  1375. return $member_result;
  1376. }
  1377. // 要求 mitac 扣款
  1378. function call_mitac_pay($lpr, $ivsno, $rows_cario)
  1379. {
  1380. $function_name = 'parking_fee_altob';
  1381. $seqno = $rows_cario['cario_no'];
  1382. $in_time = $rows_cario['out_before_time'];
  1383. $out_time = $this->now_str;
  1384. $gate_id = 1; // 20171124 改為強制 1//$ivsno;
  1385. // 確認會員身份
  1386. $member_result = $this->check_member_state($lpr, $in_time, $out_time);
  1387. switch($member_result['state'])
  1388. {
  1389. case 0:
  1390. trigger_error(__FUNCTION__ . '|非會員|');
  1391. break;
  1392. case 1:
  1393. trigger_error(__FUNCTION__ . '|無法驗証時段|skip MITAC|'. print_r($member_result, true));
  1394. return false; // 跳過 mitac
  1395. break;
  1396. case 2:
  1397. trigger_error(__FUNCTION__ . '|進出時間都在會員區間內|skip MITAC|'. print_r($member_result, true));
  1398. return false; // 跳過 mitac
  1399. break;
  1400. case 3:
  1401. trigger_error(__FUNCTION__ . '|入場時間在會員區間內|'. print_r($member_result, true));
  1402. $in_time = $member_result['in_time'];
  1403. break;
  1404. case 4:
  1405. trigger_error(__FUNCTION__ . '|出場時間在會員區間內|'. print_r($member_result, true));
  1406. $out_time = $member_result['out_time'];
  1407. break;
  1408. default:
  1409. trigger_error(__FUNCTION__ . '|未定義|'. print_r($member_result, true));
  1410. break;
  1411. }
  1412. // 通訊內容
  1413. $parms = array(
  1414. 'seqno' => $seqno,
  1415. 'lpr' => $lpr,
  1416. 'in_time' => $in_time,
  1417. 'out_time' => $out_time,
  1418. 'gate_id' => $gate_id);
  1419. // 超過一天就擋掉
  1420. if(strtotime($parms['out_time']) - strtotime($parms['in_time']) > 86400)
  1421. {
  1422. trigger_error(__FUNCTION__ . '|超過計費時限|skip MITAC|'. print_r($parms, true));
  1423. return false; // 跳過 mitac
  1424. }
  1425. // 驗証碼
  1426. $parms['ck'] = md5($parms['seqno']. 'a' . date('dmh') . 'l' . $parms['lpr'] . 't'. $parms['in_time']. 'o'. $parms['out_time'] . 'b'. $parms['gate_id'] . $function_name);
  1427. // 呼叫
  1428. try{
  1429. $ch = curl_init();
  1430. curl_setopt($ch, CURLOPT_URL, "http://localhost/mitac_service.html/{$function_name}");
  1431. curl_setopt($ch, CURLOPT_HEADER, FALSE);
  1432. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  1433. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  1434. curl_setopt($ch, CURLOPT_POST, TRUE);
  1435. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,3);
  1436. curl_setopt($ch, CURLOPT_TIMEOUT, 3); //timeout in seconds
  1437. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($parms));
  1438. $data = curl_exec($ch);
  1439. if(curl_errno($ch))
  1440. {
  1441. trigger_error(__FUNCTION__ . ', curl error: '. curl_error($ch));
  1442. }
  1443. curl_close($ch);
  1444. trigger_error(__FUNCTION__ . '..'. $data);
  1445. }catch (Exception $e){
  1446. trigger_error(__FUNCTION__ . 'error:'.$e->getMessage());
  1447. }
  1448. }
  1449. }