<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          記錄TP5監(jiān)聽GPS設(shè)備協(xié)議的方法

          共 10574字,需瀏覽 22分鐘

           ·

          2021-06-05 12:02

          新建/application/server/controller/Server.php文件


          <?php

          namespace app\server\controller;use Workerman\Worker;use Workerman\Lib\Timer;use Workerman\Connection\AsyncTcpConnection;use think\Db;class Server { private $connections; private $connection_to_ws; public function index() { $socket = new Worker('websocket://0.0.0.0:2346'); // 設(shè)置transport開啟ssl,websocket+ssl即wss //$socket->transport = 'ssl'; // 啟動(dòng)1個(gè)進(jìn)程對(duì)外提供服務(wù) $socket->count = 1; //給這個(gè)進(jìn)程設(shè)置一個(gè)array() //$socket->connections = array(); // 當(dāng)有客戶端連接時(shí) $socket->onConnect = function ($connection) { $this->connections[$connection->id] = $connection; }; // 當(dāng)有客戶端連接時(shí) $socket->onMessage = function ($connection, $data) { // $this->connection_to_ws = new AsyncTcpConnection('tcp://101.32.206.28:8018'); // $this->connection_to_ws->connect(); // $this->connection_to_ws->send($data); // $this->connections[$connection->id]=$connection; }; // 當(dāng)有客戶端連接斷開時(shí) $socket->onClose = function ($connection) { if (isset($connection->id)) { // 連接斷開時(shí)刪除映射 //unset($this->connections[$connection->id]); } }; $socket->onError = function ($connection, $code, $msg) { echo "error $code $msg\n"; }; $tcp = new Worker('tcp://0.0.0.0:8018'); $tcp->onMessage = function ($connection, $data) { //var_dump($connection); // if(is_null($this->connection_to_ws)) { // $this->connection_to_ws = new AsyncTcpConnection('ws://101.32.206.28:2346'); // $this->connection_to_ws->connect(); // } // $this->connection_to_ws->send($data); if (strpos($data, 'BR00') !== false) { $data = str_replace(array( '(', ')' ) , '', $data); $where['macid'] = substr($data, 0, strpos($data, 'BR00')); $result = substr($data, strrpos($data, "BR00") + 4); $where['ymd'] = substr($result, 0, 6); $where['lat'] = substr($result, 7, 10); $where['lng'] = substr($result, 17, 11); $where['su'] = substr($result, 28, 5); $where['his'] = substr($result, 33, 6); $where['direction'] = substr($result, 40, 6); $where['io'] = substr($result, 44, 8); $where['mileage'] = substr($result, 53, 9); $where['gps_content'] = $data; $where['create_time'] = time(); $check = DB::name('gpslist')->where('gps_content', $where['gps_content'])->find(); $mac['lat'] = $where['lat']; $mac['lng'] = $where['lng']; DB::name('merchant_shop_commodity')->where('macid', $where['macid'])->update($mac); if (!$check) { DB::name('gpslist')->insert($where); } } if (strpos($data, 'BR01') !== false) { $data = str_replace(array( '(', ')' ) , '', $data); $where['macid'] = substr($data, 0, strpos($data, 'BR01')); $result = substr($data, strrpos($data, "BR01") + 4); $where['ymd'] = substr($result, 0, 6); $where['lat'] = substr($result, 7, 10); $where['lng'] = substr($result, 17, 11); $where['su'] = substr($result, 28, 5); $where['his'] = substr($result, 33, 6); $where['direction'] = substr($result, 40, 6); $where['io'] = substr($result, 44, 8); $where['mileage'] = substr($result, 53, 9); $where['gps_content'] = $data; $where['create_time'] = time(); $check = DB::name('gpslist')->where('gps_content', $where['gps_content'])->find(); DB::name('merchant_shop_commodity')->where('macid', $where['macid'])->update($mac); if (!$check) { DB::name('gpslist')->insert($where); } } var_dump($data); if (strpos($data, 'BP05') !== false) { $data = str_replace(array( '(', ')' ) , '', $data); $data = substr($data, 0, strpos($data, 'B')); //登陸應(yīng)答 $send = '(' . $data . 'AP05)'; var_dump($send); //授時(shí) $time = '(' . $data . 'AP06' . date('YmdHis') . ")"; var_dump($time); //$check = DB::name('merchant_shop_commodity')->where('macid',$data)->find(); // if($check){ // $content = base64_encode($connection); // DB::name('merchant_shop_commodity')->where('macid',$data)->setfield('gpscontent',$content); // } $connection->send($send); $connection->send($time); $this->connections[$connection->id] = $connection; } if (strpos($data, 'BP00') !== false) { $data = str_replace(array( '(', ')' ) , '', $data); $data = substr($data, 0, strpos($data, 'B')); //握手應(yīng)答 $hand = '(' . $data . 'AP01HSO)'; var_dump($hand); $connection->send($hand); $this->connections[$connection->id] = $connection; } if (strpos($data, 'BP01') !== false) { $data = str_replace(array( '(', ')' ) , '', $data); $macid = substr($data, 0, strpos($data, 'BP01')); $a = substr($data, strpos($data, 'BP01') + 4); $where['version'] = substr($a, 0, strpos($a, 'CCID')); $where['iccid'] = substr($data, strripos($data, ":") + 1); var_dump($where); $checkiccid = DB::name('merchant_shop_commodity')->where('macid', $macid)->field('version,iccid')->find(); if (!$checkiccid['version'] || !$checkiccid['iccid']) { DB::name('merchant_shop_commodity')->where('macid', $macid)->update($where); } } if (strpos($data, 'BO01') !== false) { $data = str_replace(array( '(', ')' ) , '', $data); $where['macid'] = substr($data, 0, strpos($data, 'BO01')); $a = substr($data, strpos($data, 'BO01') + 4); $result = substr($data, strrpos($data, 'BO01') + 4); $where['ymd'] = substr($result, 0, 7); $where['lat'] = substr($result, 8, 10); $where['lng'] = substr($result, 18, 11); $where['su'] = substr($result, 29, 5); $where['his'] = substr($result, 34, 6); $where['direction'] = substr($result, 41, 6); $where['io'] = substr($result, 45, 8); $where['mileage'] = substr($result, 54, 9); $where['level'] = substr($a, 0, strpos($a, '2')); $where['content'] = $data; $where['create_time'] = time(); DB::name('gps_police')->insert($where); //報(bào)警應(yīng)答 $hand = '(' . $where['macid'] . 'AS01' . $where['level'] . ')'; var_dump($hand); $connection->send($hand); $this->connections[$connection->id] = $connection; } if (strpos($data, 'BO02') !== false) { $data = str_replace(array( '(', ')' ) , '', $data); $where['macid'] = substr($data, 0, strpos($data, 'BO02')); $a = substr($data, strpos($data, 'BO02') + 4); $result = substr($data, strrpos($data, 'BO01') + 4); $where['ymd'] = substr($result, 0, 7); $where['lat'] = substr($result, 8, 10); $where['lng'] = substr($result, 18, 11); $where['su'] = substr($result, 29, 5); $where['his'] = substr($result, 34, 6); $where['direction'] = substr($result, 41, 6); $where['io'] = substr($result, 45, 8); $where['mileage'] = substr($result, 54, 9); $where['level'] = substr($a, 0, strpos($a, '2')); $where['content'] = $data; $where['create_time'] = time(); DB::name('gps_police')->insert($where); } if (strpos($data, 'BV01') !== false) { $data = str_replace(array( '(', ')' ) , '', $data); $macid = substr($data, 0, strpos($data, 'B')); $instructions = substr($data, -1); $checkdevice = DB::name('merchant_shop_commodity')->where('macid', $macid)->find(); if ($checkdevice) { DB::name('merchant_shop_commodity')->where('macid', $macid)->setfield('instructions', $instructions); } } if (strpos($data, 'AT00') !== false || strpos($data, 'AV010') !== false || strpos($data, 'AV011') !== false || strpos($data, 'AP07') !== false || strpos($data, 'AP16') !== false || strpos($data, 'AV03') !== false || strpos($data, 'AP30') !== false || strpos($data, ' AP00') !== false) { //echo $data; if (isset($this->connections[1])) { $this->connections[1]->send($data); } else { $connection->send($data); } } //var_dump(base64_encode($connection)); }; // 運(yùn)行worker Worker::runAll(); }}


          在項(xiàng)目根目錄創(chuàng)建server.php

          #!/usr/bin/env php<?phpdefine('APP_PATH', __DIR__ . '/application/');define('BIND_MODULE','server/Server/index');// 加載框架引導(dǎo)文件require __DIR__ . '/thinkphp/start.php';


          最后終端啟動(dòng)服務(wù)

          php server.php start -d


          瀏覽 89
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  大香蕉婷婷伊人 | 中文丰满亲子伦在线观看 | 热热热热热色 | 免费操网站久久久久 | 99曰高清热视频 |