123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- ini_set('display_errors', 1);
- // idcol 故障信息推送
- require_once './DB.php';
- require_once './config.php';
- date_default_timezone_set('Asia/Shanghai');
- $config = json_decode(file_get_contents('./db_config.php'),true);
- // 发送邮件
- function send_email($to,$msg,$title = '维修通知'){
- // $this->load->library('Smtp');
- require_once './Smtp.php';
- $config = array();
- $config['protocol'] = 'smtp';
- $config['smtp_host'] = 'smtpdm.aliyun.com';
- $config['user_email'] = 'admin@lampmind.com';
- $config['smtp_user'] = 'admin@lampmind.com';
- $config['smtp_pass'] = 'wecloudsSMTP2018';
- $config['smtp_port'] = 80;
- $config['smtp_timeout'] = 30;
- $config['crlf'] = "\r\n";
- $config['newline'] = "\r\n";
- $config['mailtype'] = "html";
- //******************** 配置信息 ********************************
- // $config = $config['email'];
- $smtpserver = $config['smtp_host'];//SMTP服务器
- $smtpserverport = $config['smtp_port'];//SMTP服务器端口
- $smtpusermail = $config['user_email'];//SMTP服务器的用户邮箱
- $smtpemailto = $to;//发送给谁
- $smtpuser = $config['smtp_user'];//SMTP服务器的用户帐号,注:部分邮箱只需@前面的用户名
- $smtppass = $config['smtp_pass'];//SMTP服务器的用户密码
- $mailtitle = $title;//邮件主题
- $mailcontent = $msg;//邮件内容
- $mailtype = "HTML";//邮件格式(HTML/TXT),TXT为文本邮件
- //************************ 配置信息 ****************************
- $smtp = new Smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
- $smtp->debug = false;//是否显示发送的调试信息
- return $smtp->sendmail($smtpemailto, $smtpusermail, $mailtitle, $mailcontent, $mailtype);
- }
- // 故障信息
- $batstatusArr = array('1'=>'Overdischarge','2'=>'Over Charge','3'=>'High temperature','4'=>'Battery overtemperature');
- $panelstatusArr = array('1'=>'Less than the optiocally controlled voltage','2'=>'greate than the optiocally controlled voltage','3'=>'greater than the battery voltage');
- $lampstatusArr = array('1'=>'open circuit','2'=>'short circuit','3'=>'overload','4'=>'Lamp overtemperature');
- $tempstatusArr = array('1'=>'Charge high temperature','2'=>'Charge over temperature','3'=>'Discharge high temperature','4'=>'Discharge over temperature');
- $onlinestatusArr = array('1'=>'Offline failure');
- while (1) {
- $beginTime = time();
- $beginDate = date('H:i',$beginTime);
-
- if (date('H:00',time() - 4*3600) == '09:00') {
- $db = new Db($config);
- $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');
- $temp_send = [];
- if (!empty($lampList)) {
-
- foreach ($lampList as $key => $value) {
- $userList = $db->query('select email,id from alarm_send_user_info where is_send = 1 and FIND_IN_SET('.$value['projectid'].',project)');
- // $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]";
- $alarmArr = array();
- if (!empty($value['batstatus']) && isset($batstatusArr[$value['batstatus']])) $alarmArr[] = $batstatusArr[$value['batstatus']];
- if (!empty($value['panelstatus']) && isset($panelstatusArr[$value['panelstatus']])) $alarmArr[] = $panelstatusArr[$value['panelstatus']];
- if (!empty($value['lampstatus']) && isset($lampstatusArr[$value['lampstatus']])) $alarmArr[] = $lampstatusArr[$value['lampstatus']];
- if (!empty($value['tempstatus']) && isset($tempstatusArr[$value['tempstatus']])) $alarmArr[] = $tempstatusArr[$value['tempstatus']];
- if (!empty($value['onlinestatus']) && isset($onlinestatusArr[$value['onlinestatus']])) $alarmArr[] = $onlinestatusArr[$value['onlinestatus']];
- if (!empty($alarmArr)) {
- $stralarmtype = implode(',',$alarmArr);
- $msg = '';
- $msg .= '<table border="1" cellpadding="2" cellspacing="0">';
- $msg .= '<tr>';
- $msg .= '<td>Project name</td>';
- $msg .= '<td>'.$value['projectname'].'</td>';
- $msg .= '<td>Lamp number</td>';
- $msg .= '<td>'.$value['number'].'</td>';
- $msg .= '<td>Wireless module address</td>';
- $msg .= '<td>'.$value['address'].'</td>';
- $msg .= '<td>Road</td>';
- $msg .= '<td>'.$value['section'].'</td>';
- $msg .= '</tr>';
- $msg .= '<tr>';
- $msg .= '<td>Brightness</td>';
- $msg .= '<td>'.$value['lighteness'].'%</td>';
- $msg .= '<td>Lamp voltage</td>';
- $msg .= '<td>'.$value['lampvoltage'].'V</td>';
- $msg .= '<td>Lamp current</td>';
- $msg .= '<td>'.$value['lampcurrent'].'A</td>';
- $msg .= '<td>Lamp power</td>';
- $msg .= '<td>'.$value['lamppower'].'W</td>';
- $msg .= '</tr>';
- $netstatus = $value['netstatus'] == 0 ? 'Not online' : 'Online';
- $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);
- $msg .= '<tr>';
- $msg .= '<td>Network status</td>';
- $msg .= '<td>'.$netstatus.'</td>';
- $msg .= '<td>Version information</td>';
- $msg .= '<td>'.$value['softwareVersion'].'</td>';
- $msg .= '<td>ICCID</td>';
- $msg .= '<td>'.$value['iccid'].'</td>';
- $msg .= '<td>Update time</td>';
- $msg .= '<td>'.$updatetime.'</td>';
- $msg .= '</tr>';
- $msg .= '</table>';
- $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!";
- foreach ($userList as $user) {
- if (!empty($user['email'])) {
- if (!empty($value['onlinestatus'])) {
- if ($value['netstatus'] == 0) {
- if (isset($temp_send[$user['id']])) {
- $temp_send[$user['id']]['msg'] .= $msg;
- }else{
- $user['msg'] = $msg;
- $temp_send[$user['id']] = $user;
- }
- // send_email($user['email'],$msg,'Alarm info');
- }
- }else{
- if (isset($temp_send[$user['id']])) {
- $temp_send[$user['id']]['msg'] .= $msg;
- }else{
- $user['msg'] = $msg;
- $temp_send[$user['id']] = $user;
- }
- // send_email($user['email'],$msg,'Alarm info');
- }
- }
- }
- }
- $db->table('warning_info_log')->where('id='.$value['id'])->update(['is_send'=>1]);
- }
- }
- if (!empty($temp_send)) {
- foreach ($temp_send as $key => $value) {
- send_email($value['email'],$value['msg'],'Alarm info');
- }
- }
- $db->close();
- }
- $endDate = date('H:i',time());
- while ($beginDate == $endDate) {
- sleep(1);
- $endDate = date('H:i',time());
- }
- }
- ?>
|