ProtoCmdLine.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Jiaruan;
  3. class ProtoCmdLine {
  4. public function proc( $req, $connmgr ){
  5. //检查签名
  6. if($req->sign != $this->sign_req($req) ) {
  7. log_error('check sign failed ' . json_encode($req));
  8. return $this->create_resp($req, false, "检查签名失败");
  9. }
  10. //生成下发基站的命令
  11. $cmd = $this->create_cmd($req);
  12. //下发命令给单个基站
  13. $result = $connmgr->send_one($req->station_number,$cmd);
  14. return $this->create_resp($req, $result['success'], $result['message']);
  15. }
  16. public function create_cmd( $req ){
  17. $config = array(
  18. "subtype" => 1,
  19. "cmd" => $req->cmdline,
  20. );
  21. $cmd = array(
  22. 'type' => 4,
  23. 'mac' => '??', //?? 表示由连接管理池发送时自动填充
  24. 'msgid' => 0,
  25. 'num' => 1,
  26. 'config' => array($config),
  27. );
  28. return $cmd;
  29. }
  30. public function create_resp( $req, $isSuccess, $message ){
  31. $resp = array(
  32. 'success' => $isSuccess,
  33. 'message' => $message
  34. );
  35. return $resp;
  36. }
  37. public function sign_req( $req ){
  38. $str = $req->type;
  39. $str.= $req->cityid;
  40. $str.= $req->station_number;
  41. $str.= $req->cmdline;
  42. $str.= C('协议签名密钥');
  43. return strtoupper(md5(urlencode($str)));
  44. }
  45. }