wang jun 1 year ago
parent
commit
c2ed643902

+ 154 - 0
application/api/controller/Shouhuan.php

@@ -0,0 +1,154 @@
+<?php
+namespace app\api\controller;
+
+use app\api\logic\Shouhuanlogic;
+//use app\common\server\ShouhuanCommand;
+use think\Controller;
+
+/**
+ * 套餐配送
+ *
+ * @author wj
+ * @date 2022-12-03
+ */
+class Shouhuan extends Controller
+{
+    protected $middleware = [\app\common\middleware\checkfacility::class];
+
+    /**
+     * 创建命令
+     *
+     * @return void
+     * @author wj
+     * @date 2023-09-02
+     */
+    public function createcommand()
+    {
+        $commandlist = [
+            'init', //初始化
+            'cr', //定位
+            'poweroff', //关机
+            'sos', //sos
+            'interval', //间隔
+            'falldown', //跌倒
+            'pedo', //计步开关
+            'phl', //电话本
+            'remind', //闹钟
+            'silencetime2', //静默时间
+            'remove', //佩戴提醒
+            'bootoff', //开关机时间
+        ];
+        $data = request()->post();
+        $command = $data['command'];
+        if (in_array($command, $commandlist)) {
+            $functionname = 'ctreate' . ucwords($command) . "Command";
+            if (method_exists($this, $functionname)) {
+                $facility_id = $data['facility_id'];
+                $device_id_code = $data['device_id_code'];
+                $param = !isset($data['param']) || empty($data['param']) ? [] : $data['param'];
+                $userinfo = request()->suinfo;
+                $sys_user_id = $userinfo['id'];
+                $result = $this->$functionname($facility_id, $device_id_code, $param, $sys_user_id);
+
+                $this->successjson($result['msg']);
+            }
+        }
+        $this->errorjson("命令错误");
+    }
+    private function ctreateInitCommand($facility_id, $device_id_code, $param = [], $sys_user_id)
+    {
+        $l_s = new Shouhuanlogic();
+        $result = $l_s->facilityinit($facility_id, $device_id_code, $param, $sys_user_id);
+        return $result;
+    }
+    private function ctreateCrCommand($facility_id, $device_id_code, $param = [], $sys_user_id)
+    {
+        $l_s = new Shouhuanlogic();
+        $result = $l_s->createcrcommand($facility_id, $device_id_code, $param, $sys_user_id);
+        return $result;
+    }
+    private function ctreatePoweroffCommand($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $l_s = new Shouhuanlogic();
+        $result = $l_s->createpoweroffcommand($facility_id, $device_id_code, $param, $sys_user_id);
+        return $result;
+    }
+
+    private function ctreateSosCommand($facility_id, $device_id_code, $param = [], $sys_user_id)
+    {
+        $l_s = new Shouhuanlogic();
+        $result = $l_s->createsoscommand($facility_id, $device_id_code, $param, $sys_user_id);
+        return $result;
+    }
+    private function ctreateIntervalCommand($facility_id, $device_id_code, $param = [], $sys_user_id)
+    {
+        $l_s = new Shouhuanlogic();
+        $result = $l_s->ctreateintervalcommand($facility_id, $device_id_code, $param, $sys_user_id);
+        return $result;
+    }
+    private function ctreateFalldownCommand($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $l_s = new Shouhuanlogic();
+        $result = $l_s->createfalldowncommand($facility_id, $device_id_code, $param, $sys_user_id);
+        return $result;
+    }
+    private function ctreatePedoCommand($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $l_s = new Shouhuanlogic();
+        $result = $l_s->createpedocommand($facility_id, $device_id_code, $param, $sys_user_id);
+        return $result;
+    }
+    private function ctreatePhlCommand($facility_id, $device_id_code, $param = [], $sys_user_id)
+    {
+        $l_s = new Shouhuanlogic();
+        $result = $l_s->createphlcommand($facility_id, $device_id_code, $param, $sys_user_id);
+        return $result;
+    }
+    private function ctreateRemindCommand($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $l_s = new Shouhuanlogic();
+        $result = $l_s->createremindcommand($facility_id, $device_id_code, $param, $sys_user_id);
+        return $result;
+    }
+    private function ctreateSilencetime2Command($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $l_s = new Shouhuanlogic();
+        $result = $l_s->createsilencetime2command($facility_id, $device_id_code, $param, $sys_user_id);
+        return $result;
+    }
+    private function ctreateRemoveCommand($facility_id, $device_id_code, $param = [], $sys_user_id)
+    {
+        $l_s = new Shouhuanlogic();
+        $result = $l_s->createremovecommand($facility_id, $device_id_code, $param, $sys_user_id);
+        return $result;
+    }
+    private function ctreateBootoffCommand($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $l_s = new Shouhuanlogic();
+        $result = $l_s->createbootoffcommand($facility_id, $device_id_code, $param, $sys_user_id);
+        return $result;
+    }
+    /**
+     * 返回正确信息
+     *
+     * @return void
+     * @author wj
+     * @date 2023-09-02
+     */
+    private function successjson($msg, $data = [])
+    {
+        return backjson2(200, $msg, $data);
+    }
+    /**
+     * 返回错误信息
+     *
+     * @return void
+     * @author wj
+     * @date 2023-09-02
+     */
+    private function errorjson($msg)
+    {
+        backjson2(500, $msg);
+    }
+
+}

+ 274 - 0
application/api/logic/Shouhuanlogic.php

