VideowarnController.class.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/4/30 0030
  6. * Time: 上午 9:53
  7. */
  8. namespace Home\Controller;
  9. use Think\Controller;
  10. include '../Common/function.php';
  11. class VideowarnController extends PushWarnController
  12. {
  13. public function message_voice()
  14. {
  15. $Data = I();
  16. //日志打印
  17. $filename_log = "/var/www/html/jdxf/log/video_b_log" . date("Y-m-d") . ".log";
  18. $this->printing_log($Data, $filename_log);
  19. //需要用到的参数
  20. $device_code = $Data['device_code'];
  21. $unique_number = $device_code;
  22. $insert_id = $Data['insert_id'];
  23. $remarks = $Data['bz'];
  24. $time = $Data['time'];
  25. $evt_name = $Data['evt_name'];
  26. $where = " AND data2 like '%8%'";
  27. if (empty($insert_id) || empty($device_code) || empty($evt_name) || empty($unique_number)) {
  28. echo '缺少重要参数,请检查推送代码!';
  29. exit();
  30. }
  31. //3小时以内相同设备报警未处理则不推送;
  32. $redis = new \Redis();
  33. $result = $redis->connect('127.0.0.1', 6379);
  34. $if_push = 1;
  35. if ($result == 1) {
  36. $res = $redis->get("$unique_number");
  37. if ($res == 1) {
  38. $if_push = 1;
  39. } else if (!empty($res)) {
  40. if (floor((strtotime($Data['time']) - strtotime($res)) / 3600) > 3) {
  41. $if_push = 1;
  42. } else {
  43. $if_push = 0;
  44. }
  45. } else {
  46. $if_push = 1;
  47. }
  48. $redis->get("$unique_number");
  49. $redis->set("$unique_number", "$time");
  50. $redis->close();
  51. }
  52. $data = M()->query("select s.push_param2,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 . "'");
  53. $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);
  54. $openids = $this->array_column1($union_sql, "phone");
  55. if (empty($openids)) {
  56. echo 'open is null';
  57. exit;
  58. }
  59. $op = M()->query("SELECT openid FROM sp_wx_customuser WHERE type='wx' and idphone in($openids)");
  60. $status11 = M()->query("SELECT time FROM sp_video2017 where id='" . $insert_id . "'");
  61. $access_token = GetAccess_Token1();
  62. $address = '警报地址:' . $data[0]['owner_address'] . $data[0]['unitinfo'];
  63. //keyword3.DATA
  64. if (empty($time)) {
  65. $time = $status11[0]['time'];
  66. }
  67. //remark.DATA
  68. if (empty($remarks)) {
  69. $remarks = '设备名称:' . $data[0]['owner_name'];
  70. }
  71. if ($data[0]['company'] == "11111") {
  72. $url = "https://qhome.usky.cn/jdxf/wxapp7.php/Home/Fireinfo/index/type/16/id/" . $insert_id . "/zdid/" . $data[0]['push_param2'];
  73. $access_token2 = GetAccess_Token2();
  74. foreach ($op as $key => $o) {
  75. if (!empty($o['openid'])) {
  76. $R = $this->SendDeviceAlarm3($access_token2, $o['openid'], $address, $device_code, $evt_name, $time, $remarks, $url);
  77. print_r($R);
  78. }
  79. }
  80. } else {
  81. $url = "https://iot.usky.cn/jdxf/wxapp2.php/Home/Fireinfo/index/type/16/id/" . $insert_id;
  82. if ($if_push == 1) {
  83. foreach ($op as $key => $o) {
  84. if (!empty($o['openid'])) {
  85. $R = $this->SendDeviceAlarm($access_token, $o['openid'], $address, $device_code, $evt_name, $time, $remarks, $url);
  86. $filename_log = "/var/www/html/jdxf/log/video_t_log" . date("Y-m-d") . ".log";
  87. $this->printing_log($R, $filename_log);
  88. print_r($R);
  89. }
  90. }
  91. }
  92. }
  93. }
  94. }