wang jun 1 year ago
parent
commit
fb19e72a36

+ 99 - 42
application/common/server/ShouhuanCommand.php

@@ -72,12 +72,12 @@ class ShouhuanCommand
         } else {
             $msg_type = 0;
         }
-        if ('back' == $config['kind']) {
-            $content = $config['content'];
-            $content = implode(',', $content);
-            $send_type = 0;
-            $is_success = 1;
-        }
+        // if ('back' == $config['kind']) {
+        //     $content = $config['content'];
+        //     $content = implode(',', $content);
+        //     $send_type = 0;
+        //     $is_success = 1;
+        // }
         if ('send' == $config['kind']) {
             $content = $config['content'];
             $useconmmand = $content['command'];
@@ -100,45 +100,90 @@ class ShouhuanCommand
                 $is_success = 1;
             }
 
+            $weight = $this->getsendweight($command);
+            $msgdata = [
+                0 => $commandxy,
+                'device_id_code' => $device_id_code,
+                'len' => str_pad(strtoupper(dechex(mb_strlen($content))), 4, "0", STR_PAD_LEFT),
+                'content' => $content,
+            ];
+            $msg = '[' . implode('*', $msgdata) . ']';
+            $sslInsertData = [
+                'facility_id' => $facility_id,
+                'device_id_code' => $device_id_code,
+                'command' => $command,
+                'send_msg' => $msg,
+                'send_weight' => $weight,
+                'send_time' => date('Y-m-d H:i:s'),
+                'is_success' => $is_success,
+                'send_type' => $send_type,
+                'sys_user_id' => $sys_user_id,
+            ];
+            $sslid = $m_ssl->insertData($sslInsertData);
+            if (empty($sslid)) {
+                throw new \Exception("发送数据添加失败");
+            }
+            $data = [
+                'msg' => $msg,
+                'weight' => $weight,
+                'createtime' => date('Y-m-d H:i:s'),
+                'facility_id' => $facility_id,
+                'device_id_code' => $device_id_code,
+                'send_list_id' => $sslid,
+                'msg_type' => $msg_type,
+            ];
+            $m_ssq = new ShsendqueueModel();
+            $id = $m_ssq->insertData($data);
+            if (empty($id)) {
+                throw new \Exception("发送队列数据添加失败");
+            }
+            return true;
         }
