ShOneanalysis.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. <?php
  2. namespace app\common\server;
  3. use app\common\model\FacilityModel;
  4. use app\common\model\ShoneReceiveInfoModel;
  5. use app\common\model\ShoneReceiveInfoRecode;
  6. use app\common\model\ShoneReceiveQueueModel;
  7. use app\common\model\ShoneSendListModel;
  8. use app\common\model\ShoneSendQueueModel;
  9. use think\facade\Log;
  10. /**
  11. * 手环字符串解析
  12. *
  13. * @author wj
  14. * @date 2023-08-11
  15. */
  16. class ShOneanalysis
  17. {
  18. private $num_scale = 16; //16进制
  19. /**
  20. * 校验长度
  21. *
  22. * @return void
  23. * @author wj
  24. * @date 2023-08-11
  25. */
  26. public function checklen($len, $str)
  27. {
  28. $strlen = mb_strlen($str);
  29. if ($len != $strlen) {
  30. return false;
  31. }
  32. return true;
  33. }
  34. /**
  35. * 获取信息
  36. *
  37. * @return void
  38. * @author wj
  39. * @date 2023-08-11
  40. */
  41. public function getline($str)
  42. {
  43. //[厂商*设备 ID*内容长度*内容]
  44. $preg = "/^\[(.*)\*(.*)\*(.*)\*(.*)\]$/";
  45. preg_match($preg, $str, $match);
  46. if (empty($match)) {
  47. throw new \Exception('解析失败:' . $str);
  48. }
  49. unset($match[0]);
  50. $data = array_values($match);
  51. $sandom_string = $data[0]; //厂商 随机字符串
  52. $device_id_code = $data[1]; //设置id编码
  53. $content_len = $data[2]; //内容长度
  54. $content_str = $data[3]; //内容字符串
  55. $content_len = $this->analysislen($content_len);
  56. $result = $this->checklen($content_len, $content_str);
  57. if (empty($result)) {
  58. throw new \Exception('内容位数错误');
  59. }
  60. $data = [
  61. 'device_id_code' => $device_id_code,
  62. 'content_len' => $content_len,
  63. 'content_str' => $content_str,
  64. ];
  65. return $data;
  66. }
  67. //KA,230814,0,0,96
  68. //WT,130823,160054,V,22.601242,N,113.8302765,E,0.00,0.0,29.2,0,70,96,0,0,00000000,1,1,460,0,8593,265807240,136,0,9999.0
  69. //ICCID,02203002080045057806
  70. public function getcommandcontent($content_str)
  71. {
  72. $content = explode(',', $content_str);
  73. return $content;
  74. }
  75. /**
  76. * 保存手环设备one信息
  77. *
  78. * @return void
  79. * @author wj
  80. * @date 2023-08-11
  81. */
  82. public function saveshouhuanoneinfo()
  83. {
  84. //保存时时
  85. //保存历史
  86. }
  87. //内容解析
  88. //解析长度
  89. public function analysislen($len)
  90. {
  91. //低位数在前
  92. $len = base_convert($len, 16, 10);
  93. return $len;
  94. }
  95. /**
  96. * 获取命令信息
  97. *
  98. * @param [type] $command
  99. * @return void
  100. * @author wj
  101. * @date 2023-08-11
  102. */
  103. public function getcommandinfo($command)
  104. {
  105. $command = strtoupper($command);
  106. $data = [
  107. 'LK' => [
  108. 'content' => [
  109. 'command' => 'LK',
  110. ],
  111. 'kind' => 'back',
  112. ],
  113. 'PING' => [
  114. 'content' => [
  115. 'command' => 'PING',
  116. 'isbind' => 1,
  117. ],
  118. 'kind' => 'back',
  119. ],
  120. 'KA' => [
  121. 'content' => [
  122. 'command' => 'KA',
  123. ],
  124. 'kind' => 'back',
  125. ],
  126. 'MONITOR' => [
  127. 'content' => [
  128. 'command' => 'MONITOR',
  129. 'telno' => '',
  130. ],
  131. 'kind' => 'send',
  132. ],
  133. 'SOS' => [
  134. 'content' => [
  135. 'command' => 'SOS',
  136. 'telno1' => '',
  137. 'telno2' => '',
  138. 'telno3' => '',
  139. ],
  140. 'kind' => 'send',
  141. ],
  142. 'VERNO' => [
  143. 'content' => [
  144. 'command' => 'VERNO',
  145. ],
  146. 'kind' => 'send',
  147. ],
  148. 'ZONE' => [
  149. 'content' => [
  150. 'command' => 'ZONE',
  151. 'zone' => '',
  152. ],
  153. 'kind' => 'send',
  154. ],
  155. 'POWEROFF' => [
  156. 'content' => [
  157. 'command' => 'POWEROFF',
  158. ],
  159. 'kind' => 'send',
  160. ],
  161. 'TEMP' => [
  162. 'content' => [
  163. 'command' => 'temp',
  164. ],
  165. 'kind' => 'back',
  166. ],
  167. 'BPHRT' => [
  168. 'content' => [
  169. 'command' => 'bphrt',
  170. ],
  171. 'kind' => 'back',
  172. ],
  173. 'HEART'=>[
  174. 'content' => [
  175. 'command' => 'heart',
  176. ],
  177. 'kind' => 'back',
  178. ]
  179. ];
  180. if (!isset($data[$command])) {
  181. return false;
  182. }
  183. return $data[$command];
  184. }
  185. public function gettsendcommandinfo($command)
  186. {
  187. $command = strtoupper($command);
  188. $data = [
  189. 'WT' => [
  190. 'content' => [
  191. 'command' => 'WT',
  192. 'date' => '',
  193. 'time' => '',
  194. 'is_location' => '',
  195. 'gps_long' => '',
  196. 'gps_long_tag' => '',
  197. 'gps_lat' => '',
  198. 'gps_lat_tag' => '',
  199. 'speed' => '',
  200. 'direction' => '',
  201. 'poster' => '',
  202. 'direction' => '',
  203. 'gps_satellite_num' => '',
  204. 'gsm_signal_strength' => '',
  205. 'electric_quantity' => '',
  206. 'step_number' => '',
  207. 'roll_number' => '',
  208. 'terminal_status' => '',
  209. ],
  210. 'kind' => 'tsend',
  211. 'need_bacl' => 0,
  212. ],
  213. 'WG' => [
  214. 'content' => [
  215. 'command' => 'WT',
  216. 'date' => '',
  217. 'time' => '',
  218. 'is_location' => '',
  219. 'gps_long' => '',
  220. 'gps_long_tag' => '',
  221. 'gps_lat' => '',
  222. 'gps_lat_tag' => '',
  223. 'speed' => '',
  224. 'direction' => '',
  225. 'poster' => '',
  226. 'direction' => '',
  227. 'gps_satellite_num' => '',
  228. 'gsm_signal_strength' => '',
  229. 'electric_quantity' => '',
  230. 'step_number' => '',
  231. 'roll_number' => '',
  232. 'terminal_status' => '',
  233. ],
  234. 'kind' => 'tsend',
  235. 'need_bacl' => 0,
  236. ],
  237. 'KA' => [
  238. 'content' => [
  239. 'command' => 'KA',
  240. 'date' => '',
  241. 'step_number' => '',
  242. 'roll_number' => '',
  243. 'electric_quantity' => '',
  244. ],
  245. 'kind' => 'tsend',
  246. 'need_back' => 1,
  247. ],
  248. 'LK' => [
  249. 'content' => [
  250. 'command' => 'LK',
  251. ],
  252. 'kind' => 'tsend',
  253. 'need_back' => 1,
  254. ],
  255. 'MONITOR' => [
  256. 'content' => [
  257. 'command' => 'MONITOR',
  258. ],
  259. 'kind' => 'tback',
  260. ],
  261. 'SOS3' => [
  262. 'content' => [
  263. 'command' => 'SOS',
  264. ],
  265. 'kind' => 'tback',
  266. ],
  267. 'VERNO' => [
  268. 'content' => [
  269. 'command' => 'VERNO',
  270. 'version' => '',
  271. ],
  272. 'kind' => 'tback',
  273. ],
  274. 'TEMP' => [
  275. 'content' => [
  276. 'command' => 'temp',
  277. 'temp' => '',
  278. ],
  279. 'kind' => 'tsend',
  280. 'need_back' => 1,
  281. ],
  282. 'BPHRT' => [
  283. 'content' => [
  284. 'command' => 'bphrt',
  285. 'blood_height_pressure' => '',
  286. 'blood_low_pressure' => '',
  287. 'heart_rate' => '',
  288. 'height' => '',
  289. 'gender' => '',
  290. 'age' => '',
  291. 'weight' => '',
  292. ],
  293. 'kind' => 'tsend',
  294. 'need_back' => 1,
  295. ],
  296. 'HEART' => [
  297. 'content' => [
  298. 'command' => 'heart',
  299. 'heart_rate' => '',
  300. ],
  301. 'kind' => 'tsend',
  302. 'need_back' => 1,
  303. ],
  304. ];
  305. if (!isset($data[$command])) {
  306. return false;
  307. }
  308. return $data[$command];
  309. }
  310. /**
  311. * 获取回复权重
  312. *
  313. * @param [type] $command
  314. * @return void
  315. * @author wj
  316. * @date 2023-08-11
  317. */
  318. public function getsendweight($command)
  319. {
  320. $weight = -1;
  321. switch ($command) {
  322. case 'POWEROFF':
  323. //关机
  324. $weight = 99;
  325. break;
  326. case 'RESET':
  327. //重启
  328. $weight = 98;
  329. break;
  330. case 'LK':
  331. case 'PING':
  332. case 'KA':
  333. case 'AL':
  334. case 'UD2';
  335. $weight = 1;
  336. break;
  337. case 'UPLOAD':
  338. case 'MONITOR':
  339. case 'SOS':
  340. case 'LANG':
  341. case 'ZONE':
  342. case 'CENTER':
  343. case 'SOSSMS':
  344. case 'REMOVE':
  345. case 'REMOVESMS':
  346. case 'VERNO':
  347. case 'CR':
  348. case 'SILENCETIME2':
  349. case 'WALKTIME':
  350. case 'SLEEPTIME':
  351. case 'FIND':
  352. case 'REMIND':
  353. case 'SCHEDULE':
  354. case 'PHB':
  355. case 'PHBX':
  356. case 'DPHBX':
  357. case 'MESSAGE':
  358. case 'FACTORY':
  359. case 'PROFILE':
  360. case 'BTEMP2':
  361. case 'BODYTEMP':
  362. case 'BTWARNSET':
  363. case 'APPLOCK':
  364. case 'HRTSTART':
  365. case 'BPHRT':
  366. case 'LSSET':
  367. $weight = 0;
  368. break;
  369. default:
  370. $weight = -1;
  371. break;
  372. }
  373. if ($weight < 0) {
  374. //不需设置 发送信息
  375. return false;
  376. }
  377. return $weight;
  378. }
  379. /**
  380. * 获取设别表id
  381. *
  382. * @return void
  383. * @author wj
  384. * @date 2023-08-11
  385. */
  386. public function getfacilityid($device_id_code)
  387. {
  388. $m_f = new FacilityModel();
  389. $where = ['code' => $device_id_code, 'status' => 1];
  390. $finfo = $m_f->getInfo($where, ['id']);
  391. if (empty($finfo)) {
  392. throw new \Exception("设备信息错误:" . $device_id_code);
  393. }
  394. $id = $finfo['id'];
  395. return $id;
  396. }
  397. /**
  398. * 创建发送信息
  399. *
  400. * @param [type] $data
  401. * @param [type] $command
  402. * @return void
  403. * @author wj
  404. * @date 2023-08-14
  405. */
  406. public function createbacksendmsg($facility_id, $device_id_code, $data, $command)
  407. {
  408. $infoarr = $this->gettsendcommandinfo($command);
  409. if (!$infoarr) {
  410. throw new \Exception("无对应命令数据1:" . $command);
  411. }
  412. $data = $this->getdata($data, $command, $infoarr);
  413. $info_content = $data['info_content'];
  414. $need_back = isset($data['need_back']) && $data['need_back'] ? true : false;
  415. if ($need_back) {
  416. $infoarr = $this->getcommandinfo($command);
  417. $data = $this->getdata($data, $command, $infoarr);
  418. $info_content = $data['info_content'];
  419. $weight = $this->getsendweight($command);
  420. $content = implode(',', $info_content);
  421. $msgdata = [
  422. 0 => '3G',
  423. 'device_id_code' => $device_id_code,
  424. 'len' => str_pad(dechex(mb_strlen($content)), 4, "0", STR_PAD_LEFT),
  425. 'content' => $content,
  426. ];
  427. $msg = '[' . implode('*', $msgdata) . ']';
  428. $sslInsertData = [
  429. 'facility_id' => $facility_id,
  430. 'device_id_code' => $device_id_code,
  431. 'send_msg' => $msg,
  432. 'send_time' => date('Y-m-d H:i:s'),
  433. 'send_weight' => $weight,
  434. ];
  435. $m_ssl = new ShoneSendListModel();
  436. $sslid = $m_ssl->insertData($sslInsertData);
  437. if (empty($sslid)) {
  438. throw new \Exception("发送数据添加失败");
  439. }
  440. $data = [
  441. 'msg' => $msg,
  442. 'weight' => $weight,
  443. 'createtime' => date('Y-m-d H:i:s'),
  444. 'device_id_code' => $device_id_code,
  445. 'list_id' => $sslid,
  446. ];
  447. $m_ssq = new ShoneSendQueueModel();
  448. $id = $m_ssq->insertData($data);
  449. if (empty($id)) {
  450. throw new \Exception("发送队列数据添加失败");
  451. }
  452. return $data;
  453. }
  454. return false;
  455. }
  456. /**
  457. * 获取数据值
  458. *
  459. * @param [type] $data
  460. * @param [type] $command
  461. * @return void
  462. * @author wj
  463. * @date 2023-08-14
  464. */
  465. public function getdata($data, $command, $infoarr)
  466. {
  467. $info_content = $infoarr['content'];
  468. foreach (array_keys($info_content) as $key => $value) {
  469. if (empty($info_content[$value])) {
  470. if (isset($data[$key])) {
  471. $info_content[$value] = $data[$key];
  472. }
  473. }
  474. }
  475. if (isset($info_content['time'])) {
  476. $time = $info_content['time'];
  477. $info_content['time'] = $this->gettime($time);
  478. }
  479. if (isset($info_content['date'])) {
  480. $date = $info_content['date'];
  481. $info_content['date'] = $this->getdate($date);
  482. }
  483. $infoarr['info_content'] = $info_content;
  484. return $infoarr;
  485. }
  486. /**
  487. * 保存接收信息队列
  488. *
  489. * @param [type] $data
  490. * @return void
  491. * @author wj
  492. * @date 2023-08-14
  493. */
  494. public function savereceivequeue($data)
  495. {
  496. $m_srq = new ShoneReceiveQueueModel();
  497. $data = [
  498. 'msg' => $data,
  499. 'createtime' => date('Y-m-d H:i:s'),
  500. ];
  501. $id = $m_srq->insertData($data);
  502. Log::write('id:' . $id, 'shouhuan');
  503. if (empty($id)) {
  504. return false;
  505. }
  506. return true;
  507. }
  508. /**
  509. * 保存手环信息
  510. *
  511. * @return void
  512. * @author wj
  513. * @date 2023-08-14
  514. */
  515. public function saveshinfo($facility_id, $device_id_code, $data, $original_str)
  516. {
  517. $command = $data[0];
  518. $infoarr = $this->gettsendcommandinfo($command);
  519. if (!$infoarr) {
  520. throw new \Exception("无对应命令数据2:" . $command);
  521. }
  522. $data = $this->getdata($data, $data[0], $infoarr);
  523. $m_sri = new ShoneReceiveInfoModel();
  524. $m_srir = new ShoneReceiveInfoRecode();
  525. $data = $data['info_content'];
  526. $data['facility_id'] = $facility_id;
  527. $data['device_id_code'] = $device_id_code;
  528. //$m_sri处理
  529. $sriwhere = [
  530. 'facility_id' => $facility_id,
  531. 'device_id_code' => $device_id_code,
  532. ];
  533. $sriinfo = $m_sri->getInfo($sriwhere);
  534. unset($data['command']);
  535. if (empty($sriinfo)) {
  536. $sriinsertData = $data;
  537. $sriinsertData['createtime'] = date('Y-m-d H:i:s');
  538. $sriid = $m_sri->insertData($sriinsertData);
  539. if (empty($sriid)) {
  540. throw new \Exception("设备信息添加失败:" . $device_id_code);
  541. }
  542. } else {
  543. unset($data['device_id_code']);
  544. unset($data['facility_id']);
  545. $sriid = $sriinfo['id'];
  546. $sriupdateData = $data;
  547. $sriupdateData['updatetime'] = date('Y-m-d H:i:s');
  548. $row = $m_sri->updateinfo(['id' => $sriid], $sriupdateData);
  549. if (empty($row)) {
  550. throw new \Exception("设备信息修改失败:" . $device_id_code);
  551. }
  552. }
  553. //m_srir处理
  554. $data['original_str'] = $original_str;
  555. $sririnsertData = $data;
  556. $sririnsertData['facility_id'] = $facility_id;
  557. $sririnsertData['device_id_code'] = $device_id_code;
  558. $sririnsertData['createtime'] = date('Y-m-d H:i:s');
  559. $sririd = $m_srir->insertData($sririnsertData);
  560. if (empty($sririd)) {
  561. throw new \Exception("设备历史信息添加失败:" . $device_id_code);
  562. }
  563. }
  564. /**
  565. * 获取接收信息队列列表
  566. *
  567. * @param [type] $page
  568. * @param [type] $size
  569. * @return void
  570. * @author wj
  571. * @date 2023-08-14
  572. */
  573. public function getreceivequeuelist($page = null, $size = null)
  574. {
  575. $m_srq = new ShoneReceiveQueueModel();
  576. $where = ['status' => 0];
  577. $size = empty($size) ? 20 : $size;
  578. if (empty($page)) {
  579. $count = $m_srq->getList($where, 'count');
  580. $totalpage = ceil($count / $size);
  581. $data = ['totalpage' => $totalpage, 'size' => $size];
  582. return $data;
  583. } else {
  584. $list = $m_srq->getList($where, '*', $page, $size, 'id asc');
  585. if (empty($list)) {
  586. Log::write("手环接收信息队列-无数据", 'shouhuan');
  587. return false;
  588. }
  589. $list = $list->toArray();
  590. $ids = array_column($list, 'id');
  591. $updatecount = $m_srq->updateinfo(['id' => ['in', $ids], 'status' => 0], ['status' => 1]);
  592. if ($updatecount != count($ids)) {
  593. Log::write("手环接收信息队列-部分未修改", 'shouhuan');
  594. Log::write("count:" . count($ids) . " update count:" . $updatecount, 'shouhuan');
  595. }
  596. if (empty($updatecount)) {
  597. Log::write("手环接收信息队列-无修改数据", 'shouhuan');
  598. return false;
  599. }
  600. return $list;
  601. }
  602. }
  603. /**
  604. * 获取发送信息队列列表
  605. *
  606. * @param [type] $page
  607. * @param [type] $size
  608. * @return void
  609. * @author wj
  610. * @date 2023-08-14
  611. */
  612. public function getsendqueuelist($device_id_code, $page = null, $size = null)
  613. {
  614. $m_ssq = new ShoneSendQueueModel();
  615. $where = ['status' => 0, 'device_id_code' => $device_id_code];
  616. $size = empty($size) ? 20 : $size;
  617. if (empty($page)) {
  618. $count = $m_ssq->getList($where, 'count');
  619. $totalpage = ceil($count / $size);
  620. $data = ['totalpage' => $totalpage, 'size' => $size];
  621. return $data;
  622. } else {
  623. $list = $m_ssq->getList($where, '*', $page, $size, 'id asc,weight desc');
  624. if (empty($list)) {
  625. Log::write("手环发送信息队列-无数据", 'shouhuan');
  626. return false;
  627. }
  628. $list = $list->toArray();
  629. $ids = array_column($list, 'id');
  630. $updatecount = $m_ssq->updateinfo(['id' => ['in', $ids], 'status' => 0], ['status' => 1]);
  631. if ($updatecount != count($ids)) {
  632. Log::write("手环发送信息队列-部分未修改", 'shouhuan');
  633. Log::write("count:" . count($ids) . " update count:" . $updatecount, 'shouhuan');
  634. }
  635. if (empty($updatecount)) {
  636. Log::write("手环发送信息队列-无修改数据", 'shouhuan');
  637. return false;
  638. }
  639. return $list;
  640. }
  641. }
  642. public function sendmsgsuccess($item)
  643. {
  644. $m_ssq = new ShoneSendQueueModel();
  645. $m_ssl = new ShoneSendListModel();
  646. $ssqid = $item['id'];
  647. $list_id = $item['list_id'];
  648. $sslwhere = ['id' => $list_id, 'is_send' => 0];
  649. $sslinfo = $m_ssl->getInfo($sslwhere);
  650. if ($sslinfo) {
  651. $row = $m_ssl->updateinfo(['id' => $sslinfo['id']], ['is_send' => 1, 'send_time' => date('Y-m-d H:i:s')]);
  652. }
  653. $ssqwhere = ['id' => $ssqid];
  654. $ssqinfo = $m_ssq->getInfo($ssqwhere);
  655. if ($ssqinfo) {
  656. $m_ssq->deleteinfobyid($ssqid);
  657. }
  658. }
  659. public function receivemsgsuccess($item)
  660. {
  661. $m_srq = new ShoneReceiveQueueModel();
  662. $srqid = $item['id'];
  663. $srqwhere = ['id' => $srqid, 'status' => 1];
  664. $srqinfo = $m_srq->getInfo($srqwhere);
  665. if ($srqinfo) {
  666. $m_srq->deleteinfobyid($srqid);
  667. }
  668. }
  669. /**
  670. * 日期解析
  671. *
  672. * @return void
  673. * @author wj
  674. * @date 2023-08-15
  675. */
  676. public function getdate($date)
  677. {
  678. $day = substr($date, 0, 2);
  679. $month = substr($date, 2, 2);
  680. $year = substr($date, 4, 2);
  681. $year1 = date('Y');
  682. $year1 = substr($year1, 0, 2);
  683. $year = $year1 . $year;
  684. $day = $year . '-' . $month . '-' . $day;
  685. return $day;
  686. }
  687. public function gettime($time)
  688. {
  689. $hour = substr($time, 0, 2);
  690. $minute = substr($time, 2, 2);
  691. $second = substr($time, 4, 2);
  692. $time = $hour . ':' . $minute . ':' . $second;
  693. return $time;
  694. }
  695. /**
  696. * 初始化手环接收信息解析
  697. *
  698. * @return void
  699. * @author wj
  700. * @date 2023-08-15
  701. */
  702. public function initanalysisShoneReceiveMsg()
  703. {
  704. $m_srq = new ShoneReceiveQueueModel();
  705. $where = ['status' => 1];
  706. $m_srq->updateinfo($where, ['status' => 0]);
  707. }
  708. /**
  709. * 拆包
  710. *
  711. * @return void
  712. * @author wj
  713. * @date 2023-08-15
  714. */
  715. public function unpack($data)
  716. {
  717. $arr = explode("][", $data);
  718. foreach ($arr as $key => $value) {
  719. $regex = "/^[^[].*$/";
  720. preg_match($regex, $value, $mc0);
  721. $regex = "/^.*[^]]$/";
  722. preg_match($regex, $value, $mc1);
  723. if ($mc0) {
  724. $arr[$key] = '[' . $value;
  725. }
  726. if ($mc1) {
  727. $arr[$key] = $value . "]";
  728. }
  729. }
  730. return $arr;
  731. }
  732. }