12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Mead
- * Date: 2019/9/3
- * Time: 8:05 PM
- */
- namespace App\Servers;
- class BoxStatusChangeServer extends BaseServer
- {
- public function main($body)
- {
- $data = $this->decode($body);
- self::log($data, 'BoxStatusChangeServer', self::$LOG_MAJOR);
- return $this->response();
- }
- const RESPONSE_SUCCESS = '01';
- const RESPONSE_FAIL = '00';
- protected function response($response_status = self::RESPONSE_SUCCESS)
- {
- $body = [
- $response_status
- ];
- $body = str_split(implode('', $body), 2);
- return $body;
- }
- /**
- * 解析装载的数据
- * @param $body
- * @return array
- * User: Mead
- */
- private function decode($body)
- {
- $i = 0;
- $box_no = self::stitching($body, $i, 5);
- $i += 5;
- $time = self::stitching($body, $i, 4);
- $i += 4;
- // 状态类型
- $status_type = self::stitching($body, $i, 1);
- $i += 1;
- // 状态值长度
- $status_length = self::stitching($body, $i, 1);
- $i += 1;
- //MsgId
- $status = self::stitching($body, $i);
- // 处理数据
- $box_no = $this->decodeBoxNo($box_no);
- $time = $this->decodeTime($time);
- return [
- 'box_no' => $box_no,
- 'time' => $time,
- 'status_type' => $status_type,
- 'status_length' => $status_length,
- 'status' => $status,
- ];
- }
- }
|