@@ -0,0 +1,274 @@
+<?php
+namespace app\api\logic;
+
+use app\common\model\SettingModel;
+use app\common\server\ShouhuanCommand;
+
+/**
+ * 手环处理
+ * 低电报警开关 跌倒报警开关 睡眠时间段设置 立即定位  设置翻滚时间 设置sos电话 设置电话本
+ * 发送间隔 设备初始化
+ *
+ * @author wj
+ * @date 2023-08-29
+ */
+class Shouhuanlogic
+{
+    /**
+     * 设备初始化
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-29
+     */
+    public function facilityinit($facility_id, $device_id_code, $sys_user_id)
+    {
+        $m_s = new SettingModel();
+        $s_sc = new ShouhuanCommand();
+        $zone = $m_s->getvalue('shouhuan_zone'); //时区
+        $upload_interval = $m_s->getvalue('shouhuan_local_space'); //定位间隔
+        $fd_is_open = $m_s->getvalue('shouhuan_fall_call'); //定位间隔
+        $pedo_is_open = $m_s->getvalue('shouhuan_step_status'); //计步开关
+        $remove_is_open = $m_s->getvalue('shouhuan_wear_call'); //佩戴开关
+        $param = [
+            'zone' => $zone,
+            'upload_interval' => $upload_interval,
+            'fd_is_open' => $fd_is_open,
+            'lowbat_is_open' => 1,
+            'pedo_is_open' => $pedo_is_open,
+            'remove_is_open' => $remove_is_open,
+        ];
+        $s_sc->facilityinit($facility_id, $device_id_code, $param, $sys_user_id);
+        return backarr(1, "操作成功");
+    }
+    /**
+     * 低电报警开关
+     *
+     * @param  [type] $arr
+     * @return void
+     * @author wj
+     * @date 2023-08-29
+     */
+    public function createlowbatcommand($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $is_open = empty($param['is_open']) ? 0 : 1;
+        $s_sc = new ShouhuanCommand();
+        $s_sc->createlowbatcommand($facility_id, $device_id_code, $is_open, $sys_user_id);
+        return backarr(1, "操作成功");
+    }
+    /**
+     * 设置 跌倒报警开关
+     *
+     * @param  [type] $arr
+     * @return void
+     * @author wj
+     * @date 2023-08-29
+     */
+    public function createfalldowncommand($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $is_open = empty($param['is_open']) ? 0 : 1;
+        $s_sc = new ShouhuanCommand();
+        $s_sc->createfalldowncommand($facility_id, $device_id_code, $is_open, $sys_user_id);
+        return backarr(1, "操作成功");
+    }
+    //['starttime'=>'21:00','endtime'=>'6:00'];
+    /**
+     * 设置睡眠/翻滚时间段
+     *
+     * @param  [type] $arr
+     * @return void
+     * @author wj
+     * @date 2023-08-29
+     * 参数格式 ['starttime'=>'21:00','endtime'=>'6:00'];
+     */
+    public function createsleeptimecommand($facility_id, $device_id_code, $data, $sys_user_id)
+    {
+        $param = ['starttime' => $data['starttime'], 'endtime' => $data['endtime']];
+        $s_sc = new ShouhuanCommand();
+        $s_sc->createsleeptimecommand($facility_id, $device_id_code, $param, $sys_user_id);
+        return backarr(1, "操作成功");
+    }
+    //立即定位
+    public function createcrcommand($facility_id, $device_id_code, $sys_user_id)
+    {
+        $s_sc = new ShouhuanCommand();
+        $s_sc->createcrcommand($facility_id, $device_id_code, $sys_user_id);
+        return backarr(1, "操作成功");
+    }
+
+    //设置sos 电话
+    /**
+     * 设置sos 电话
+     * tels 一维数组 未验证是否为手机号
+     * @param  [type] $arr
+     * @return void
+     * @author wj
+     * @date 2023-08-29
+     */
+    public function createsoscommand($facility_id, $device_id_code, $data, $sys_user_id)
+    {
+        $param = $data['tels'];
+        $s_sc = new ShouhuanCommand();
+        $s_sc->createsoscommand($facility_id, $device_id_code, $param, $sys_user_id);
+        return backarr(1, "操作成功");
+    }
+    //设置电话本
+    /**
+     * 设置电话本
+     * 参数格式
+     * $phldata = [
+     *   ['telno' => '12344', 'name' => '测试2'],
+     *   ['telno' => '123', 'name' => '测试'],
+     * ];
+     * @param  [type] $arr
+     * @return void
+     * @author wj
+     * @date 2023-08-29
+     */
+    public function createphlcommand($facility_id, $device_id_code, $data, $sys_user_id)
+    {
+        $param = $data['param'];
+        $s_sc = new ShouhuanCommand();
+        $s_sc->createphlcommand($facility_id, $device_id_code, $param, $sys_user_id);
+        return backarr(1, "操作成功");
+    }
+    /**
+     * 数据间隔设置
+     *
+     * @param  [type] $facility_id
+     * @param  [type] $device_id_code
+     * @param  [type] $data
+     * @param  [type] $sys_user_id
+     * @return void
+     * @author wj
+     * @date 2023-09-05
+     */
+    public function ctreateintervalcommand($facility_id, $device_id_code, $data, $sys_user_id)
+    {
+        $m_s = new SettingModel();
+        $s_sc = new ShouhuanCommand();
+        //定位
+        if (!isset($data['cr_interval']) || empty($data['cr_interval'])) {
+            $cr_interval = $m_s->getvalue('shouhuan_local_space'); //分钟
+            $data['cr_interval'] = bcmul((int) $cr_interval, 60);
+        }
+        //心率
+        if (!isset($data['hrt_interval']) || empty($data['hrt_interval'])) {
+            $hrt_interval = $m_s->getvalue('shouhuan_heart_space'); //分钟
+            $data['hrt_interval'] = bcmul((int) $hrt_interval, 60);
+        }
+        //体温
+        if (!isset($data['wd_interval']) || empty($data['wd_interval'])) {
+            $wd_interval = $m_s->getvalue('shouhuan_body_space'); //分钟
+            $data['wd_interval'] = bcmul((int) $wd_interval, 60);
+        }
+        //血压
+        if (!isset($data['bld_interval']) || empty($data['bld_interval'])) {
+            $bld_interval = $m_s->getvalue('shouhuan_blood_space'); //分钟
+            $data['bld_interval'] = bcmul((int) $bld_interval, 60);
+        }
+        //血氧
+        if (!isset($data['ox_interval']) || empty($data['ox_interval'])) {
+            $ox_interval = $m_s->getvalue('shouhuan_oxygen_space'); //分钟
+            $data['ox_interval'] = bcmul((int) $ox_interval, 60);
+        }
+        $s_sc->setdatainterval($facility_id, $device_id_code, $data, $sys_user_id);
+        return backarr(1, "操作成功");
+    }
+    /**
+     * 关机
+     *
+     * @param  [type] $facility_id
+     * @param  [type] $device_id_code
+     * @param  [type] $sys_user_id
+     * @return void
+     * @author wj
+     * @date 2023-09-05
+     */
+    public function createpoweroffcommand($facility_id, $device_id_code, $sys_user_id)
+    {
+        $s_sc = new ShouhuanCommand();
+        $s_sc->createpoweroffcommand($facility_id, $device_id_code, $sys_user_id);
+        return backarr(1, "操作成功");
+    }
+    /**
+     * 静默时间
+     *
+     * @param  [type] $facility_id
+     * @param  [type] $device_id_code
+     * @param  [type] $param
+     * @param  [type] $sys_user_id
+     * @return void
+     * @author wj
+     * @date 2023-09-05
+     */
+    public function createsilencetime2command($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $s_sc = new ShouhuanCommand();
+        $s_sc->createsilencetime2command($facility_id, $device_id_code, $param, $sys_user_id);
+        return backarr(1, "操作成功");
+    }
+
+    /**
+     * 开关机时间
+     *
+     * @return void
+     * @author wj
+     * @date 2023-09-05
+     */
+    public function createbootoffcommand($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $s_sc = new ShouhuanCommand();
+        $s_sc->createbootoffcommand($facility_id, $device_id_code, $param, $sys_user_id);
+        return backarr(1, "操作成功");
+    }
+    /**
+     * 佩戴提醒
+     *
+     * @param  [type] $facility_id
+     * @param  [type] $device_id_code
+     * @param  [type] $param
+     * @param  [type] $sys_user_id
+     * @return void
+     * @author wj
+     * @date 2023-09-05
+     */
+    public function createremovecommand($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $is_open = empty($param['is_open']) ? 0 : 1;
+        $s_sc = new ShouhuanCommand();
+        $s_sc->createremovecommand($facility_id, $device_id_code, $is_open, $sys_user_id);
+        return backarr(1, "操作成功");
+    }
+    /**
+     * 闹钟
+     *
+     * @param  [type] $facility_id
+     * @param  [type] $device_id_code
+     * @param  [type] $param
+     * @param  [type] $sys_user_id
+     * @return void
+     * @author wj
+     * @date 2023-09-05
+     */
+    public function createremindcommand($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $s_sc = new ShouhuanCommand();
+        $s_sc->createremindcommand($facility_id, $device_id_code, $param, $sys_user_id);
+        return backarr(1, "操作成功");
+    }
+    /**
+     * 计步开关
+     *
+     * @return void
+     * @author wj
+     * @date 2023-09-05
+     */
+    public function createpedocommand($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $is_open = empty($param['is_open']) ? 0 : 1;
+        $s_sc = new ShouhuanCommand();
+        $s_sc->createpedocommand($facility_id, $device_id_code, $is_open, $sys_user_id);
+        return backarr(1, "操作成功");
+    }
+}

+ 15 - 1
application/common.php

@@ -10,6 +10,20 @@
 // +----------------------------------------------------------------------
 
 // 应用公共文件
