wang jun 1 ano atrás
pai
commit
8fc05b2f77

+ 4 - 2
application/common/server/ShouhuanCommand.php

@@ -65,7 +65,8 @@ class ShouhuanCommand
         $config = $infoarr;
 
         $m_ssl = new ShsendlistModel();
-        $commandxy = "3G";
+        //$commandxy = "3G";
+        $commandxy = "DW";
         //仅创建
         if ($command == 'AL') {
             $msg_type = 1;
@@ -146,7 +147,8 @@ class ShouhuanCommand
     {
         $command = $data['command'];
         $infoarr = $this->getsendcommandinfo($command);
-        $commandxy = "3G";
+        //$commandxy = "3G";
+        $commandxy = "DW";
         if (!$infoarr) {
             // Log::write("无对应命令数据1:" . $command, 'shouhuan');
             // Log::write($data, 'shouhuan');

+ 28 - 6
application/common/server/SouhuanAnalysis.php

@@ -2,6 +2,7 @@
 
 namespace app\common\server;
 
+use app\common\model\Devicelistmodel;
 use app\common\model\FacilityModel;
 use app\common\model\ShalarmlistModel;
 use app\common\model\ShinfoModel;
@@ -117,6 +118,7 @@ class SouhuanAnalysis
      */
     public function getmacforUD($str, $device_id_code)
     {
+        Log::write($str, 'shouhuan');
         $data = explode(",", $str);
         $is_gps = $data[3];
         $is_success = false;
@@ -168,15 +170,23 @@ class SouhuanAnalysis
             $macs = join("|", $macs_arr);
             $accesstype = 1;
             $url = "http://apilocate.amap.com/position?macs=" . $macs . "&bts=" . $bts . "&nearbts=" . $nearbts . "&network=GSM&cdma=0&accesstype=" . $accesstype . "&output=json&key=" . $apikey;
+            Log::write($url, 'shouhuan');
             $result = curl_request($url);
+            Log::write($result, 'shouhuan');
             if ('10000' === $result['infocode']) {
                 $resultdata = $result['result'];
-                $locations = explode(",", $resultdata['location']);
-                $use_gps_long = $locations[0];
-                $use_gps_lat = $locations[1];
-                $address_desc = $resultdata['desc'];
-                $accesstype = 2;
-                $is_success = true;
+                if (isset($resultdata['location'])) {
+                    $locations = explode(",", $resultdata['location']);
+                    $use_gps_long = $locations[0];
+                    $use_gps_lat = $locations[1];
+                    $address_desc = $resultdata['desc'];
+                    $accesstype = 2;
+                    $is_success = true;
+                }else{
+                    Log::write($url, 'shouhuan');
+                    Log::write($result, 'shouhuan');
+                    $accesstype = -2; 
+                }
             } else {
                 Log::write($url, 'shouhuan');
                 Log::write($result, 'shouhuan');
@@ -189,10 +199,14 @@ class SouhuanAnalysis
             $gps_str = $use_gps_long . "," . $use_gps_lat;
             $url = "https://restapi.amap.com/v3/assistant/coordinate/convert?locations=" . $gps_str . "&coordsys=gps&output=JSON&key=" . $apikey;
             $result = curl_request($url);
+            Log::write($url, 'shouhuan');
+            Log::write($result, 'shouhuan');
             if ('10000' == $result['infocode']) {
                 $locations = $result['locations'];
                 $url = "https://restapi.amap.com/v3/geocode/regeo?location=" . $locations . "&key=" . $apikey;
                 $result = curl_request($url);
+                Log::write($url, 'shouhuan');
+                Log::write($result, 'shouhuan');
                 if ('10000' == $result['infocode']) {
                     $address_desc = $result['regeocode']['formatted_address'];
                     $is_success = true;
@@ -846,6 +860,14 @@ 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;

+ 15 - 8
application/workerman/ShTcp.php

@@ -14,7 +14,7 @@ class ShTcp extends Server
 
     protected function init()
     {
-        $this->count = 4; //线程数
+        $this->count = 10; //线程数
     }
 
     public function onConnect($connection)
@@ -74,16 +74,19 @@ class ShTcp extends Server
                         $command = $linedata['command'];
                         $content = $linedata['content_arr'];
                         $fid = $server_sa->getfacilityid($device_id_code);
-                        $result = $server_sa->saveshinfo($fid, $device_id_code, $linedata, $value);
                         $config = $linedata['config'];
-                        if ($result && 'tsend' == $config['kind']) {
-                            $data = $server_sc->createsendmsg($fid, $device_id_code, $linedata);
+                        if ($config) {
+                            $result = $server_sa->saveshinfo($fid, $device_id_code, $linedata, $value);
+                            if ($result && 'tsend' == $config['kind']) {
+                                $data = $server_sc->createsendmsg($fid, $device_id_code, $linedata);
+                            }
                         }
                         $server_sa->receivemsgsuccess($value);
                     } catch (\Exception $e) {
                         $msg = $e->getMessage();
                         echo $msg . "\n";
                         Log::write($msg, 'shouhuan');
+                        Log::write($e->getTraceAsString(), 'shouhuan');
                     }
                 }
             }
@@ -117,12 +120,16 @@ class ShTcp extends Server
         $datas = (array) $server_sa->unpack($data);
         foreach ($datas as $key => $data) {
             //测试
-            echo "onmessage receive msg:" . $data . "\n";
+            echo "[" . date('Y-m-d H:i:s') . "] onmessage receive msg:" . $data . "\n";
             //$server_sa->showfortest($data);
             try {
                 //$device_id_code = $server_sa->getline($data, 'device_id_code');
                 $lineinfo = $server_sa->getline($data);
                 $device_id_code = $lineinfo['device_id_code'];
+
+                //设置上线
+                $server_sa->setonlineinfo($device_id_code);
+
                 if ($lineinfo['config']) {
                     $result = $server_sa->savereceivequeue($data, $device_id_code);
                     if (empty($result)) {
@@ -130,6 +137,7 @@ class ShTcp extends Server
                     }
                 }
                 $command = $lineinfo['command'];
+
                 //回复消息
                 $fid = $server_sa->getfacilityid($device_id_code);
                 $sendmsg = $server_sc->createsendmsg2($fid, $device_id_code, $lineinfo);
@@ -138,9 +146,8 @@ class ShTcp extends Server
                 } else {
                     $sendmsg = 'NULL';
                 }
-                echo "onmessage send:" . $sendmsg . "\n";
-                //设置上线
-                $server_sa->setonlineinfo($device_id_code);
+                echo "[" . date('Y-m-d H:i:s') . "] onmessage send:" . $sendmsg . "\n";
+
                 $this->device_id_code = $device_id_code;
                 //测试
                 //$this->device_id_code = "358800006072996";