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 {$value['stralarmtype']}, 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 .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $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 .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= ''; $msg .= '
Project name'.$value['projectname'].'Lamp number'.$value['number'].'Wireless module address'.$value['address'].'Road'.$value['section'].'
Brightness'.$value['lighteness'].'%Lamp voltage'.$value['lampvoltage'].'VLamp current'.$value['lampcurrent'].'ALamp power'.$value['lamppower'].'W
Network status'.$netstatus.'Version information'.$value['softwareVersion'].'ICCID'.$value['iccid'].'Update time'.$updatetime.'
'; $msg .= "The device located in project:{$value['projectname']}->number:{$value['number']} appears {$stralarmtype}, 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()); } } ?>