"09", * "IMEI" => 设备编号, * "DateTime" => 时间, * "Interval" => 间隔时间, * "Status" => 状态, * "Battery" => 电量, * "Signal" => 信号, * "Unit" => 单位, * "Pressure" => 水压值, * "phone" => 电话, * "insert_id" => 插入表id * @return [type] [description] */ public function message_level() { $Data = I(); //日志打印 $filename_log = "/var/www/html/jdxf/log/level_b_log" . date("Y-m-d") . ".log"; $this->printing_log($Data, $filename_log); //需要用到的参数 if (!empty($Data['IMEI'])) { $device_code = $Data['IMEI']; } else if (!empty($Data['IEMI'])) { $device_code = $Data['IEMI']; } $unique_number = $device_code; $insert_id = $Data['insert_id']; $remarks = $Data['bz']; $time = $Data['time']; $evt_name = $Data['evt_c']; $evt = $Data['Status']; if (empty($insert_id) || empty($device_code) || empty($types) || empty($unique_number)) { echo '缺少重要参数,请检查推送代码!'; exit(); } //3小时以内相同设备报警未处理则不推送; $redis = new \Redis(); $result = $redis->connect('127.0.0.1', 6379); $if_push = 1; if ($result == 1) { $res = $redis->get("$unique_number"); if ($res == 1) { $if_push = 1; } else if (!empty($res)) { if (floor((strtotime($Data['time']) - strtotime($res)) / 3600) > 3) { $if_push = 1; } else { $if_push = 0; } } else { $if_push = 1; } $redis->get("$unique_number"); $redis->set("$unique_number", "$time"); $redis->close(); } switch ($evt) { case 'LL0': $status = '正常'; $where = " AND data2 like '%3%'"; break; case 'LL1': $status = '低水位'; $where = " AND data2 like '%3%'"; break; case 'LL2': $status = '高水位'; $where = " AND data2 like '%3%'"; break; case 'LL3': $status = '故障'; $where = " AND data2 like '%3%'"; break; case 'LL4': $status = '离线'; $where = " AND data2 like '%5%'"; break; case 'LL5': $status = '波动告警'; $where = " AND data2 like '%3%'"; break; default: $status = '其他' . $Data['Status']; $where = " AND data2 like '%3%'"; break; } if (!empty($evt_name)) { $status = $evt_name; } $data = M()->query("select s.owner_name,s.unitinfo,s.company,c.owner_address from sp_owner s ,sp_owner_company c where s.company=c.owner_id and s.owner_code ='" . $device_code . "'"); $union_sql = M()->query("select phone from sp_owner_phone WHERE owner_code='" . $data[0]['company'] . "' " . $where . " union select phone from sp_owner_phone WHERE owner_code in (select other_code from sp_owner_fujin where owner_code='" . $data[0]['company'] . "') " . $where); if (count($union_sql) == 0) { echo "phone is null"; exit; } $openids = $this->array_column1($union_sql, "phone"); if (empty($openids)) { echo 'open is null'; exit; } $status11 = M()->query("SELECT statustime FROM sp_devices_status where deviceid='" . $device_code . "'"); $op = M()->query("SELECT openid FROM sp_wx_customuser WHERE type='wx' and idphone in($openids)"); $access_token = GetAccess_Token1(); $address = '警报地址:' . $data[0]['owner_address'] . $data[0]['unitinfo']; $type = $status; if (empty($time)) { $time = $status11[0]['statustime']; } //remark.DATA if (empty($remarks)) { $remarks = '设备名称:' . $data[0]['owner_name']; } $url = "https://iot.usky.cn/jdxf/wxapp2.php/Home/Fireinfo/index/type/2/id/" . $insert_id; if ($if_push == 1) { foreach ($op as $o) { if (!empty($o['openid'])) { $R = $this->SendDeviceAlarm($access_token, $o['openid'], $address, $device_code, $type, $time, $remarks, $url); $filename_log = "/var/www/html/jdxf/log/level_t_log" . date("Y-m-d") . ".log"; $this->printing_log($R, $filename_log); print_r($R); } } } } }