-        $weight = $this->getsendweight($command);
-        $msgdata = [
-            0 => $commandxy,
-            'device_id_code' => $device_id_code,
-            'len' => str_pad(strtoupper(dechex(mb_strlen($content))), 4, "0", STR_PAD_LEFT),
-            'content' => $content,
-        ];
-        $msg = '[' . implode('*', $msgdata) . ']';
-        $sslInsertData = [
-            'facility_id' => $facility_id,
-            'device_id_code' => $device_id_code,
-            'command' => $command,
-            'send_msg' => $msg,
-            'send_weight' => $weight,
-            'send_time' => date('Y-m-d H:i:s'),
-            'is_success' => $is_success,
-            'send_type' => $send_type,
-            'sys_user_id' => $sys_user_id,
-        ];
-        $sslid = $m_ssl->insertData($sslInsertData);
-        if (empty($sslid)) {
-            throw new \Exception("发送数据添加失败");
+        return false;
+    }
+
+    public function createsendmsg2($facility_id, $device_id_code, $data)
+    {
+        $command = $data['command'];
+        $infoarr = $this->getsendcommandinfo($command);
+        if (!$infoarr) {
+            // Log::write("无对应命令数据1:" . $command, 'shouhuan');
+            // Log::write($data, 'shouhuan');
+            return false;
         }
-        $data = [
-            'msg' => $msg,
-            'weight' => $weight,
-            'createtime' => date('Y-m-d H:i:s'),
-            'facility_id' => $facility_id,
-            'device_id_code' => $device_id_code,
-            'send_list_id' => $sslid,
-            'msg_type' => $msg_type,
-        ];
-        $m_ssq = new ShsendqueueModel();
-        $id = $m_ssq->insertData($data);
-        if (empty($id)) {
-            throw new \Exception("发送队列数据添加失败");
+        $content_arr = $data['content_arr'];
+        $config = $infoarr;
+
+        $m_ssl = new ShsendlistModel();
+        $commandxy = "3G";
+        if ('back' == $config['kind']) {
+            $content = $infoarr['command'];
+            $weight = $this->getsendweight($command);
+            $msgdata = [
+                0 => $commandxy,
+                'device_id_code' => $device_id_code,
+                'len' => str_pad(strtoupper(dechex(mb_strlen($content))), 4, "0", STR_PAD_LEFT),
+                'content' => $content,
+            ];
+            $msg = '[' . implode('*', $msgdata) . ']';
+            $sslInsertData = [
+                'facility_id' => $facility_id,
+                'device_id_code' => $device_id_code,
+                'command' => $command,
+                'send_msg' => $msg,
+                'send_weight' => $weight,
+                'send_time' => date('Y-m-d H:i:s'),
+                'is_success' => 1,
+                'send_type' => 0,
+                'sys_user_id' => 0,
+            ];
+            $sslid = $m_ssl->insertData($sslInsertData);
+            if (empty($sslid)) {
+                throw new \Exception("发送数据添加失败");
+            }
+            return $msg;
         }
-        return true;
+        return false;
     }
     /**
      * 获取回复权重
@@ -464,6 +509,18 @@ class ShouhuanCommand
                 ],
                 'kind' => 'back',
             ],
+            'TKQ' => [
+                'content' => [
+                    'command' => 'TKQ',
+                ],
+                'kind' => 'back',
+            ],
+            'WG' => [
+                'content' => [
+                    'command' => 'WG',
+                ],
+                'kind' => 'back',
+            ],
         ];
         if (!isset($data[$command])) {
             return false;

+ 21 - 12
application/common/server/SouhuanAnalysis.php

@@ -2,7 +2,6 @@
 
 namespace app\common\server;
 
-use app\common\model\Devicelistmodel;
 use app\common\model\FacilityModel;
 use app\common\model\ShalarmlistModel;
 use app\common\model\ShinfoModel;
@@ -97,10 +96,11 @@ class SouhuanAnalysis
             if (!$config) {
                 $errmsg = '命令无解析配置 command:' . $command;
                 Log::write($errmsg, 'shouhuan');
-                return false;
+                //return false;
+            } else {
+                $data['config'] = [];
             }
         }
-
         if (isset($field)) {
             return $data[$field];
         }
@@ -220,7 +220,6 @@ class SouhuanAnalysis
         ];
         return $data;
     }
-
     /**
      * 内容解析
      *
@@ -373,6 +372,24 @@ class SouhuanAnalysis
                 'need_back' => 1,
                 'command' => 'oxygen',
             ],
+            'TKQ' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tsend',
+                'need_back' => 1,
+            ],
+            'TKQ' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tsend',
+                'need_back' => 1,
+            ],
+            'WG' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tsend',
+                'need_back' => 1,
+            ],
             //终端回复
             //ZONE UPLOAD CR SLEEPTIME FALLDOWN FACTORY SOS VERNO LOWBAT
             //POWEROFF LSSET PEDO PHL REMIND SILENCETIME2 BOOTOFF REMOVE
@@ -828,14 +845,6 @@ class SouhuanAnalysis
             $data['shinfo_id'] = $sshinfo_id;
             $data['facility_id'] = $facility_id;
             $data['createtime'] = date('Y-m-d H:i:s');
-            $result = $this->getmacforUD($original_str, $device_id_code);
-            $data['use_gps_long'] = $result['use_gps_long'];
-            $data['use_gps_lat'] = $result['use_gps_lat'];
-            $data['location'] = $result['address_desc'];
-            $m_dl = new Devicelistmodel();
-            $uid = $m_dl->getuidbydeviceid($device_id_code);
-            $uid = empty($uid) ? 0 : $uid;
-            $data['user_id'] = $uid;
             $said = $m_sa->insertData($data);
             if (empty($said)) {
                 $msg = "报警信息添加失败:" . $original_str;

+ 24 - 10
application/workerman/ShTcp.php

@@ -32,7 +32,8 @@ class ShTcp extends Server
             if (isset($worker->device_id_code)) {
                 $device_id_code = $worker->device_id_code;
                 foreach ($worker->connections as $connection) {
-                    $info = $server_sa->getsendqueuelist($device_id_code);
+                    $size = 500;
+                    $info = $server_sa->getsendqueuelist($device_id_code, null, $size);
                     $totalpage = $info['totalpage'];
                     if ($totalpage > 0) {
                         $size = $info['size'];
@@ -40,6 +41,7 @@ class ShTcp extends Server
                             $list = $server_sa->getsendqueuelist($device_id_code, 1, $size);
                             $list = (array) $list;
                             foreach ($list as $key => $value) {
+                                echo 'send:' . $value['id'] . "-" . $value['msg'] . "\n";
                                 $connection->send($value['msg']);
                                 $server_sa->showfortest($value['msg']);
                                 $server_sa->sendmsgsuccess($value);
@@ -53,7 +55,7 @@ class ShTcp extends Server
         $server_sa->initanalysisShoneReceiveMsg();
         Timer::add(10, function () use ($worker, $server_sa, $server_sc) {
             $page = 1;
-            $size = 30;
+            $size = 500;
             $list = $server_sa->getreceivequeuelist($page, $size);
             if ($list) {
                 $list = (array) $list;
@@ -111,20 +113,32 @@ class ShTcp extends Server
     {
         Log::write($data, 'shouhuan');
         $server_sa = new SouhuanAnalysis();
+        $server_sc = new ShouhuanCommand();
         $datas = (array) $server_sa->unpack($data);
         foreach ($datas as $key => $data) {
             //测试
-            $server_sa->showfortest($data);
+            echo "onmessage receive msg:" . $data . "\n";
+            //$server_sa->showfortest($data);
             try {
-                $device_id_code = $server_sa->getline($data, 'device_id_code');
-                if (!$device_id_code) {
-                    Log::write('不可解析_onMessage:' . $data, 'shouhuan');
-                    continue;
+                //$device_id_code = $server_sa->getline($data, 'device_id_code');
+                $lineinfo = $server_sa->getline($data);
+                $device_id_code = $lineinfo['device_id_code'];
+                if ($lineinfo['config']) {
+                    $result = $server_sa->savereceivequeue($data, $lineinfo);
+                    if (empty($result)) {
+                        Log::write("手环接收信息队列,数据保存失败", 'shouhuan');
+                    }
                 }
-                $result = $server_sa->savereceivequeue($data, $device_id_code);
-                if (empty($result)) {
-                    Log::write("手环接收信息队列,数据保存失败", 'shouhuan');
+                $command = $lineinfo['command'];
+                //回复消息
+                $fid = $server_sa->getfacilityid($device_id_code);
+                $sendmsg = $server_sc->createsendmsg2($fid, $device_id_code, $lineinfo);
+                if ($sendmsg) {
+                    $connection->send($sendmsg);
+                } else {
+                    $sendmsg = 'NULL';
                 }
+                echo "onmessage send:" . $sendmsg . "\n";
                 //设置上线
                 $server_sa->setonlineinfo($device_id_code);
                 $this->device_id_code = $device_id_code;