idcol_alarm_info_send.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. ini_set('display_errors', 1);
  3. // idcol 故障信息推送
  4. require_once './DB.php';
  5. require_once './config.php';
  6. date_default_timezone_set('Asia/Shanghai');
  7. $config = json_decode(file_get_contents('./db_config.php'),true);
  8. // 发送邮件
  9. function send_email($to,$msg,$title = '维修通知'){
  10. // $this->load->library('Smtp');
  11. require_once './Smtp.php';
  12. $config = array();
  13. $config['protocol'] = 'smtp';
  14. $config['smtp_host'] = 'smtpdm.aliyun.com';
  15. $config['user_email'] = 'admin@lampmind.com';
  16. $config['smtp_user'] = 'admin@lampmind.com';
  17. $config['smtp_pass'] = 'wecloudsSMTP2018';
  18. $config['smtp_port'] = 80;
  19. $config['smtp_timeout'] = 30;
  20. $config['crlf'] = "\r\n";
  21. $config['newline'] = "\r\n";
  22. $config['mailtype'] = "html";
  23. //******************** 配置信息 ********************************
  24. // $config = $config['email'];
  25. $smtpserver = $config['smtp_host'];//SMTP服务器
  26. $smtpserverport = $config['smtp_port'];//SMTP服务器端口
  27. $smtpusermail = $config['user_email'];//SMTP服务器的用户邮箱
  28. $smtpemailto = $to;//发送给谁
  29. $smtpuser = $config['smtp_user'];//SMTP服务器的用户帐号,注:部分邮箱只需@前面的用户名
  30. $smtppass = $config['smtp_pass'];//SMTP服务器的用户密码
  31. $mailtitle = $title;//邮件主题
  32. $mailcontent = $msg;//邮件内容
  33. $mailtype = "HTML";//邮件格式(HTML/TXT),TXT为文本邮件
  34. //************************ 配置信息 ****************************
  35. $smtp = new Smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
  36. $smtp->debug = false;//是否显示发送的调试信息
  37. return $smtp->sendmail($smtpemailto, $smtpusermail, $mailtitle, $mailcontent, $mailtype);
  38. }
  39. // 故障信息
  40. $batstatusArr = array('1'=>'Overdischarge','2'=>'Over Charge','3'=>'High temperature','4'=>'Battery overtemperature');
  41. $panelstatusArr = array('1'=>'Less than the optiocally controlled voltage','2'=>'greate than the optiocally controlled voltage','3'=>'greater than the battery voltage');
  42. $lampstatusArr = array('1'=>'open circuit','2'=>'short circuit','3'=>'overload','4'=>'Lamp overtemperature');
  43. $tempstatusArr = array('1'=>'Charge high temperature','2'=>'Charge over temperature','3'=>'Discharge high temperature','4'=>'Discharge over temperature');
  44. $onlinestatusArr = array('1'=>'Offline failure');
  45. while (1) {
  46. $beginTime = time();
  47. $beginDate = date('H:i',$beginTime);
  48. if (1) {
  49. // $db = new Db($config);
  50. // $lampList = $db->query('select W.id,W.batstatus,W.panelstatus,W.lampstatus,W.tempstatus,W.onlinestatus,L.projectid,P.projectname,L.number,L.address,L.section,L.lighteness,L.lampvoltage,L.lampcurrent,L.lamppower,L.netstatus,L.softwareVersion,L.iccid,L.updatetime from warning_info_log W left join lampinfo L on W.lampid = L.id left join project P on L.projectid = P.id where W.is_send = 0 and L.id is not null and P.id is not null and W.status = 0');
  51. // $temp_send = [];
  52. // if (!empty($lampList)) {
  53. // foreach ($lampList as $key => $value) {
  54. // $userList = $db->query('select email,id from alarm_send_user_info where is_send = 1 and FIND_IN_SET('.$value['projectid'].',project)');
  55. // // $msg = "The device located in project:{$value['hotelName']}->number:{$value['buildName']} appears <span style='color:red;'>{$value['stralarmtype']}</span>, please confirm as soon as possible. If repaired, please ignore it! Thank you for your cooperation! [login www.iotena-web.com to see details]";
  56. // $alarmArr = array();
  57. // if (!empty($value['batstatus']) && isset($batstatusArr[$value['batstatus']])) $alarmArr[] = $batstatusArr[$value['batstatus']];
  58. // if (!empty($value['panelstatus']) && isset($panelstatusArr[$value['panelstatus']])) $alarmArr[] = $panelstatusArr[$value['panelstatus']];
  59. // if (!empty($value['lampstatus']) && isset($lampstatusArr[$value['lampstatus']])) $alarmArr[] = $lampstatusArr[$value['lampstatus']];
  60. // if (!empty($value['tempstatus']) && isset($tempstatusArr[$value['tempstatus']])) $alarmArr[] = $tempstatusArr[$value['tempstatus']];
  61. // if (!empty($value['onlinestatus']) && isset($onlinestatusArr[$value['onlinestatus']])) $alarmArr[] = $onlinestatusArr[$value['onlinestatus']];
  62. // if (!empty($alarmArr)) {
  63. // $stralarmtype = implode(',',$alarmArr);
  64. // $msg = '';
  65. // $msg .= '<table border="1" cellpadding="2" cellspacing="0">';
  66. // $msg .= '<tr>';
  67. // $msg .= '<td>Project name</td>';
  68. // $msg .= '<td>'.$value['projectname'].'</td>';
  69. // $msg .= '<td>Lamp number</td>';
  70. // $msg .= '<td>'.$value['number'].'</td>';
  71. // $msg .= '<td>Wireless module address</td>';
  72. // $msg .= '<td>'.$value['address'].'</td>';
  73. // $msg .= '<td>Road</td>';
  74. // $msg .= '<td>'.$value['section'].'</td>';
  75. // $msg .= '</tr>';
  76. // $msg .= '<tr>';
  77. // $msg .= '<td>Brightness</td>';
  78. // $msg .= '<td>'.$value['lighteness'].'%</td>';
  79. // $msg .= '<td>Lamp voltage</td>';
  80. // $msg .= '<td>'.$value['lampvoltage'].'V</td>';
  81. // $msg .= '<td>Lamp current</td>';
  82. // $msg .= '<td>'.$value['lampcurrent'].'A</td>';
  83. // $msg .= '<td>Lamp power</td>';
  84. // $msg .= '<td>'.$value['lamppower'].'W</td>';
  85. // $msg .= '</tr>';
  86. // $netstatus = $value['netstatus'] == 0 ? 'Not online' : 'Online';
  87. // $updatetime = empty($value['updatetime']) ? date('Y-m-d H:i:s',time() - 4*3600) : date('Y-m-d H:i:s',strtotime($value['updatetime']) - 2*3600);
  88. // $msg .= '<tr>';
  89. // $msg .= '<td>Network status</td>';
  90. // $msg .= '<td>'.$netstatus.'</td>';
  91. // $msg .= '<td>Version information</td>';
  92. // $msg .= '<td>'.$value['softwareVersion'].'</td>';
  93. // $msg .= '<td>ICCID</td>';
  94. // $msg .= '<td>'.$value['iccid'].'</td>';
  95. // $msg .= '<td>Update time</td>';
  96. // $msg .= '<td>'.$updatetime.'</td>';
  97. // $msg .= '</tr>';
  98. // $msg .= '</table>';
  99. // $msg .= "The device located in project:{$value['projectname']}->number:{$value['number']} appears <span style='color:red;'>{$stralarmtype}</span>, please confirm as soon as possible. If repaired, please ignore it! Thank you for your cooperation!";
  100. // foreach ($userList as $user) {
  101. // if (!empty($user['email'])) {
  102. // if (!empty($value['onlinestatus'])) {
  103. // if ($value['netstatus'] == 0) {
  104. // if (isset($temp_send[$user['id']])) {
  105. // $temp_send[$user['id']]['msg'] .= $msg;
  106. // }else{
  107. // $user['msg'] = $msg;
  108. // $temp_send[$user['id']] = $user;
  109. // }
  110. // // send_email($user['email'],$msg,'Alarm info');
  111. // }
  112. // }else{
  113. // if (isset($temp_send[$user['id']])) {
  114. // $temp_send[$user['id']]['msg'] .= $msg;
  115. // }else{
  116. // $user['msg'] = $msg;
  117. // $temp_send[$user['id']] = $user;
  118. // }
  119. // // send_email($user['email'],$msg,'Alarm info');
  120. // }
  121. // }
  122. // }
  123. // }
  124. // $db->table('warning_info_log')->where('id='.$value['id'])->update(['is_send'=>1]);
  125. // }
  126. // }
  127. $file = fopen('./alarm_info.txt', 'w+');
  128. fwrite($file, $value['msg'].'----'.date('Y-m-d H:i:s',time()).'
  129. ');
  130. // if (!empty($temp_send)) {
  131. // foreach ($temp_send as $key => $value) {
  132. // fwrite($file, $value['msg'].'----'.date('Y-m-d H:i:s',time()).'
  133. // ');
  134. // fwrite($file, $value['email'].'----'.date('Y-m-d H:i:s',time()).'
  135. // ');
  136. // send_email($value['email'],$value['msg'],'Alarm info');
  137. // }
  138. // }
  139. fclose($file);
  140. $db->close();
  141. }
  142. $endDate = date('H:i',time());
  143. while ($beginDate == $endDate) {
  144. sleep(1);
  145. $endDate = date('H:i',time());
  146. }
  147. }
  148. ?>