123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace Home\Controller;
- use Think\Controller;
- use Think\Cache\Driver;
- include '../Common/function.php';
- class AccessControlwarnController extends PushWarnController
- {
- public function message_access_control()
- {
- $Data = I('post.');
- //日志打印
- $filename_log = "/var/www/html/jdxf/log/access_control_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 = $Data['evt'];
- if (empty($insert_id) || empty($device_code) || empty($evt) || 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 'gs01':
- $status = '可燃气体告警';
- // $where=" AND data2 like '%6%'";
- break;
- case 'gs02':
- $status = '电池电量低';
- // $where=" AND data2 like '%6%'";
- break;
- case 'gs03':
- $status = '设备防拆';
- // $where=" AND data2 like '%6%'";
- break;
- default:
- $status = '其他' . $Data['evt'];
- $where = " AND data2 like '%6%'";
- break;
- }
- $data = M()->query("select s.owner_name,s.unitinfo,s.company,c.owner_address,s.dwtype 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 "phonr 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;
- //keyword3.DATA
- 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/130/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/access_control_t_log" . date("Y-m-d") . ".log";
- $this->printing_log($R, $filename_log);
- print_r($R);
- }
- }
- }
- }
- }
|