BoxStatusChangeServer.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Mead
  5. * Date: 2019/9/3
  6. * Time: 8:05 PM
  7. */
  8. namespace App\Servers;
  9. class BoxStatusChangeServer extends BaseServer
  10. {
  11. public function main($body)
  12. {
  13. $data = $this->decode($body);
  14. self::log($data, 'BoxStatusChangeServer', self::$LOG_MAJOR);
  15. return $this->response();
  16. }
  17. const RESPONSE_SUCCESS = '01';
  18. const RESPONSE_FAIL = '00';
  19. protected function response($response_status = self::RESPONSE_SUCCESS)
  20. {
  21. $body = [
  22. $response_status
  23. ];
  24. $body = str_split(implode('', $body), 2);
  25. return $body;
  26. }
  27. /**
  28. * 解析装载的数据
  29. * @param $body
  30. * @return array
  31. * User: Mead
  32. */
  33. private function decode($body)
  34. {
  35. $i = 0;
  36. $box_no = self::stitching($body, $i, 5);
  37. $i += 5;
  38. $time = self::stitching($body, $i, 4);
  39. $i += 4;
  40. // 状态类型
  41. $status_type = self::stitching($body, $i, 1);
  42. $i += 1;
  43. // 状态值长度
  44. $status_length = self::stitching($body, $i, 1);
  45. $i += 1;
  46. //MsgId
  47. $status = self::stitching($body, $i);
  48. // 处理数据
  49. $box_no = $this->decodeBoxNo($box_no);
  50. $time = $this->decodeTime($time);
  51. return [
  52. 'box_no' => $box_no,
  53. 'time' => $time,
  54. 'status_type' => $status_type,
  55. 'status_length' => $status_length,
  56. 'status' => $status,
  57. ];
  58. }
  59. }