RemoteCmdServer.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 RemoteCmdServer extends BaseServer
  10. {
  11. public function main($body)
  12. {
  13. $data = $this->decode($body);
  14. self::log($data, 'RemoteCmdServer', self::$LOG_MAJOR);
  15. if ($data['result'] === '02') {
  16. // //运动中
  17. self::log($data['msgId']['no'], 'REMOTECMD_LOSE', self::$LOG_COMMON);
  18. BikeControl::outAreaLoseElectric($data['msgId']['no']);
  19. sleep(1);
  20. switch ($data['msgId']['cmd']) {
  21. case BikeControl::CONTROL_REMOTE_CLOSE_LOCK:
  22. //关锁处理
  23. BikeControl::closeLock($data['msgId']['no']);
  24. break;
  25. case BikeControl::CONTROL_REMOTE_TEMPORARY_CLOSE_LOCK:
  26. //临时锁车处理
  27. BikeControl::temporaryCloseLock($data['msgId']['no']);
  28. break;
  29. }
  30. }
  31. return $this->response(self::RESULT_SUCCESS);
  32. }
  33. // 登录成功
  34. const RESULT_SUCCESS = '01';
  35. // 登录失败
  36. const RESULT_FAIL = '00';
  37. /**
  38. * 登录响应
  39. * @param $login_type
  40. * @return array
  41. * User: Mead
  42. */
  43. public function response($result_type = '01')
  44. {
  45. $body = [
  46. $result_type,
  47. ];
  48. return $body;
  49. }
  50. /**
  51. * 解析装载的登录数据
  52. * @param $body
  53. * @return array
  54. * User: Mead
  55. */
  56. private function decode($body)
  57. {
  58. $i = 0;
  59. $result = self::stitching($body, $i, 1);
  60. $i += 1;
  61. //标识符
  62. $i += 2;
  63. $msgId = self::stitching($body, $i);
  64. $msgId = $this->decodeMsgId($msgId);
  65. return [
  66. 'result' => $result,
  67. 'msgId' => $msgId
  68. ];
  69. }
  70. }