+/*app用
+ * 20210927
+ * wj
+ */
+function backjson3($code, $msg = "", $data = [], $type = 320)
+{
+    $jsonData = [
+        'code' => $code,
+        'msg' => $msg,
+        'data' => $data,
+    ];
+    return json($jsonData);
+}
+/*
 /*app用
  * 20210927
  * wj
@@ -146,7 +160,7 @@ function isMoblid($tel)
         return false;
     }
 }
-//curl 请
+//curl 请
 function curl_request($url, $data = null, $header = [])
 {
     //$headerArray = array("Content-type:application/json;charset='utf-8'", "Accept:application/json");

+ 76 - 0
application/common/middleware/checkfacility.php

@@ -0,0 +1,76 @@
+<?php
+
+namespace app\common\middleware;
+
+use app\common\model\FacilityModel;
+use app\common\model\Sysusermodel;
+
+class checkfacility
+{
+    public function handle($request, \Closure $next)
+    {
+        if (!request()->isPost()) {
+            return backjson3(500, "请求错误");
+        }
+        $param = $request->post();
+        $token = request()->header('token');
+
+        $suinfo = $this->checktoken($token);
+        if (empty($suinfo)) {
+            return backjson3(401, "认证失败,无法访问系统资源");
+        }
+        $finfo = $this->checkfilleData($param);
+        if (empty($finfo)) {
+            return backjson3(500, "设备信息错误");
+        }
+
+        $request->finfo = $finfo;
+        $request->suinfo = $suinfo;
+        return $next($request);
+    }
+    /**
+     * 校验必填字段
+     *
+     * @return void
+     * @author wj
+     * @date 2023-09-02
+     */
+    private function checkfilleData($param)
+    {
+        $fillfields = ['facility_id', 'device_id_code', 'command'];
+        foreach ($fillfields as $key => $value) {
+            if (!isset($param[$value]) || empty($param[$value])) {
+                return false;
+            }
+        }
+        $facility_id = $param['facility_id'];
+        $device_id_code = $param['device_id_code'];
+
+        $m_f = new FacilityModel();
+        $where = ['id' => $facility_id, 'code' => $device_id_code];
+        $finfo = $m_f->getInfo($where, ['id']);
+        if (empty($finfo)) {
+            return false;
+        }
+        return $finfo;
+    }
+    /**
+     * 验证用户token
+     *
+     * @return void
+     * @author wj
+     * @date 2023-09-04
+     */
+    private function checktoken($token)
+    {
+        if (empty($token)) {
+            return false;
+        }
+        $m_su = new Sysusermodel();
+        $suinfo = $m_su->getinfobytoken($token);
+        if (empty($suinfo)) {
+            return false;
+        }
+        return $suinfo;
+    }
+}

+ 17 - 0
application/common/model/SettingModel.php

@@ -74,4 +74,21 @@ class SettingModel extends Model
         }
         return $data;
     }
+    /**
+     * 获取键值
+     *
+     * @param  [type] $key
+     * @return void
+     * @author wj
+     * @date 2023-09-05
+     */
+    public function getvalue($key)
+    {
+        $where = ['key' => $key];
+        $info = $this->field(['value'])->where($where)->find();
+        if (!$info) {
+            return false;
+        }
+        return $info['value'];
+    }
 }

+ 82 - 0
application/common/model/Sysusermodel.php

@@ -0,0 +1,82 @@
+<?php
+/**
+ * 系统用户
+ */
+namespace app\common\model;
+
+use think\Model;
+
+class Sysusermodel extends Model
+{
+    protected $table = 'sys_user';
+
+    public function insertData($data)
+    {
+        $field = $this->getTableFields();
+        $insertData = [];
+        foreach ($field as $key => $value) {
+            if (in_array($value, array_keys($data))) {
+                $insertData[$value] = $data[$value];
+            }
+        }
+        unset($insertData['id']);
+        $data = $insertData;
+        $id = $this->insertGetId($data);
+        return empty($id) ? false : $id;
+    }
+
+    public function getInfo($where, $field = "*", $row = true)
+    {
+        $info = $this->field($field)->where($where);
+        if ($row) {
+            $info = $info->find();
+        } else {
+            $info = $info->select();
+        }
+        return empty($info) ? false : $info;
+    }
+
+    public function updateinfo($where, $updateData)
+    {
+        $row = $this->where($where)->update($updateData);
+        return empty($row) ? false : $row;
+    }
+
+    public function deleteinfo($where)
+    {
+        $row = $this->where($where)->delete();
+        return empty($row) ? false : $row;
+    }
+
+    public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $sqlObj = $this->where($where);
+        if ("count" != $field) {
+            $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj->count();
+        }
+        return $data;
+    }
+    /**
+     * 根据token获取用户信息
+     *
+     * @param  [type] $token
+     * @return void
+     * @author wj
+     * @date 2023-09-02
+     */
+    public function getinfobytoken($token)
+    {
+        $where = ['token' => $token];
+        $field = $this->getTableFields();
+        unset($field['password']);
+        $info = $this->field($field)->where($where)->find();
+        return empty($info) ? false : $info;
+    }
+}

+ 879 - 0
application/common/server/ShouhuanCommand.php

