123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Mead
- * Date: 2019/9/3
- * Time: 8:05 PM
- */
- namespace App\Servers;
- use App\Maps\VideoMap;
- class NewBikeReportingServer extends BaseServer
- {
- public function main($body)
- {
- $data = $this->decode($body);
- self::log($data, 'NewBikeReportingServer', self::$LOG_MAJOR);
- return $this->response(self::RESPONSE_SUCCESS, VideoMap::VIDEO_FIND_BIKE);
- }
- const RESPONSE_SUCCESS = '00';
- const RESPONSE_FAI = '01';
- /**
- * 响应
- * @param string $response_status
- * @param bool $video_cmd
- * @return array
- * User: Mead
- */
- protected function response($response_status = self::RESPONSE_SUCCESS, $video_cmd = false)
- {
- $body = [
- $response_status,
- '00' . $video_cmd
- ];
- $body = str_split(implode('', $body), 2);
- return $body;
- }
- /**
- * 解析装载的数据
- * @param $body
- * @return array
- * User: Mead
- */
- private function decode($body)
- {
- $i = 0;
- // 时间
- $time = self::stitching($body, $i, 4);
- $i += 4;
- // 执行结果
- $result = self::stitching($body, $i, 1);
- $i += 1;
- // 提示音指令
- $voice_cmd = self::stitching($body, $i, 2);
- $i += 2;
- //MsgId
- $msg_id = self::stitching($body, $i);
- $time = $this->decodeTime($time);
- return [
- 'time' => $time,
- 'result' => $result,
- 'voice_cmd' => $voice_cmd,
- 'msg_id' => $msg_id,
- ];
- }
- }
|