123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- namespace Home\Controller;
- use Think\Controller;
- use Think\Cache\Driver;
- class RtuwarnController extends PushWarnController
- {
- public function message_rtu()
- {
- $Data = I();
- //日志打印
- $filename_log = "/var/www/html/jdxf/log/rtu_b_log" . date("Y-m-d") . ".log";
- $this->printing_log($Data, $filename_log);
- //需要用到的参数
- $device_code = $Data['id'];
- $unique_number = $Data['unique_number'] . $Data['types'];
- $insert_id = $Data['insert_id'];
- $remarks = $Data['bz'];
- $types = $Data['types'];
- $time = $Data['time'];
- if (empty($insert_id) || empty($device_code) || empty($types) || empty($unique_number)) {
- echo '缺少重要参数,请检查推送代码!';
- exit();
- }
- if ($types == '离线') {
- $where = " AND data2 like '%5%'";
- } else {
- $where = " AND data2 like '%4%'";
- }
- //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();
- }
- $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);
- $openids = $this->array_column1($union_sql, "phone");
- if (empty($openids)) {
- echo 'open is null';
- exit;
- }
- $op = M()->query("SELECT openid FROM sp_wx_customuser WHERE type='wx' and idphone in(" . $openids . ")");
- $status11 = M()->query("SELECT statustime FROM sp_devices_status where deviceid='" . $device_code . "'");
- $access_token = GetAccess_Token1();
- $address = '警报地址:' . $data[0]['owner_address'] . $data[0]['unitinfo'];
- $type = $types;
- //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/6/id/" . $insert_id;
- if ($if_push == 1) {
- foreach ($op as $key => $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/rtu_t_log" . date("Y-m-d") . ".log";
- $this->printing_log($R, $filename_log);
- print_r($R);
- }
- }
- }
- }
- }
|