VM暫存
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Altob.Sync.Integration.php 10KB

il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <?php
  2. /**
  3. * Altob 資料同步
  4. *
  5. * @version 1.0
  6. * @author mip
  7. */
  8. class AltobSyncAgent
  9. {
  10. const SYNC_PKS_URL = 'http://61.219.172.12/parkings/cars.html/'; // 在席記錄
  11. const SYNC_CARS_URL = 'http://61.219.172.12/parkings/cars.html/'; // 進出記錄
  12. const SYNC_ST_URL = 'http://61.219.172.11:60123/admins_station.html/'; // 場站記錄
  13. const API_URL = 'http://parks.altob.com.tw:60123/parkingquery.html/'; // 場站 API
  14. const ALLPA_URL = 'http://61.219.172.11:60123/allpa_service.html/'; // 歐pa卡
  15. public $io = '';
  16. public $etag = '';
  17. public $pic_name = '';
  18. public $ivsno = 0;
  19. public $member_no = 0;
  20. public $finished = 0;
  21. public $in_time = '';
  22. public $cario_no = 0;
  23. private $post_parms;
  24. /**
  25. * 初始化
  26. */
  27. public function init($station_no, $time='')
  28. {
  29. $this->post_parms = array();
  30. $this->post_parms['station_no'] = $station_no;
  31. $this->post_parms['io_time'] = $time;
  32. }
  33. // 檢查基本欄位
  34. function check_init_parms()
  35. {
  36. if(empty($this->post_parms['station_no']))
  37. return 'station_no not set'; // 場站編號
  38. if(empty($this->post_parms['io_time']))
  39. return 'io_time not set'; // 進出時間 (若為繳費帶進場時間)
  40. return false;
  41. }
  42. // ===============================================
  43. // st_io
  44. // ===============================================
  45. // 傳送進場記錄
  46. public function sync_st_in($parms)
  47. {
  48. $error_parms_msg = $this->check_init_parms();
  49. if(!empty($error_parms_msg)) { return $error_parms_msg; }
  50. if(empty($this->cario_no))
  51. return 'cario_no not found';
  52. if(empty($parms['lpr']))
  53. return 'lpr not found';
  54. if(empty($parms['io']))
  55. return 'io not found';
  56. $this->post_parms['cario_no'] = $this->cario_no; // 需設定
  57. $this->post_parms['member_no'] = $this->member_no; // 預設為 0
  58. $this->post_parms['lpr'] = $parms['lpr'];
  59. $this->post_parms['io'] = $parms['io'];
  60. $this->post_parms['etag'] = $parms['etag'] == 'NONE' ? '' : $parms['etag'];
  61. $this->post_parms['pic_name'] = empty($parms['pic_name']) ? '' : $parms['pic_name'];
  62. $this->post_parms['ivsno'] = $parms['ivsno'];
  63. $this->post_parms['out_before_time'] = $this->post_parms['io_time'];
  64. // 初始化網路服務物件。
  65. $oService = new AltobSyncService();
  66. $oService->ServiceURL = AltobSyncAgent::SYNC_CARS_URL;
  67. $oService->ServiceCMD = 'st_in';
  68. // 傳遞參數至遠端。
  69. return $oService->ServerPost($this->post_parms);
  70. }
  71. // 傳送離場記錄
  72. public function sync_st_out($parms)
  73. {
  74. $error_parms_msg = $this->check_init_parms();
  75. if(!empty($error_parms_msg)) { return $error_parms_msg; }
  76. // 有入場記錄時
  77. if($this->cario_no > 0)
  78. {
  79. $this->post_parms['cario_no'] = $this->cario_no;
  80. if(empty($this->in_time))
  81. return 'in_time not found'; // 需設定
  82. $this->post_parms['in_time'] = $this->in_time;
  83. $this->post_parms['minutes'] = floor((strtotime($this->post_parms['io_time']) - strtotime($this->in_time)) / 60); // 停車時數 (分鐘)
  84. }
  85. if(empty($parms['lpr']))
  86. return 'lpr not found';
  87. if(empty($parms['io']))
  88. return 'io not found';
  89. $this->post_parms['member_no'] = $this->member_no; // 預設為 0
  90. $this->post_parms['finished'] = $this->finished; // 預設為 0
  91. $this->post_parms['lpr'] = $parms['lpr'];
  92. $this->post_parms['io'] = $parms['io'];
  93. $this->post_parms['etag'] = $parms['etag'] == 'NONE' ? '' : $parms['etag'];
  94. $this->post_parms['pic_name'] = empty($parms['pic_name']) ? '' : $parms['pic_name'];
  95. $this->post_parms['ivsno'] = $parms['ivsno'];
  96. // 初始化網路服務物件。
  97. $oService = new AltobSyncService();
  98. $oService->ServiceURL = AltobSyncAgent::SYNC_CARS_URL;
  99. $oService->ServiceCMD = 'st_out';
  100. // 傳遞參數至遠端。
  101. return $oService->ServerPost($this->post_parms);
  102. }
  103. // 傳送付費更新記錄
  104. public function sync_st_pay($lpr, $pay_time, $pay_type=0, $out_before_time='')
  105. {
  106. $error_parms_msg = $this->check_init_parms();
  107. if(!empty($error_parms_msg)) { return $error_parms_msg; }
  108. if(empty($this->cario_no))
  109. return 'cario_no not found';
  110. if(empty($lpr))
  111. return 'lpr not found';
  112. if(empty($pay_time))
  113. return 'pay_time not found';
  114. $this->post_parms['cario_no'] = $this->cario_no; // 需設定
  115. $this->post_parms['lpr'] = $lpr;
  116. $this->post_parms['pay_time'] = $pay_time;
  117. $this->post_parms['pay_type'] = $pay_type;
  118. $this->post_parms['out_before_time'] = empty($out_before_time) ? date('Y-m-d H:i:s', strtotime("{$pay_time} + 15 minutes")) : $out_before_time;
  119. // 初始化網路服務物件。
  120. $oService = new AltobSyncService();
  121. $oService->ServiceURL = AltobSyncAgent::SYNC_CARS_URL;
  122. $oService->ServiceCMD = 'st_pay';
  123. // 傳遞參數至遠端。
  124. return $oService->ServerPost($this->post_parms);
  125. }
  126. // ===============================================
  127. // SOS
  128. // ===============================================
  129. // 傳送 SOS
  130. public function sync_st_sos($machine_no)
  131. {
  132. $error_parms_msg = $this->check_init_parms();
  133. if(!empty($error_parms_msg)) { return $error_parms_msg; }
  134. if(empty($machine_no))
  135. return 'machine_no not found';
  136. $this->post_parms['machine_no'] = $machine_no;
  137. // 初始化網路服務物件。
  138. $oService = new AltobSyncService();
  139. $oService->ServiceURL = AltobSyncAgent::SYNC_CARS_URL;
  140. $oService->ServiceCMD = 'st_sos';
  141. // 傳遞參數至遠端。
  142. return $oService->ServerPost($this->post_parms);
  143. }
  144. // ===============================================
  145. // members
  146. // ===============================================
  147. // 取得場站會員
  148. public function get_st_members()
  149. {
  150. if(empty($this->post_parms['station_no']))
  151. return 'station_no not set'; // 場站編號
  152. // 初始化網路服務物件。
  153. $oService = new AltobSyncService();
  154. $oService->ServiceURL = AltobSyncAgent::SYNC_ST_URL;
  155. $oService->ServiceCMD = 'member_query_all';
  156. // 傳遞參數至遠端。
  157. return $oService->ServerPost($this->post_parms);
  158. }
  159. // 同步會員鎖車 (0: 解鎖, 1: 上鎖, 2: 查詢)
  160. public function sync_security_action($lpr, $pswd, $action)
  161. {
  162. if(empty($this->post_parms['station_no']))
  163. return 'station_no not set'; // 場站編號
  164. $station_no = $this->post_parms['station_no'];
  165. $ck = md5($lpr.'i'.$pswd.'iii'.$action);
  166. // 初始化網路服務物件。
  167. $oService = new AltobSyncService();
  168. $oService->ServiceURL = AltobSyncAgent::API_URL;
  169. $oService->ServiceCMD = __FUNCTION__ . "/{$lpr}/{$pswd}/{$action}/{$ck}/{$station_no}";
  170. // 傳遞參數至遠端。
  171. return $oService->ServerPost($this->post_parms);
  172. }
  173. // 同步會員改密碼
  174. public function sync_change_pwd($lpr, $pswd, $new_pwd)
  175. {
  176. if(empty($this->post_parms['station_no']))
  177. return 'station_no not set'; // 場站編號
  178. $station_no = $this->post_parms['station_no'];
  179. $ck = md5($lpr.'i'.$pswd.'iii'.$new_pwd);
  180. // 初始化網路服務物件。
  181. $oService = new AltobSyncService();
  182. $oService->ServiceURL = AltobSyncAgent::API_URL;
  183. $oService->ServiceCMD = __FUNCTION__ . "/{$lpr}/{$pswd}/{$new_pwd}/{$ck}/{$station_no}";
  184. // 傳遞參數至遠端。
  185. return $oService->ServerPost($this->post_parms);
  186. }
  187. // ===============================================
  188. // pks
  189. // ===============================================
  190. // 在席
  191. public function upd_pks_groups($data)
  192. {
  193. if(empty($this->post_parms['station_no']))
  194. return 'station_no not set'; // 場站編號
  195. $this->post_parms['data'] = $data;
  196. // 初始化網路服務物件。
  197. $oService = new AltobSyncService();
  198. $oService->ServiceURL = AltobSyncAgent::SYNC_PKS_URL;
  199. $oService->ServiceCMD = __FUNCTION__;
  200. // 傳遞參數至遠端。
  201. return $oService->ServerPost($this->post_parms);
  202. }
  203. // ===============================================
  204. // 歐Pa卡
  205. // ===============================================
  206. // 歐Pa卡 - 開門
  207. public function allpa_go($lpr)
  208. {
  209. $error_parms_msg = $this->check_init_parms();
  210. if(!empty($error_parms_msg)) { return $error_parms_msg; }
  211. if(empty($this->in_time))
  212. return 'in_time not found'; // 需設定
  213. if(empty($lpr))
  214. return 'lpr not found'; // 需設定
  215. $this->post_parms['in_time'] = $this->in_time;
  216. $this->post_parms['lpr'] = $lpr;
  217. $this->post_parms['ck'] = md5(
  218. $this->post_parms['lpr']. 'a' . date('dmh') . 'lt' .
  219. $this->post_parms['in_time'] . 'o' . // timestamp
  220. $this->post_parms['station_no'] . 'b' . __FUNCTION__ .
  221. $this->post_parms['io_time'] // timestamp
  222. );
  223. // 初始化網路服務物件。
  224. $oService = new AltobSyncService();
  225. $oService->ServiceURL = AltobSyncAgent::ALLPA_URL;
  226. $oService->ServiceCMD = __FUNCTION__;
  227. // 傳遞參數至遠端。
  228. return $oService->ServerPost($this->post_parms);
  229. }
  230. // 歐Pa卡 - 取得場站會員
  231. public function query_allpa_users()
  232. {
  233. $this->post_parms['ck'] = md5('a' . date('dmh') . 'lt' . __FUNCTION__ . 'ob');
  234. // 初始化網路服務物件。
  235. $oService = new AltobSyncService();
  236. $oService->ServiceURL = AltobSyncAgent::ALLPA_URL;
  237. $oService->ServiceCMD = __FUNCTION__;
  238. // 傳遞參數至遠端。
  239. return $oService->ServerPost($this->post_parms);
  240. }
  241. }
  242. /**
  243. * 呼叫網路服務的類別。
  244. */
  245. class AltobSyncService {
  246. /**
  247. * 網路服務類別呼叫的位址。
  248. */
  249. public $ServiceURL = 'ServiceURL';
  250. public $ServiceCMD = 'ServiceCMD';
  251. /**
  252. * 網路服務類別的建構式。
  253. */
  254. function __construct() {$this->AltobSyncService();}
  255. /**
  256. * 網路服務類別的實體。
  257. */
  258. function AltobSyncService() {}
  259. /**
  260. * 提供伺服器端呼叫遠端伺服器 Web API 的方法。
  261. */
  262. function ServerPost($parameters) {
  263. $ch = curl_init();
  264. curl_setopt($ch, CURLOPT_URL, $this->ServiceURL . $this->ServiceCMD);
  265. curl_setopt($ch, CURLOPT_HEADER, FALSE);
  266. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  267. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  268. curl_setopt($ch, CURLOPT_POST, TRUE);
  269. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,5);
  270. curl_setopt($ch, CURLOPT_TIMEOUT, 5); //timeout in seconds
  271. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($parameters));
  272. $rs = curl_exec($ch);
  273. curl_close($ch);
  274. return $rs;
  275. }
  276. }