@@ -0,0 +1,879 @@
+<?php
+
+namespace app\common\server;
+
+use app\common\model\FacilityModel;
+use app\common\model\ShsendlistModel;
+use app\common\model\ShsendqueueModel;
+
+//use app\common\server\SouhuanAnalysis;
+
+//use think\facade\Log;
+
+/**
+ * 手环命令创建
+ *
+ * @author wj
+ * @date 2023-09-01
+ */
+class ShouhuanCommand
+{
+    /**
+     * 获取设备信息
+     *
+     * @param  [type] $facility_id
+     * @param  [type] $device_id_code
+     * @return void
+     * @author wj
+     * @date 2023-09-01
+     */
+    private function getfacilityinfo($facility_id, $device_id_code)
+    {
+        $m_f = new FacilityModel();
+        $fwhere = [
+            'id' => $facility_id,
+            'code' => $device_id_code,
+            'kind' => 1,
+            'status' => 1,
+        ];
+        $finfo = $m_f->getInfo($fwhere);
+        if (!$finfo) {
+            throw new \Exception("无对应信息:" . $facility_id . "-" . $device_id_code);
+        }
+        return $finfo;
+    }
+    /**
+     * 创建发送信息
+     *
+     * @param  [type] $data
+     * @param  [type] $command
+     * @return void
+     * @author wj
+     * @date 2023-08-14
+     * $data =['command'=>'','content_arr'=>[],]
+     */
+    public function createsendmsg($facility_id, $device_id_code, $data, $param = [], $sys_user_id = 0)
+    {
+        $command = $data['command'];
+        $infoarr = $this->getsendcommandinfo($command);
+        if (!$infoarr) {
+            // Log::write("无对应命令数据1:" . $command, 'shouhuan');
+            // Log::write($data, 'shouhuan');
+            return false;
+        }
+        $content_arr = $data['content_arr'];
+        $config = $infoarr;
+        $m_ssl = new ShsendlistModel();
+        $commandxy = "3G";
+        //仅创建
+        if ($command == 'AL') {
+            $msg_type = 1;
+        } else {
+            $msg_type = 0;
+        }
+        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'];
+            $content_custom = isset($config['content_custom']) ? $config['content_custom'] : false;
+            $need_back = $config['need_back'];
+            if ($content_custom) {
+                $functionname = 'get' . $command . "Commandinfo";
+                if (method_exists($this, $functionname)) {
+                    $content = $useconmmand . "," . $this->$functionname($param);
+                } else {
+                    throw new \Exception($command . "自定义方法不存在");
+                }
+            } else {
+                $content = implode(',', $content_arr);
+            }
+            $send_type = 1;
+            if ($need_back) {
+                $is_success = 0;
+            } else {
+                $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;
+    }
+    /**
+     * 获取回复权重
+     *
+     * @param  [type] $command
+     * @return void
+     * @author wj
+     * @date 2023-08-11
+     */
+    public function getsendweight($command)
+    {
+        $weight = -1;
+        switch ($command) {
+            case 'POWEROFF':
+                //关机
+                $weight = 99;
+                break;
+            case 'RESET':
+                //重启
+                $weight = 98; //硬件未测试
+                break;
+            //平台回复命令
+            case 'AL':
+            case 'KA':
+            case 'LK':
+            case 'PING':
+            case 'BPHRT':
+            case 'TEMP':
+            case 'HEART':
+            case 'BLOOD':
+            case 'OXYGEN':
+                $weight = 1;
+                break;
+            //平台发送命令
+            case 'ZONE':
+            case 'UPLOAD':
+            case 'CR':
+            case 'SLEEPTIME':
+            case 'FALLDOWN':
+            case 'FACTORY':
+            case 'SOS':
+            case 'VERNO':
+            case 'LOWBAT':
+            case 'POWEROFF':
+            case 'LSSET':
+            case 'PEDO':
+            case 'PHL':
+            case 'REMIND':
+            case 'SILENCETIME2':
+            case 'BOOTOFF':
+            case 'REMOVE':
+                $weight = 0;
+                break;
+            default:
+                $weight = -1;
+                break;
+        }
+        if ($weight < 0) {
+            //不需设置 发送信息
+            return false;
+        }
+        return $weight;
+    }
+    /**
+     * 获取平台发送命令信息
+     *
+     * @param  [type] $command
+     * @return void
+     * @author wj
+     * @date 2023-08-11
+     */
+    public function getsendcommandinfo($command)
+    {
+        $command = strtoupper($command);
+        $data = [
+            //平台发送
+            //时区
+            'ZONE' => [
+                'content' => [
+                    'command' => 'ZONE',
+                    'zone' => '',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            //位置发送间隔
+            'UPLOAD' => [
+                'content' => [
+                    'command' => 'UPLOAD',
+                    'interval' => '',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            //心率上传间隔
+            'HRTSTART' => [
+                'content' => [
+                    'command' => 'hrtstart',
+                    'interval' => '',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            //体温上传间隔
+            'WDSTART' => [
+                'content' => [
+                    'command' => 'wdstart',
+                    'interval' => '',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            //血压上传频率
+            'BLDSTART' => [
+                'content' => [
+                    'command' => 'bldstart',
+                    'interval' => '',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            //血氧上传频率
+            'OXSTART' => [
+                'content' => [
+                    'command' => 'oxstart',
+                    'interval' => '',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+
+            //立即定位
+            'CR' => [
+                'content' => [
+                    'command' => 'CR',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'SLEEPTIME' => [
+                'content' => [
+                    'command' => 'CR',
+                ],
+                'kind' => 'send',
+                'content_custom' => true,
+                'need_back' => 1,
+            ],
+            'FALLDOWN' => [
+                'content' => [
+                    'command' => 'FALLDOWN',
+                    'is_open' => '',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'FACTORY' => [
+                'content' => [
+                    'command' => 'FACTORY',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'SOS' => [
+                'content' => [
+                    'command' => 'SOS',
+                ],
+                'kind' => 'send',
+                'content_custom' => true,
+                'need_back' => 1,
+            ],
+            'VERNO' => [
+                'content' => [
+                    'command' => 'VERNO',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'LOWBAT' => [
+                'content' => [
+                    'command' => 'LOWBAT',
+                    'is_open' => '',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'POWEROFF' => [
+                'content' => [
+                    'command' => 'POWEROFF',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'LSSET' => [
+                'content' => [
+                    'command' => 'LSSET',
+                    'content_custom' => true,
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'PEDO' => [
+                'content' => [
+                    'command' => 'PEDO',
+                    'is_open' => '',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'PHL' => [
+                'content' => [
+                    'command' => 'PEDO',
+                ],
+                'kind' => 'send',
+                'content_custom' => true,
+                'need_back' => 1,
+            ],
+            'REMIND' => [
+                'content' => [
+                    'command' => 'REMIND',
+                ],
+                'kind' => 'send',
+                'content_custom' => true,
+                'need_back' => 1,
+            ],
+            'SILENCETIME2' => [
+                'content' => [
+                    'command' => 'SILENCETIME2',
+                ],
+                'kind' => 'send',
+                'content_custom' => true,
+                'need_back' => 1,
+            ],
+            'BOOTOFF' => [
+                'content' => [
+                    'command' => 'BOOTOFF',
+                    'is_open' => '',
+                    'bootup_time' => '',
+                    'shutdown_time' => '',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            'REMOVE' => [
+                'content' => [
+                    'command' => 'REMOVE',
+                    'is_open' => '',
+                ],
+                'kind' => 'send',
+                'need_back' => 1,
+            ],
+            //平台回复
+            'LK' => [
+                'content' => [
+                    'command' => 'LK',
+                ],
+                'kind' => 'back',
+            ],
+            'PING' => [
+                'content' => [
+                    'command' => 'PING',
+                    'isbind' => 1,
+                ],
+                'kind' => 'back',
+            ],
+            'KA' => [
+                'content' => [
+                    'command' => 'KA',
+                ],
+                'kind' => 'back',
+            ],
+            'TEMP' => [
+                'content' => [
+                    'command' => 'temp',
+                ],
+                'kind' => 'back',
+            ],
+            'BPHRT' => [
+                'content' => [
+                    'command' => 'bphrt',
+                ],
+                'kind' => 'back',
+            ],
+            'HEART' => [
+                'content' => [
+                    'command' => 'heart',
+                ],
+                'kind' => 'back',
+            ],
+            'BLOOD' => [
+                'content' => [
+                    'command' => 'blood',
+                ],
+                'kind' => 'back',
+            ],
+            'OXYGEN' => [
+                'content' => [
+                    'command' => 'oxygen',
+                ],
+                'kind' => 'back',
+            ],
+            'AL' => [
+                'content' => [
+                    'command' => 'AL',
+                ],
+                'kind' => 'back',
+            ],
+        ];
+        if (!isset($data[$command])) {
+            return false;
+        }
+        return $data[$command];
+    }
+    /**
+     * 创建sos电话设置命令
+     * 最多三个电话
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    public function getSOSCommandinfo($param)
+    {
+        if (count($param) <= 0) {
+            throw new \Exception("未设置电话");
+
+        }
+        if (count($param) > 3) {
+            throw new \Exception("设置电话数量过多");
+
+        }
+        foreach ($param as $key => $value) {
+            //判断是否为手机号
+            //暂不处理
+        }
+        $info = implode(",", $param);
+        return $info;
+    }
+    /**
+     * 设置跌倒灵敏度命令
+     * [3G*358800006072996*0009*LSSET,3+6]
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    public function getLSSETCommandinfo($param)
+    {
+        if (2 != count($param)) {
+            throw new \Exception("LSSET参数错误");
+        }
+        foreach ($param as $key => $value) {
+            if (!is_numeric($value)) {
+                throw new \Exception("LSSET参数错误:" . $value);
+            }
+        }
+        $info = $param[0] . "+" . $param[1];
+        return $info;
+    }
+    /**
+     * 设置电话本
+     * 最多10条
+     *[{telno=>'',name=>''}]
+     * @param  [type] $param
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    public function getPHLCommaninfo($param)
+    {
+        if (50 < count($param)) {
+            throw new \Exception("PHL参数错误");
+        }
+        if (0 != count($param) % 2) {
+            throw new \Exception("PHL参数长度错误");
+        }
+        $usedata = [];
+        foreach ($param as $key => $value) {
+            $telno = $value['telno'];
+            $name = $value['name'];
+            //电话号码
+            if (20 < mb_strlen($telno)) {
+                throw new \Exception("PHL电话号码错误:" . $telno);
+            }
+            $name = $this->srtingToUnicode($name);
+            $usedata[] = $telno;
+            $usedata[] = $name;
+        }
+        $info = implode(",", $usedata);
+        return $info;
+    }
+    /**
+     * 设置电话本
+     * 最多10条
+     *{[time=>'',isopen=>'','type'=>'','weeks'=>[]]}
+     *  weeks 数组 每个1到7 周日到周六
+     * 最多设置三个
+     * @param  [type] $param
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    /*
+    08:10-1-1:闹钟时间 8:10,打开,响铃一次
+    08:10-1-2:闹钟时间 8:10,打开,每天响铃
+    08:10-1-3-0111110:闹钟时间 8:10,打开,自定义周一至周五打开
+    最左边是周日,最右边是周六,即 0111110 的顺序是:周日,周一,周二,周三,周四,周五,周
+    六(1 为打开,0 为关闭),其中周一至周五打开闹钟
+     */
+    public function getREMINDCommandinfo($param)
+    {
+        if (3 > count($param)) {
+            throw new \Exception("PHL参数错误");
+        }
+        $usedata = [];
+        foreach ($param as $key => $value) {
+            $useweeks = ["0", "0", "0", "0", "0", "0", "0"];
+            $time = $this->formattime($value['time'], 'H:i');
+            $isopen = $value['isopen'];
+            $type = $value['type'];
+            $weeks = $value['weeks'];
+            if (3 == $type) {
+                foreach ($weeks as $wkey => $wvalue) {
+                    if ($wvalue >= 1 && $wvalue <= 7) {
+                        $useweeks[$wvalue - 1] = '1';
+                    }
+                }
+                $useweeks = implode("", $useweeks);
+                $type = $useweeks;
+            }
+            $usedata[] = $time . "-" . $isopen . "-" . $type;
+        }
+        $usedata = implode(",", $usedata);
+        return $usedata;
+    }
+    /**
+     * 静默时间段测试
+     *{[starttime=>'',endtime=>'',isopen=>'',weeks=>[]]}
+     * weeks 数组 每个1到7 周日到周六
+     * 最多设置三个
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    /*
+    [DW*334588000000156*0038*SILENCETIME2,7:30-21:10-1-0111110,7:30-21:10-1-0111110,7:
+    30-21:10-0-0111110]
+    设置上课禁用时间段范围,拦截终端的任何来电。格式为“起始时间-结束时间-自定义星期几”, 比
+    如上面的 7:30-21:00-0111110,则表示周一到周五 7:30 到 21:00 之间上课禁用生效,起始时间
+    默认大于结束时间。
+    总开关:0 为关,1 为开
+    关于自定义星期几的规则:最左边是周日,最右边是周六,即 0111110 的顺序是:周日,周一,周
+    二,周三,周四,周五,周六(1 为打开,0 为关闭),所以上面的意思是周一至周五打开上课禁
+    用。
+     */
+    public function getSILENCETIME2Commandinfo($param)
+    {
+        if (3 <= count($param)) {
+            throw new \Exception("SILENCETIME2参数错误");
+        }
+        $usedata = [];
+        foreach ($param as $key => $value) {
+            $useweeks = ["0", "0", "0", "0", "0", "0", "0"];
+            //未比较时间大小
+            $starttime = $this->formattime($value['starttime'], 'H:i');
+            $endtime = $this->formattime($value['endtime'], 'H:i');
+            $isopen = $value['isopen'];
+            $weeks = $value['weeks'];
+            foreach ($weeks as $wkey => $wvalue) {
+                if ($wvalue >= 1 && $wvalue <= 7) {
+                    $useweeks[$wvalue - 1] = '1';
+                }
+            }
+            $useweeks = implode("", $useweeks);
+            $usedata[] = $starttime . "-" . $endtime . "-" . $isopen . "-" . $useweeks;
+        }
+        $usedata = implode(",", $usedata);
+        return $usedata;
+    }
+    /**
+     * 睡眠时间段设置
+     *{starttime=>'',endtime=>''}
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    public function getSLEEPTIMECommandinfo($param)
+    {
+        if (2 > count($param)) {
+            throw new \Exception("SLEEPTIME参数错误");
+        }
+        $starttime = $this->formattime($param['starttime'], 'H:i');
+        $endtime = $this->formattime($param['endtime'], 'H:i');
+        $usedata = $starttime . "-" . $endtime;
+        return $usedata;
+    }
+
+    public function formattime($time, $format)
+    {
+        $time = strtotime($time);
+        $time = date($format, $time);
+        return $time;
+    }
+    /**
+     * unicode 编码
+     *
+     * @param  [type] $str
+     * @return void
+     * @author wj
+     * @date 2023-08-21
+     */
+    public function srtingToUnicode($str)
+    {
+        $unicode = '';
+        $arr = mb_str_split($str); //适配中文
+        foreach ($arr as $key => $value) {
+            $char = bin2hex(iconv('UTF-8', 'UCS-2BE', $value));
+            $char = str_pad($char, 4, '0', STR_PAD_LEFT);
+            $arr[$key] = $char;
+        }
+        $unicode = implode("", $arr);
+        return $unicode;
+    }
+    //设置 低电报警开关
+    public function createlowbatcommand($facility_id, $device_id_code, $is_open, $sys_user_id)
+    {
+        $command = ['command' => 'LOWBAT', 'content_arr' => ['command' => 'LOWBAT', 'is_open' => $is_open]];
+        $this->createsendmsg($facility_id, $device_id_code, $command, [], $sys_user_id);
+    }
+    //设置 跌倒报警开关
+    public function createfalldowncommand($facility_id, $device_id_code, $is_open, $sys_user_id)
+    {
+        $command = ['command' => 'FALLDOWN', 'content_arr' => ['command' => 'FALLDOWN', 'is_open' => $is_open]];
+        $this->createsendmsg($facility_id, $device_id_code, $command, [], $sys_user_id);
+    }
+    /**
+     * 睡眠时间段设置
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-29
+     */
+    public function createsleeptimecommand($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $command = ['command' => 'SLEEPTIME'];
+        $this->createsendmsg($facility_id, $device_id_code, $command, $param, $sys_user_id);
+    }
+    /**
+     * 立即定位
+     *
+     * @return void
+     * @author wj
+     * @date 2023-08-29
+     */
+    public function createcrcommand($facility_id, $device_id_code, $sys_user_id)
+    {
+        $command = ['command' => 'CR'];
+        $this->createsendmsg($facility_id, $device_id_code, $command, [], $sys_user_id);
+    }
+    /**
+     * 设置警报电话
+     *
+     * @param  [type] $facility_id
+     * @param  [type] $device_id_code
+     * @param  [type] $param
+     * @return void
+     * @author wj
+     * @date 2023-08-29
+     */
+    public function createsoscommand($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $command = ['command' => 'SOS'];
+        $this->createsendmsg($facility_id, $device_id_code, $command, $param, $sys_user_id);
+    }
+    /**
+     * 设置电话本
+     *
+     * @param  [type] $arr
+     * @return void
+     * @author wj
+     * @date 2023-08-29
+     */
+    public function createphlcommand($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $command = ['command' => 'PHL'];
+        $this->createsendmsg($facility_id, $device_id_code, $command, $param, $sys_user_id);
+    }
+    //设备初始化
+    public function facilityinit($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $zone = $param['zone'];
+        $upload_interval = $param['upload_interval'];
+        $fd_is_open = $param['fd_is_open'];
+        $lowbat_is_open = $param['lowbat_is_open'];
+        $pedo_is_open = $param['pedo_is_open'];
+        $remove_is_open = $param['remove_is_open'];
+        $commandlist = [
+            ['command' => 'ZONE', 'content_arr' => ['command' => 'ZONE', 'zone' => $zone]],
+            ['command' => 'UPLOAD', 'content_arr' => ['command' => 'UPLOAD', 'interval' => $upload_interval]],
+            ['command' => 'CR', 'content_arr' => ['command' => 'CR']],
+            ['command' => 'FALLDOWN', 'content_arr' => ['command' => 'FALLDOWN', 'is_open' => $fd_is_open]],
+            ['command' => 'VERNO', 'content_arr' => ['command' => 'VERNO']],
+            ['command' => 'LOWBAT', 'content_arr' => ['command' => 'LOWBAT', 'is_open' => $lowbat_is_open]],
+            ['command' => 'PEDO', 'content_arr' => ['command' => 'PEDO', 'is_open' => $pedo_is_open]],
+            ['command' => 'REMOVE', 'content_arr' => ['command' => 'REMOVE', 'is_open' => $remove_is_open]],
+        ];
+        foreach ($commandlist as $key => $value) {
+            $this->createsendmsg($facility_id, $device_id_code, $value, [], $sys_user_id);
+        }
+    }
+    /**
+     * 数据间隔设置
+     * 位置 心率 体温 血压 血氧
+     *
+     * @return void
+     * @author wj
+     * @date 2023-09-01
+     */
+    public function setdatainterval($facility_id, $device_id_code, $param = [], $sys_user_id)
+    {
+        $cr_interval = $param['cr_interval'];
+        $hrt_interval = $param['hrt_interval'];
+        $wd_interval = $param['wd_interval'];
+        $bld_interval = $param['bld_interval'];
+        $ox_interval = $param['ox_interval'];
+
+        $commandlist = [
+            ['command' => 'UPLOAD', 'content_arr' => ['command' => 'UPLOAD', 'interval' => $cr_interval]],
+            ['command' => 'HRTSTART', 'content_arr' => ['command' => 'HRTSTART', 'interval' => $hrt_interval]],
+            ['command' => 'WDSTART', 'content_arr' => ['command' => 'WDSTART', 'interval' => $wd_interval]],
+            ['command' => 'BLDSTART', 'content_arr' => ['command' => 'BLDSTART', 'interval' => $bld_interval]],
+            ['command' => 'OXSTART', 'content_arr' => ['command' => 'OXSTART', 'interval' => $ox_interval]],
+        ];
+        foreach ($commandlist as $key => $value) {
+            $this->createsendmsg($facility_id, $device_id_code, $value, $sys_user_id);
+        }
+    }
+    /**
+     * 关机
+     *
+     * @param  [type] $facility_id
+     * @param  [type] $device_id_code
+     * @param  [type] $sys_user_id
+     * @return void
+     * @author wj
+     * @date 2023-09-05
+     */
+    public function createpoweroffcommand($facility_id, $device_id_code, $sys_user_id)
+    {
+        $command = ['command' => 'POWEROFF'];
+        $this->createsendmsg($facility_id, $device_id_code, $command, [], $sys_user_id);
+    }
+    /**
+     * 计步开关
+     *
+     * @param  [type] $facility_id
+     * @param  [type] $device_id_code
+     * @param  [type] $sys_user_id
+     * @return void
+     * @author wj
+     * @date 2023-09-05
+     */
+    public function createpedocommand($facility_id, $device_id_code, $is_open, $sys_user_id)
+    {
+        $command = ['command' => 'PEDO', 'content_arr' => ['command' => 'PEDO', 'is_open' => $is_open]];
+        $this->createsendmsg($facility_id, $device_id_code, $command, [], $sys_user_id);
+    }
+    /**
+     * 闹钟
+     *
+     * @param  [type] $facility_id
+     * @param  [type] $device_id_code
+     * @param  [type] $param
+     * @param  [type] $sys_user_id
+     * @return void
+     * @author wj
+     * @date 2023-09-05
+     */
+    public function createremindcommand($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $command = ['command' => 'REMIND'];
+        $this->createsendmsg($facility_id, $device_id_code, $command, $param, $sys_user_id);
+    }
+    /**
+     * 静默时间
+     *
+     * @param  [type] $facility_id
+     * @param  [type] $device_id_code
+     * @param  [type] $param
+     * @param  [type] $sys_user_id
+     * @return void
+     * @author wj
+     * @date 2023-09-05
+     */
+    public function createsilencetime2command($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $command = ['command' => 'SILENCETIME2'];
+        $this->createsendmsg($facility_id, $device_id_code, $command, $param, $sys_user_id);
+    }
+    /**
+     * 开机关机时间
+     *
+     * @param  [type] $facility_id
+     * @param  [type] $device_id_code
+     * @param  [type] $param
+     * @param  [type] $sys_user_id
+     * @return void
+     * @author wj
+     * @date 2023-09-05
+     */
+    public function createbootoffcommand($facility_id, $device_id_code, $param, $sys_user_id)
+    {
+        $is_open = $param['is_open'];
+        $bootup_time = $param['bootup_time'];
+        $shutdown_time = $param['shutdown_time'];
+        $command = [
+            'command' => 'BOOTOFF',
+            'content' => ['command' => 'BOOTOFF', 'is_open' => $is_open, 'bootup_time' => $bootup_time, 'shutdown_time' => $shutdown_time],
+        ];
+        $this->createsendmsg($facility_id, $device_id_code, $command, [], $sys_user_id);
+    }
+    /**
+     * 佩戴提醒
+     *
+     * @param  [type] $facility_id
+     * @param  [type] $device_id_code
+     * @param  [type] $param
+     * @param  [type] $sys_user_id
+     * @return void
+     * @author wj
+     * @date 2023-09-05
+     */
+    public function createremovecommand($facility_id, $device_id_code, $is_open, $sys_user_id)
+    {
+        $command = ['command' => 'REMOVE', 'content_arr' => ['command' => 'REMOVE', 'is_open' => $is_open]];
+        $this->createsendmsg($facility_id, $device_id_code, $command, [], $sys_user_id);
+    }
+}

+ 26 - 610
application/common/server/SouhuanAnalysis.php

@@ -13,6 +13,7 @@ use think\facade\Log;
 
 /**
  * 手环字符串解析
+ * 解析命令 发送命令
  *
  * @author wj
  * @date 2023-08-11
@@ -65,6 +66,8 @@ class SouhuanAnalysis
             Log::write($errmsg . ":" . $str, 'shouhuan');
             throw new \Exception($errmsg);
         }
+        //验证设备状态
+        $fid = $this->getfacilityid($device_id_code);
         $data = [
             'device_id_code' => $device_id_code,
             'content_len' => $content_len,
@@ -223,6 +226,7 @@ class SouhuanAnalysis
         ];
         return $data;
     }
+
     /**
      * 解析终端发送命令长度
      *
@@ -236,215 +240,7 @@ class SouhuanAnalysis
         $len = base_convert($len, 16, 10);
         return $len;
     }
-    /**
-     * 获取平台发送命令信息
-     *
-     * @param  [type] $command
-     * @return void
-     * @author wj
-     * @date 2023-08-11
-     */
-    public function getsendcommandinfo($command)
-    {
-        $command = strtoupper($command);
-        $data = [
-            //平台发送
-            'ZONE' => [
-                'content' => [
-                    'command' => 'ZONE',
-                    'zone' => '',
-                ],
-                'kind' => 'send',
-                'need_back' => 1,
-            ],
-            'UPLOAD' => [
-                'content' => [
-                    'command' => 'UPLOAD',
-                    'interval' => '',
-                ],
-                'kind' => 'send',
-                'need_back' => 1,
-            ],
-            'CR' => [
-                'content' => [
-                    'command' => 'CR',
-                ],
-                'kind' => 'send',
-                'need_back' => 1,
-            ],
-            'SLEEPTIME' => [
-                'content' => [
-                    'command' => 'CR',
-                ],
-                'kind' => 'send',
-                'content_custom' => true,
-                'need_back' => 1,
-            ],
-            'FALLDOWN' => [
-                'content' => [
-                    'command' => 'FALLDOWN',
-                    'is_open' => '',
-                ],
-                'kind' => 'send',
-                'need_back' => 1,
-            ],
-            'FACTORY' => [
-                'content' => [
-                    'command' => 'FACTORY',
-                ],
-                'kind' => 'send',
-                'need_back' => 1,
-            ],
-            'SOS' => [
-                'content' => [
-                    'command' => 'SOS',
-                ],
-                'kind' => 'send',
-                'content_custom' => true,
-                'need_back' => 1,
-            ],
-            'VERNO' => [
-                'content' => [
-                    'command' => 'VERNO',
-                ],
-                'kind' => 'send',
-                'need_back' => 1,
-            ],
-            'LOWBAT' => [
-                'content' => [
-                    'command' => 'LOWBAT',
-                    'is_open' => '',
-                ],
-                'kind' => 'send',
-                'need_back' => 1,
-            ],
-            'POWEROFF' => [
-                'content' => [
-                    'command' => 'POWEROFF',
-                ],
-                'kind' => 'send',
-                'need_back' => 1,
-            ],
-            'LSSET' => [
-                'content' => [
-                    'command' => 'LSSET',
-                    'content_custom' => true,
-                ],
-                'kind' => 'send',
-                'need_back' => 1,
-            ],
-            'PEDO' => [
-                'content' => [
-                    'command' => 'PEDO',
-                    'is_open' => '',
-                ],
-                'kind' => 'send',
-                'need_back' => 1,
-            ],
-            'PHL' => [
-                'content' => [
-                    'command' => 'PEDO',
-                ],
-                'kind' => 'send',
-                'content_custom' => true,
-                'need_back' => 1,
-            ],
-            'REMIND' => [
-                'content' => [
-                    'command' => 'REMIND',
-                ],
-                'kind' => 'send',
-                'content_custom' => true,
-                'need_back' => 1,
-            ],
-            'SILENCETIME2' => [
-                'content' => [
-                    'command' => 'SILENCETIME2',
-                ],
-                'kind' => 'send',
-                'content_custom' => true,
-                'need_back' => 1,
-            ],
-            'BOOTOFF' => [
-                'content' => [
-                    'command' => 'BOOTOFF',
-                    'is_open' => '',
-                    'bootup_time' => '',
-                    'shutdown_time' => '',
-                ],
-                'kind' => 'send',
-                'need_back' => 1,
-            ],
-            'REMOVE' => [
-                'content' => [
-                    'command' => 'REMOVE',
-                    'is_open' => '',
-                ],
-                'kind' => 'send',
-                'need_back' => 1,
-            ],
-            //平台回复
-            'LK' => [
-                'content' => [
-                    'command' => 'LK',
-                ],
-                'kind' => 'back',
-            ],
-            'PING' => [
-                'content' => [
-                    'command' => 'PING',
-                    'isbind' => 1,
-                ],
-                'kind' => 'back',
-            ],
-            'KA' => [
-                'content' => [
-                    'command' => 'KA',
-                ],
-                'kind' => 'back',
-            ],
-            'TEMP' => [
-                'content' => [
-                    'command' => 'temp',
-                ],
-                'kind' => 'back',
-            ],
-            'BPHRT' => [
-                'content' => [
-                    'command' => 'bphrt',
-                ],
-                'kind' => 'back',
-            ],
-            'HEART' => [
-                'content' => [
-                    'command' => 'heart',
-                ],
-                'kind' => 'back',
-            ],
-            'BLOOD' => [
-                'content' => [
-                    'command' => 'blood',
-                ],
-                'kind' => 'back',
-            ],
-            'OXYGEN' => [
-                'content' => [
-                    'command' => 'oxygen',
-                ],
-                'kind' => 'back',
-            ],
-            'AL' => [
-                'content' => [
-                    'command' => 'AL',
-                ],
-                'kind' => 'back',
-            ],
-        ];
-        if (!isset($data[$command])) {
-            return false;
-        }
-        return $data[$command];
-    }
+
     /**
      * 设置可解析数据 终端发送信息解析
      *
@@ -576,6 +372,26 @@ class SouhuanAnalysis
                 'content' => null,
                 'kind' => 'tback',
             ],
+            'HRTSART' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tback',
+            ],
+            'WDSTART' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tback',
+            ],
+            'BLDSTART' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tback',
+            ],
+            'OXSTART' => [
+                'analysis_digit' => null,
+                'content' => null,
+                'kind' => 'tback',
+            ],
             'CR' => [
                 'analysis_digit' => null,
                 'content' => null,
@@ -652,68 +468,7 @@ class SouhuanAnalysis
         }
         return $data[$command];
     }
-    /**
-     * 获取回复权重
-     *
-     * @param  [type] $command
-     * @return void
-     * @author wj
-     * @date 2023-08-11
-     */
-    public function getsendweight($command)
-    {
-        $weight = -1;
-        switch ($command) {
-            case 'POWEROFF':
-                //关机
-                $weight = 99;
-                break;
-            case 'RESET':
-                //重启
-                $weight = 98; //硬件未测试
-                break;
-            //平台回复命令
-            case 'AL':
-            case 'KA':
-            case 'LK':
-            case 'PING':
-            case 'BPHRT':
-            case 'TEMP':
-            case 'HEART':
-            case 'BLOOD':
-            case 'OXYGEN':
-                $weight = 1;
-                break;
-            //平台发送命令
-            case 'ZONE':
-            case 'UPLOAD':
-            case 'CR':
-            case 'SLEEPTIME':
-            case 'FALLDOWN':
-            case 'FACTORY':
-            case 'SOS':
-            case 'VERNO':
-            case 'LOWBAT':
-            case 'POWEROFF':
-            case 'LSSET':
-            case 'PEDO':
-            case 'PHL':
-            case 'REMIND':
-            case 'SILENCETIME2':
-            case 'BOOTOFF':
-            case 'REMOVE':
-                $weight = 0;
-                break;
-            default:
-                $weight = -1;
-                break;
-        }
-        if ($weight < 0) {
-            //不需设置 发送信息
-            return false;
-        }
-        return $weight;
-    }
+
     /**
      * 获取数据值
      *
@@ -1152,288 +907,6 @@ class SouhuanAnalysis
         }
         return true;
     }
-
-    /**
-     * 创建发送信息
-     *
-     * @param  [type] $data
-     * @param  [type] $command
-     * @return void
-     * @author wj
-     * @date 2023-08-14
-     * $data =['command'=>'','content_arr'=>[],]
-     */
-    public function createsendmsg($facility_id, $device_id_code, $data, $param = [])
-    {
-        $command = $data['command'];
-        $infoarr = $this->getsendcommandinfo($command);
-        if (!$infoarr) {
-            // Log::write("无对应命令数据1:" . $command, 'shouhuan');
-            // Log::write($data, 'shouhuan');
-            return false;
-        }
-        $content_arr = $data['content_arr'];
-        $config = $infoarr;
-        $m_ssl = new ShsendlistModel();
-        $commandxy = "3G";
-        //仅创建
-        if ($command == 'AL') {
-            $msg_type = 1;
-        } else {
-            $msg_type = 0;
-        }
-        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'];
-            $content_custom = isset($config['content_custom']) ? $config['content_custom'] : false;
-            $need_back = $config['need_back'];
-            if ($content_custom) {
-                $functionname = 'get' . $command . "Commandinfo";
-                if (method_exists($this, $functionname)) {
-                    $content = $useconmmand . "," . $this->$functionname($param);
-                } else {
-                    throw new \Exception($command . "自定义方法不存在");
-                }
-            } else {
-                $content = implode(',', $content_arr);
-            }
-            $send_type = 1;
-            if ($need_back) {
-                $is_success = 0;
-            } else {
-                $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,
-        ];
-        $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;
-    }
-    /**
-     * 创建sos电话设置命令
-     * 最多三个电话
-     *
-     * @return void
-     * @author wj
-     * @date 2023-08-21
-     */
-    public function getSOSCommandinfo($param)
-    {
-        if (count($param) <= 0) {
-            throw new \Exception("未设置电话");
-
-        }
-        if (count($param) > 3) {
-            throw new \Exception("设置电话数量过多");
-
-        }
-        foreach ($param as $key => $value) {
-            //判断是否为手机号
-            //暂不处理
-        }
-        $info = implode(",", $param);
-        return $info;
-    }
-    /**
-     * 设置跌倒灵敏度命令
-     * [3G*358800006072996*0009*LSSET,3+6]
-     *
-     * @return void
-     * @author wj
-     * @date 2023-08-21
-     */
-    public function getLSSETCommandinfo($param)
-    {
-        if (2 != count($param)) {
-            throw new \Exception("LSSET参数错误");
-        }
-        foreach ($param as $key => $value) {
-            if (!is_numeric($value)) {
-                throw new \Exception("LSSET参数错误:" . $value);
-            }
-        }
-        $info = $param[0] . "+" . $param[1];
-        return $info;
-    }
-    /**
-     * 设置电话本
-     * 最多10条
-     *[{telno=>'',name=>''}]
-     * @param  [type] $param
-     * @return void
-     * @author wj
-     * @date 2023-08-21
-     */
-    public function getPHLCommaninfo($param)
-    {
-        if (50 < count($param)) {
-            throw new \Exception("PHL参数错误");
-        }
-        if (0 != count($param) % 2) {
-            throw new \Exception("PHL参数长度错误");
-        }
-        $usedata = [];
-        foreach ($param as $key => $value) {
-            $telno = $value['telno'];
-            $name = $value['name'];
-            //电话号码
-            if (20 < mb_strlen($telno)) {
-                throw new \Exception("PHL电话号码错误:" . $telno);
-            }
-            $name = $this->srtingToUnicode($name);
-            $usedata[] = $telno;
-            $usedata[] = $name;
-        }
-        $info = implode(",", $usedata);
-        return $info;
-    }
-    /**
-     * 设置电话本
-     * 最多10条
-     *{[time=>'',isopen=>'','type'=>'','weeks'=>[]]}
-     *  weeks 数组 每个1到7 周日到周六
-     * 最多设置三个
-     * @param  [type] $param
-     * @return void
-     * @author wj
-     * @date 2023-08-21
-     */
-    /*
-    08:10-1-1:闹钟时间 8:10,打开,响铃一次
-    08:10-1-2:闹钟时间 8:10,打开,每天响铃
-    08:10-1-3-0111110:闹钟时间 8:10,打开,自定义周一至周五打开
-    最左边是周日,最右边是周六,即 0111110 的顺序是:周日,周一,周二,周三,周四,周五,周
-    六(1 为打开,0 为关闭),其中周一至周五打开闹钟
-     */
-    public function getREMINDCommandinfo($param)
-    {
-        if (3 > count($param)) {
-            throw new \Exception("PHL参数错误");
-        }
-        $usedata = [];
-        foreach ($param as $key => $value) {
-            $useweeks = ["0", "0", "0", "0", "0", "0", "0"];
-            $time = $this->formattime($value['time'], 'H:i');
-            $isopen = $value['isopen'];
-            $type = $value['type'];
-            $weeks = $value['weeks'];
-            if (3 == $type) {
-                foreach ($weeks as $wkey => $wvalue) {
-                    if ($wvalue >= 1 && $wvalue <= 7) {
-                        $useweeks[$wvalue - 1] = '1';
-                    }
-                }
-                $useweeks = implode("", $useweeks);
-                $type = $useweeks;
-            }
-            $usedata[] = $time . "-" . $isopen . "-" . $type;
-        }
-        $usedata = implode(",", $usedata);
-        return $usedata;
-    }
-    /**
-     * 静默时间段测试
-     *{[starttime=>'',endtime=>'',isopen=>'',weeks=>[]]}
-     * weeks 数组 每个1到7 周日到周六
-     * 最多设置三个
-     *
-     * @return void
-     * @author wj
-     * @date 2023-08-21
-     */
-    /*
-    [DW*334588000000156*0038*SILENCETIME2,7:30-21:10-1-0111110,7:30-21:10-1-0111110,7:
-    30-21:10-0-0111110]
-    设置上课禁用时间段范围,拦截终端的任何来电。格式为“起始时间-结束时间-自定义星期几”, 比
-    如上面的 7:30-21:00-0111110,则表示周一到周五 7:30 到 21:00 之间上课禁用生效,起始时间
-    默认大于结束时间。
-    总开关:0 为关,1 为开
-    关于自定义星期几的规则:最左边是周日,最右边是周六,即 0111110 的顺序是:周日,周一,周
-    二,周三,周四,周五,周六(1 为打开,0 为关闭),所以上面的意思是周一至周五打开上课禁
-    用。
-     */
-    public function getSILENCETIME2Commandinfo($param)
-    {
-        if (3 <= count($param)) {
-            throw new \Exception("SILENCETIME2参数错误");
-        }
-        $usedata = [];
-        foreach ($param as $key => $value) {
-            $useweeks = ["0", "0", "0", "0", "0", "0", "0"];
-            //未比较时间大小
-            $starttime = $this->formattime($value['starttime'], 'H:i');
-            $endtime = $this->formattime($value['endtime'], 'H:i');
-            $isopen = $value['isopen'];
-            $weeks = $value['weeks'];
-            foreach ($weeks as $wkey => $wvalue) {
-                if ($wvalue >= 1 && $wvalue <= 7) {
-                    $useweeks[$wvalue - 1] = '1';
-                }
-            }
-            $useweeks = implode("", $useweeks);
-            $usedata[] = $starttime . "-" . $endtime . "-" . $isopen . "-" . $useweeks;
-        }
-        $usedata = implode(",", $usedata);
-        return $usedata;
-    }
-    /**
-     * 睡眠时间段设置
-     *{starttime=>'',endtime=>''}
-     *
-     * @return void
-     * @author wj
-     * @date 2023-08-21
-     */
-    public function getSLEEPTIMECommandinfo($param)
-    {
-        if (2 > count($param)) {
-            throw new \Exception("SLEEPTIME参数错误");
-        }
-        $starttime = $this->formattime($param['starttime'], 'H:i');
-        $endtime = $this->formattime($param['endtime'], 'H:i');
-        $usedata = $starttime . "-" . $endtime;
-        return $usedata;
-    }
     //发送完处理
     /**
      * 发送成功 删除发送数据
@@ -1571,26 +1044,6 @@ class SouhuanAnalysis
         }
     }
     //工具方法
-    /**
-     * unicode 编码
-     *
-     * @param  [type] $str
-     * @return void
-     * @author wj
-     * @date 2023-08-21
-     */
-    public function srtingToUnicode($str)
-    {
-        $unicode = '';
-        $arr = mb_str_split($str); //适配中文
-        foreach ($arr as $key => $value) {
-            $char = bin2hex(iconv('UTF-8', 'UCS-2BE', $value));
-            $char = str_pad($char, 4, '0', STR_PAD_LEFT);
-            $arr[$key] = $char;
-        }
-        $unicode = implode("", $arr);
-        return $unicode;
-    }
     /**
      * unicode 解码
      *
@@ -1641,41 +1094,4 @@ class SouhuanAnalysis
         }
         return $arr;
     }
-
-    public function formattime($time, $format)
-    {
-        $time = strtotime($time);
-        $time = date($format, $time);
-        return $time;
-    }
-
-    //设备初始化
-    public function facilityinit($facility_id, $device_id_code)
-    {
-        $m_f = new FacilityModel();
-        $fwhere = [
-            'id' => $facility_id,
-            'code' => $device_id_code,
-            'kind' => 1,
-            'status' => 1,
-        ];
-        $finfo = $m_f->getInfo($fwhere);
-        if (!$finfo) {
-            throw new \Exception("无对应信息:" . $facility_id . "-" . $device_id_code);
-        }
-        $commandlist = [
-            ['command' => 'ZONE', 'content_arr' => ['command' => 'ZONE', 'zone' => 8]],
-            ['command' => 'UPLOAD', 'content_arr' => ['command' => 'UPLOAD', 'interval' => 60]],
-            ['command' => 'CR', 'content_arr' => ['command' => 'CR']],
-            ['command' => 'FALLDOWN', 'content_arr' => ['command' => 'FALLDOWN', 'is_open' => 1]],
-            ['command' => 'VERNO', 'content_arr' => ['command' => 'VERNO']],
-            ['command' => 'LOWBAT', 'content_arr' => ['command' => 'LOWBAT', 'is_open' => 1]],
-            ['command' => 'PEDO', 'content_arr' => ['command' => 'PEDO', 'is_open' => 1]],
-            ['command' => 'REMOVE', 'content_arr' => ['command' => 'REMOVE', 'is_open' => 1]],
-        ];
-        foreach ($commandlist as $key => $value) {
-            $this->createsendmsg($facility_id, $device_id_code, $value);
-        }
-    }
-
 }