public static function sendEmailCode($email, $repeatAt) { $memcached = MemcachedPool::getMemcached(MemcachedConfig::$SERVER_COMMON); $key = MemcachedKeys::UC_EMAIL_AUTH_ . $email; $info = $memcached->get($key); // 如果没有过期 if (!empty($info)) { // 如果刷新时间没到,那么直接返回false if ($info['repeat_at'] > time()) { return false; } $code = $info['code']; // 重复发送相同的验证码 } else { $code = self::makeCode(); } // 发送邮件 $subject = 'HQOJ验证码'; $body = "您的验证码为:{$code}"; $emailClient = new EmailClient(EmailConfig::$SENDER_ADMIN); $emailClient->sendAsync($subject, $body, $email); $info = array('code' => $code, 'repeat_at' => $repeatAt); $memcached->set($key, $info, 600); // 设置验证码有效时间为10分钟 return $code; }
function func(GearmanJob $job) { $params = json_decode($job->workload(), true); $config = Arr::get('config', $params, array()); $subject = Arr::get('subject', $params, ''); $body = Arr::get('body', $params, ''); $to = Arr::get('to', $params, ''); $cc = Arr::get('cc', $params, ''); $bcc = Arr::get('bcc', $params, ''); $email = new EmailClient($config); $email->send($subject, $body, $to, $cc, $bcc); }
public static function sendMonitorEmail($receivers, $title, $content) { /*{{{*/ $remoteAddr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $serverAddr = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : ''; $content .= "\n\nclientIp:{$remoteAddr}\nservieIp:{$serverAddr}"; try { EmailClient::getInstance()->sendSync($receivers, $title, $content, 'text/html'); } catch (Exception $e) { } }
private function sendEmail($content) {/*{{{*/ if ($content) { $subject = '工单占用超时提醒'; $content .= "\n\n请相互提醒注意,如果不审核,请及时下线释放。"; EmailClient::getInstance()->sendSync( array('*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', ), $subject, $content); } }/*}}}*/
private function _rechargeAndPay() {/*{{{*/ try { return $this->_recharge(); } catch(Exception $ex) { try{ $receivers = array('*****@*****.**', '*****@*****.**'); $subject = "好大夫在线:患者支付订单失败,余额不足,订单id:{$this->depositeOrder->id}"; $content = "errorMsg=".print_r($ex, true); EmailClient::getInstance()->sendSync($receivers, $subject, $content, 'text/html'); }catch(Exception $ex2) {} } return false; }/*}}}*/
/** * sendEmailForCommon * 给运维发送邮件 * * @param mixed $subject * @param mixed $content * @param string $type * @static * @access public * @return void */ public static function sendEmail($subject, $content, $type = 'text/plain') { /*{{{*/ $config = BeanFinder::get('configs'); if ($config->isDevEnv()) { $sendToEmail = array(); //开发环境乱发邮件,先去掉了 //$sendToEmail = array('*****@*****.**', '*****@*****.**'); } else { if ($config->isTestEnv()) { $sendToEmail = array('*****@*****.**'); } else { $sendToEmail = array('*****@*****.**'); } } $content = $config->getHostName() . "\n\n" . $content; EmailClient::getInstance()->sendAsync($sendToEmail, $subject, $content, $type); }
/** * sendMailFile 发送日志邮件 * * @param mixed $type * @param mixed $theDate * @access private * @return void */ private function sendMailFile($type, $theDate) { /*{{{*/ $filePath = PhoneConferenceClient::getInstance()->getConfLogPath(); $fileType = $type . '-' . $theDate; $fileName = $fileType . '.log'; $fileLongPath = $filePath . $fileName; //全路径日志文件 DBC::requireTrue(file_exists($fileLongPath), '文件不存在,不发送邮件'); $goalDir = $this->writeLogDir($filePath); $this->getBatchLog($fileLongPath, $filePath, $goalDir . $fileType); $attachmentName = $type . $theDate . '-' . date("YmdHis"); $tarFile = $goalDir . $attachmentName . '.zip'; exec('zip -r9 ' . $tarFile . ' ' . $goalDir . '.'); $file = fopen($tarFile, "r"); DBC::requireTrue($file, '打开文件错误'); $attachment = array("fileName" => $attachmentName . '.zip', "fileType" => "application/tar", "data" => fread($file, filesize($tarFile))); fclose($file); $emails = array('*****@*****.**'); $title = $this->curUser->name . "|获取电话系统日志:{$attachmentName}"; EmailClient::getInstance()->batchSendMail($emails, $title, '见附件' . rand(1, 1000), 'text/plain', $attachment); exec('rm ' . $tarFile); }
/** * callInWaitingCnt * 监控排队数量,目前客服阀值15,加号阀值5 * @param mixed $request * @param mixed $response * @access public * @return void */ public function callInWaitingCnt($request, $response) { /*{{{*/ $res = array('20cnt' => 0, '91cnt' => 0); $callinWaitingInfos = DAL::get()->queryCallinWaitingInfo('teleconversation'); $serviceQueues = DAL::get()->find('ServiceQueue', array_keys($callinWaitingInfos)); foreach ($callinWaitingInfos as $queueId => $waitingInfo) { if (ServiceQueue::TYPE_JIAHAO == $serviceQueues[$queueId]->queueType) { $res['20cnt'] = $waitingInfo['enterqueuecnt']; } if (ServiceQueue::TYPE_CUSTOMER_SERVICE == $serviceQueues[$queueId]->queueType) { $res['91cnt'] = $waitingInfo['enterqueuecnt']; } } if (15 < $res['91cnt'] || 5 < $res['20cnt']) { $content = print_r($res, true); EmailClient::getInstance()->sendSync(array('*****@*****.**'), '好大夫在线:排队数量过多', $content, 'text/html'); } echo implode(" ", $res); return parent::DIRECT_OUTPUT; }
public function sendEmail($request, $response) { $userId = $request->userId; $emailTitle = $request->emailTitle; $taskName = $request->taskName; //$request->emailContent会把html代码拦截 $emailContent = $request->getUnSafeData('emailContent'); $emails = array(); $errorUserIds = array(); $userIds = explode(',', $userId); $userIds = array_filter($userIds); $users = DAL::get()->find('user', $userIds); foreach ($users as $key => $user) { $email = trim($user->email); if ($user->isNull()) { $errorUserIds[] = $key; continue; } $is_email = preg_match("/^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+\\.)+[a-z]{2,3}\$/", $email); if ($is_email) { $emails[] = $email; } else { $errorUserIds[] = $user->id; } } $msg = "邮件已提交发送"; if (empty($errorUserIds) == false) { $msg = "邮件已提交发送, 其中有问题的userid: " . implode(', ', $errorUserIds); } if (empty($emails) == false) { //qq邮件接口 EmailClient::getInstance()->sendSync($emails, $emailTitle, $emailContent, $type = 'text/plain'); //华祥同辉提供的邮件服务接口 // EmailClient::getInstance()->sendSyncByHXTH($emails, $taskName, $emailTitle, $emailContent, 'text/plain'); } $url = $response->router->urlfor('message/showsendemail', array('msg' => $msg)); $response->setRedirect($url); }
<?php $dir = dirname(__FILE__); include_once($dir.'/../script/init.php'); ini_set('memory_limit','1024M'); $sourceName = (isset($argv[1]))?trim($argv[1]):''; if (!$sourceName) { echo "usage: php ".$argv[0]." datasourcename"; exit; } try { $factory = new OpenFactory; echo XDateTime::now()->toString()."\n"; $factory->buildDataSource($sourceName); $factory->wrapDataBySource($sourceName); $factory->generateIndexBySource($sourceName); $factory->packageBySource($sourceName); } catch(Exception $ex) { EmailClient::getInstance()->sendSync(BeanFinder::get('configs')->aladdinMailbox, "阿拉丁数据源定时任务运行异常", $ex->getMessage(), $type='text/html'); }
<?php require(dirname(__FILE__).'/../../monitor/assembly.php'); DAL::get()->setUp('ops'); $to = array('*****@*****.**'); exec('/bin/sh /home/avatar/system/ops/stat/spider/spider.sh', $content); EmailClient::getInstance()->batchSendMail($to, '[STAT]spider抓取情况统计', implode("\n", $content));
private function sendEmail() {/*{{{*/ if(file_exists($this->filePath)) { $res = file_get_contents($this->filePath); EmailClient::getInstance()->sendSync($this->mailbox, "阿拉丁监控数据源异常", $res, $type='text/html'); unlink($this->filePath); } }/*}}}*/
<?php require(dirname(__FILE__).'/../../monitor/assembly.php'); DAL::get()->setUp('ops'); #$to = array('*****@*****.**', '*****@*****.**'); $to = array('*****@*****.**'); exec('/bin/bash /home/avatar/system/ops/stat/mysql/statslowquery.sh'); //文件大于500k就打包发送 if (filesize('/tmp/killslow.log') > 512000){ exec('tar -zcf /tmp/slow.tgz /tmp/killslow.log'); $attachment = array("fileName"=>'slow.tgz',"fileType"=>"application/tar","data"=>file_get_contents('/tmp/slow.tgz')); EmailClient::getInstance()->batchSendMail($to, '[STAT]线上即将强行kill掉的慢查询', '太多了,只能打包发邮件啦', 'text/plain', $attachment); }else { EmailClient::getInstance()->batchSendMail($to, '[STAT]线上即将强行kill掉的慢查询', file_get_contents('/tmp/killslow.log')); } if (filesize('/tmp/killslow.log') < 10240000){ exec("cat /tmp/killslow.log | awk -F '\t' '{print $8}' | sort | uniq > /tmp/b.log"); EmailClient::getInstance()->batchSendMail(array('*****@*****.**'), '[STAT]线上即将强行kill掉的慢查询(去重)', file_get_contents('/tmp/b.log')); }
<?php require(dirname(__FILE__).'/../../monitor/assembly.php'); DAL::get()->setUp('ops'); $to = array('*****@*****.**', '*****@*****.**'); exec('/bin/sh /home/avatar/system/ops/stat/exception/xclient.sh'); $attachment = array("fileName"=>'exception.tgz',"fileType"=>"application/tar","data"=>file_get_contents('/tmp/exception.tgz')); EmailClient::getInstance()->batchSendMail($to, '[STAT]线上异常统计', '由当前线上版本维护组进行修改.', 'text/plain', $attachment);
<?php require(dirname(__FILE__).'/../../monitor/assembly.php'); DAL::get()->setUp('ops'); $to = array('*****@*****.**', '*****@*****.**'); exec('/bin/sh /home/avatar/system/ops/stat/client/xclient.sh | sort | uniq -c | sort -rn', $content); $content = implode("\n", $content); EmailClient::getInstance()->sendSync($to, '[STAT]client³¬Ê±Í³¼Æ', $content);
private function realFinish($request, $response) { $user = UserClient::getInstance()->getCurrentUser(); $response->userName = ''; if ($user->hasSpace() == false) { MsgHtml::msg('医生注册失败, 请重新尝试, <a href="http://www.haodf.com/suggestion/suggestion">或与我们联系</a>'); } else { $response->space = $user->space; $response->userName = $user->name; try { $tplname = "doctor.reg.success"; $userId = $user->id; $datas = array(); $datas['doctorname'] = $user->realName; $datas['username'] = $user->name; //站内消息 StationLetterClient::getInstance()->sendMsgByTpl($tplname, Auditor::ADMIN_USER_ID, array($userId), $datas); //邮件 $email = $user->email; EmailClient::getInstance()->sendByTpl($tplname, $email, $datas, true); $operators = array(); $operators['zxh']="张旭海"; $operators['lyp']="刘义平"; $operators['dh']="代红"; $operators['ll']="刘柳"; $operators['liu']="刘柳"; $operators['ccm']="陈超美"; $operators['test']="内部测试"; $operators['sjp']="史建平"; $operators['ylf']="杨利锋"; $operators['cf']="崔芳"; //内部注册特殊处理 $userPhone = $user->phone; foreach($operators as $key=>$value) { if(strpos($userPhone,$key) !== false) { $userPhone = trim(str_replace($key,'',$userPhone)); $userPhone = str_replace('()',' ',$userPhone); $userPhone = str_replace('( )',' ',$userPhone); $dd = array(); $dd['phone'] = $userPhone; $dd['spaceRemarks1'] = $user->spaceRemarks1."电话拜访"; $dd['spaceRemarks2'] = $user->spaceRemarks2.$value; $userId = UserClient::getInstance()->modifyInfoNew($userId, $dd); $tplname = "doctor.reg.success.2"; break; } //防刷新时,发送电话拜访的短信 if(strpos($user->spaceRemarks2, $value) !== false) { $tplname = "doctor.reg.success.2"; break; } } //暂时只发自注册医生的短信通知 if($tplname != "doctor.reg.success.2") { //短信 $phone = $user->mobile; SMSClient::getInstance()->sendSMSByTplName($tplname, array($phone), $datas, SMSLog::OPT_TYPE_DOCTOR_REG_SUCCESS, '', true); } } catch(Exception $ex) { //暂时忽略异常 } } }
<?php require(dirname(__FILE__).'/../../monitor/assembly.php'); DAL::get()->setUp('ops'); $to = array('*****@*****.**'); exec('/bin/sh /home/avatar/system/ops/stat/exception/optimistic_log_gather.sh'); $attachment = array("fileName"=>'optimistic_exception.tgz',"fileType"=>"application/tar","data"=>file_get_contents('/tmp/optimisticlockexception.tgz')); $content = "以下是失效更新所涉及的表以及失效数目, 请相关负责人处理一下\n现在乐观锁只是记日志, 并未抛异常, 将在5月中旬改为抛异常, 到时整个事务更新都将失效哦\n\n主要关注下20个以上的, 其他的就算了吧\n\n"; $content .= file_get_contents('/tmp/optimistic_exception/stat.txt'); EmailClient::getInstance()->batchSendMail($to, '[STAT]乐观锁异常', $content, 'text/plain', $attachment);
<?php set_time_limit(0); ini_set('memory_limit', '521M'); include_once(dirname(__FILE__).'/../../services/message/scripts/init.php'); $file = dirname(__FILE__).'/log/test.log'; if(file_exists($file)) { $content = file_get_contents($file); $to = array('*****@*****.**'); if($content) { $attachment = array("fileName"=>'test.log',"fileType"=>"application/txt","data"=>$content); EmailClient::getInstance()->batchSendMail($to, '[每日构建]单元测试', $content, 'text/plain', $attachment); } } ?>
public function sendDiagnoseReport($request, $response) {/*{{{*/ $spType = $request->spType; $confId = $request->confId; $reportContent = $request->reportContent; $loginUser = $this->curUser->name; DBC::requireNotEmpty($reportContent,"邮件内容不能为空"); $resultContent = ""; if(false == empty($spType)) { $resultContent = XDateTime::now()->toString()."{$spType} \n"; $resultContent .= $reportContent; if(false == empty($confId)) { $confMemberList = DAL::get()->find_all_by_confid('ConferenceMember', $confId); foreach($confMemberList as $confMember) { $resultContent .= "\n".$confMember->getRoleTitle()."|".$confMember->phoneNumber."|".$confMember->spcallId."|".$confMember->ctime."|".$confMember->startTime->toString(); if(false == $confMember->startTime->isZero()) { $resultContent .= "成功接听"; } } } $resultContent .= "\n"." ----BY ".$loginUser; EmailClient::getInstance()->batchSendMail(array('*****@*****.**'), '电话会议诊断结果', $resultContent); } $response->setRedirect("/paymentfront/telconference/diagnose?confId={$confId}&spType={$spType}&step=reportdiagnose"); }/*}}}*/
<?php require(dirname(__FILE__).'/../../monitor/assembly.php'); DAL::get()->setUp('ops'); $to = array('*****@*****.**'); $content = file_get_contents('/home/avatar/logs/services/core/tu/main.log'); EmailClient::getInstance()->batchSendMail($to, 'FastDFS storageÔËÐÐÇé¿ö', $content);