/** * 更新账户有效状态 * @param string $type 第三方平台类型 */ public function fail($third, $error_msg = NULL) { $pid = $third['pid']; $type = $third['type']; ob_start(); debug_print_backtrace(); $trace = ob_get_contents(); ob_clean(); Log::customLog('token_expires_error.txt', $this->rep_platform("Token 过期,平台:{pid}|{type}, {platform},{weibo},原因:{$error_msg}\r\n调用堆栈:\r\n{$trace}", $pid, $type)); $mail = Config::get_mail('token_expire'); sendmail($mail['to'], $this->rep_platform($mail['subject'], $pid, $type), $this->rep_platform($mail['content'], $pid, $type) . "<br>原因:{$error_msg}"); return $this->update(array('valid' => 0), array('pid' => $pid, 'type' => $type)); }
/** * SMTP方式发邮件 * @param string $to 目标邮箱,多个地址半角逗号分隔 * @param string $subject * @param string $content */ function sendmail($to, $subject, $content, &$error = null) { $smtp = Config::get_mail('smtp'); if (!$smtp) { return false; } $mail = new SmtpMail($smtp['host'], $smtp['ip'], $smtp['port']); $mail->setFromEnv($smtp['email'], $smtp['username'], $smtp['password'], $smtp['display']); $ret = false; foreach ($to as $item) { $ret = $mail->send($item, $subject, $content, array(), $error); } return $ret; }
$third = $thirdAccount->getByType($arr[0], $arr[1]); $api = Factory::CreateAPI2($arr[0], $arr[1], $third); $ret = $api->upload($_POST['content'], $upload_file); if ($ret !== true && strpos($ret, '已过期') !== false) { $thirdAccount->fail($third, $ret); } $TEMPLATE['report'][$type] = array('status' => $ret === true, 'msg' => $ret === true ? '发送成功!<a href="' . $third['url'] . '" target="_blank">查看</a>' : '发送失败:' . $ret . ' <a href="list_err.php">重新发送</a>'); $task->AddTask($type, $_POST['content'], time(), $upload_file, $ret === true ? Task::OK : Task::ERROR, $ret); } $watch->Stop(); $TEMPLATE['report']['watch'] = array('status' => true, 'msg' => "总耗时:{$watch->getElapsedSeconds()} 秒"); } } } if ($_GET['testmail']) { $mail = Config::get_mail('token_expire'); if (sendmail($mail['to'], '【微博工具】测试邮件', '测试邮件内容', $error)) { echo '发送成功'; } else { echo "<font color=red>发送失败:{$error}</font>"; } } $TEMPLATE['title'] = '发微博'; $TEMPLATE['login_name'] = Passport::GetLoginName(); $TEMPLATE['nav']['index'] = 'current'; $TEMPLATE['target_list'] = $wt_open->getWeiboList(); $TEMPLATE['platform_list'] = $wt_open->getPlatformList(); foreach ($TEMPLATE['platform_list'] as &$item) { $item['list'] = $wt_open->getWeiboList($item['id']); unset($item); }