123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace Home\Controller;
- use Think\Controller;
- use Think\Cache\Driver;
- class RtuwarnController extends PushWarnController
- {
- /**
- *
- * @return [type] [description]
- */
- public function message_sendalarm()
- {//用户传输设备微信推送
- $Data = I();
- $log = "[时间" . date("Y-m-d H:i:s") . "]报警数据:" . json_encode($Data) . "\r\n";
- $filename_log = "/var/www/html/jdxf/log/rtu_log" . date("Y-m-d") . ".log";
- file_put_contents($filename_log, $log, FILE_APPEND | LOCK_EX);
- if (empty($Data['id'])) {
- echo 'phone is null';
- exit;
- }
- if ($Data['types'] == '离线') {
- $where = " AND data2 like '%5%'";
- } else {
- $where = " AND data2 like '%4%'";
- }
- $insert_id = $Data['insert_id'];
- $user_from = $Data['user_from'];
- $bz = $Data['bz'];
- //3小时以内相同设备报警未处理则不推送;
- $time = $Data['time'];
- $unique_number = $Data['unique_number'].$Data['types'];
- $redis = new \Redis();
- $result = $redis->connect('47.98.201.73', 6379);
- $pd = 1;
- print_r($unique_number);
- if ($result == 1) {
- $res = $redis->get("$unique_number");
- print_r('$res='.$res);
- if ($res == 1) {
- // echo "1----";
- $pd = 1;
- } else if (!empty($res)) {
- // echo "2----".floor((strtotime($Data['time'])-strtotime($res))%86400/3600);
- if (floor((strtotime($Data['time']) - strtotime($res)) / 3600) > 3) {
- // echo "2.1----";
- $pd = 1;
- } else {
- echo "2.2----";
- $pd = 0;
- }
- } else {
- // echo "3----";
- $pd = 1;
- }
- $res1 = $redis->get("$unique_number");
- var_dump($res);
- $redis->set("$unique_number", "$time");
- $redis->close();
- }
- if ($Data['id']=='4023363030303537'){
- $pd = 1;
- }
- $company = 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 ='" . $Data['id'] . "'");
- $union_sql = M()->query("select phone from sp_owner_phone WHERE owner_code='" . $company[0]['company'] . "' " . $where . " union select phone from sp_owner_phone WHERE owner_code in (select other_code from sp_owner_fujin where owner_code='" . $company[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='" . $Data['id'] . "'");
- $access_token = GetAccess_Token1();
- $address = '警报地址:' . $company[0]['owner_address'] . $company[0]['unitinfo'];
- $deviceid = $Data['id'];
- $type = $Data['types'];
- $time = $status11[0]['statustime'];
- if (!empty($Data['time'])) {
- $time = $Data['time'];
- }
- // $remark='设备名称:'.$company[0]['owner_name'];
- if (!empty($bz)) {
- $remark = $bz;
- } else {
- $remark = '设备名称:' . $company[0]['owner_name'];
- }
- if ($Data['id'] == '4023383030303836' || $Data['id'] == '4023383030303835' || $Data['id'] == '4023383030303834' || $Data['id'] == '4023383030303833' || $Data['id'] == '4023383030303832'
- || $Data['id'] == '4023383030303831' || $Data['id'] == '4023383030303830' || $Data['id'] == '4023383030303739') {
- // $ljurl = "https://iot.usky.cn/jdxf/wxapp2.php/Home/Fireinfo/index/type/6/id/" . $insert_id;
- $ljurl = "https://iot.usky.cn/jdxf/wxapp5.php/Home/Fireinfo/index/type/6/id/" . $insert_id;
- } else {
- $ljurl = "https://qhome.usky.cn/jdxf/wxapp2.php/Home/Fireinfo/index/type/6/id/" . $insert_id;
- }
- print_r($ljurl);
- if ($pd == 1) {
- foreach ($op as $key => $o) {
- if (!empty($o['openid'])) {
- //{{remark.DATA}}$remark
- $Message = $this->SendDeviceAlarm($access_token, $o['openid'], $address, $deviceid, $type, $time, $remark, $ljurl, $url = '');
- $log = "[时间" . date("Y-m-d H:i:s") . "]报警数据:" . json_encode($Message) . "\r\n";
- $filename_log = "/var/www/html/jdxf/log/rtu_fh_log" . date("Y-m-d") . ".log";
- file_put_contents($filename_log, $log, FILE_APPEND | LOCK_EX);
- print_r($Message);
- }
- }
- }
- }
- }
|