<?php 
require_once "./Base.php";
echo "微信企业号平台wiki更新检测日志:<br>";
$git_dir = WIKI_DIR_QY;
if (!file_exists($git_dir . '.git')) {
    echo date("Y-m-d H:i:s") . " 未创建git库。";
    exit;
}
$ret = get_lastlog($git_dir, 3);
echo "前3次git的提交日志内容如下:<br><hr>" . nl2br(htmlspecialchars($ret));
Exemple #2
0
function send_mail($path, $mail_lock, $subject, $to = array())
{
    if (!file_exists($mail_lock)) {
        //从getwiki.php中得到的更新标志
        $tmp_file = './update_' . time() . '.txt';
        $ret_text = get_lastlog($path, 1);
        //##########################################
        $smtpserver = isset($_ENV["SMTP_SERVER"]) ? $_ENV["SMTP_SERVER"] : "smtp.163.com";
        //SMTP服务器
        $smtpserverport = isset($_ENV["SMTP_SERVER_PORT"]) ? $_ENV["SMTP_SERVER_PORT"] : "465";
        //SMTP服务器端口
        $smtpusermail = isset($_ENV["SMTP_USER_MAIL"]) ? $_ENV["SMTP_USER_MAIL"] : "";
        //SMTP服务器的用户邮箱
        $smtpemailto = isset($_ENV["SMTP_MAIL_TO"]) ? $_ENV["SMTP_MAIL_TO"] : "";
        //收件人
        $smtpuser = isset($_ENV["SMTP_USER"]) ? $_ENV["SMTP_USER"] : "";
        //SMTP服务器的用户帐号
        $smtppass = isset($_ENV["SMTP_PASS"]) ? $_ENV["SMTP_PASS"] : "";
        //SMTP服务器的用户密码
        $mailtype = "HTML";
        //邮件格式(HTML/TXT),TXT为文本邮件
        $mailsubject = "监测通知:微信公众平台WIKI更新";
        //邮件主题
        $mailbody = "<h1> 更新内容为: </h1>" . "git日志内容如下:<br><hr>" . nl2br(htmlspecialchars(substr($ret_text, 0, stripos($ret_text, "\ndiff --git")))) . "<br><hr>更多内容,请参看附件" . $tmp_file;
        //邮件内容
        ##########################################
        if (!$smtpuser) {
            echo "由于邮箱SMTP账号信息等未配置,邮件未能发送<br />";
            return false;
            //未设置参数则返回
        }
        if (REMOTE_URL !== '') {
            $mailbody .= "<br>或者点击查看远程仓库页面:<a href=\"" . REMOTE_URL . "\">" . REMOTE_URL . "</a>";
        }
        $mailbody .= '<hr>收到此邮件说明曾经订阅此通知,如不是您本人操作或不想再接收到此通知请单独向我发邮件说明或阅读
                <a href="http://help.mail.163.com/faqDetail.do?code=d7a5dc8471cd0c0e8b4b8f4f8e49998b374173cfe9171305fa1ce630d7f67ac28425c7e6c5a286cc.">自助退订方法</a>';
        if (empty($to)) {
            $to = isset($_ENV["SMTP_MAIL_TO2"]) ? $_ENV["SMTP_MAIL_TO2"] : "";
            //附加收件人
        }
        $to_arr = preg_split('/[,;\\/\\\\|]/', $smtpemailto);
        if (is_string($to)) {
            $to = preg_split('/[,;\\/\\\\|]/', $to);
        }
        $to_arr = array_merge($to_arr, $to);
        $to_count = count($to_arr);
        $to_arr = array_chunk($to_arr, 20);
        write($tmp_file, $ret_text);
        $mail = new PHPMailer();
        $mail->IsSMTP();
        // send via SMTP
        //$mail->SMTPDebug  = 1;
        $mail->SMTPAuth = true;
        // turn on SMTP authentication
        $mail->SMTPSecure = "ssl";
        $mail->CharSet = "utf-8";
        // 这里指定字符集!
        $mail->Encoding = "base64";
        $mail->Host = $smtpserver;
        // SMTP servers
        $mail->Port = $smtpserverport;
        $mail->Username = $smtpuser;
        // SMTP username  注意:普通邮件认证不需要加 @域名
        $mail->Password = $smtppass;
        // SMTP password
        $mail->setFrom($smtpusermail, "Auto Robot");
        //设置发件人信息
        $mail->AddReplyTo($smtpusermail);
        //回复地址和姓名
        $mail->WordWrap = 50;
        // set word wrap
        $mail->IsHTML(true);
        // send as HTML
        $mail->Subject = $subject ? $subject : $mailsubject;
        // 邮件主题
        $mail->Body = $mailbody;
        $mail->AltBody = "text/html";
        $mail->addAttachment($tmp_file);
        $sendRet = true;
        foreach ($to_arr as $to_arr_lite) {
            foreach ($to_arr_lite as $to_str) {
                $mail->AddAddress($to_str);
                // 收件人邮箱和姓名
            }
            $sendRet = $mail->Send() & $sendRet;
            $mail->clearAllRecipients();
        }
        if ($sendRet) {
            unlink($tmp_file);
            echo "邮件发送失败,";
            echo "邮件错误信息: " . $mail->ErrorInfo . "<br />";
        } else {
            unlink($tmp_file);
            echo "邮件已发送到邮箱 <br />";
            file_put_contents($mail_lock, 'ok');
        }
    } else {
        echo "未更新,不发送通知邮件。";
    }
}