NewBikeReportingServer.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. use App\Maps\VideoMap;
  10. class NewBikeReportingServer extends BaseServer
  11. {
  12. public function main($body)
  13. {
  14. $data = $this->decode($body);
  15. self::log($data, 'NewBikeReportingServer', self::$LOG_MAJOR);
  16. return $this->response(self::RESPONSE_SUCCESS, VideoMap::VIDEO_FIND_BIKE);
  17. }
  18. const RESPONSE_SUCCESS = '00';
  19. const RESPONSE_FAI = '01';
  20. /**
  21. * 响应
  22. * @param string $response_status
  23. * @param bool $video_cmd
  24. * @return array
  25. * User: Mead
  26. */
  27. protected function response($response_status = self::RESPONSE_SUCCESS, $video_cmd = false)
  28. {
  29. $body = [
  30. $response_status,
  31. '00' . $video_cmd
  32. ];
  33. $body = str_split(implode('', $body), 2);
  34. return $body;
  35. }
  36. /**
  37. * 解析装载的数据
  38. * @param $body
  39. * @return array
  40. * User: Mead
  41. */
  42. private function decode($body)
  43. {
  44. $i = 0;
  45. // 时间
  46. $time = self::stitching($body, $i, 4);
  47. $i += 4;
  48. // 执行结果
  49. $result = self::stitching($body, $i, 1);
  50. $i += 1;
  51. // 提示音指令
  52. $voice_cmd = self::stitching($body, $i, 2);
  53. $i += 2;
  54. //MsgId
  55. $msg_id = self::stitching($body, $i);
  56. $time = $this->decodeTime($time);
  57. return [
  58. 'time' => $time,
  59. 'result' => $result,
  60. 'voice_cmd' => $voice_cmd,
  61. 'msg_id' => $msg_id,
  62. ];
  63. }
  64. }