@@ -17,7 +17,7 @@ |
||
| 17 | 17 | { |
| 18 | 18 | self::$lang === null && self::$lang = require 'lang.php'; |
| 19 | 19 | |
| 20 | - $message = isset(self::$lang[$code]) ? self::$lang[$code] : ''; |
|
| 20 | + $message = isset(self::$lang[ $code ]) ? self::$lang[ $code ] : ''; |
|
| 21 | 21 | |
| 22 | 22 | if ($additional !== null) { |
| 23 | 23 | if (is_array($additional)) { |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | chmod($logFile, 0666); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - fwrite($handle, $mark . ' - ' . date('Y-m-d H:i:s') . ' --> ' . (IS_CLI ? 'CLI' : 'URI: ' . $_SERVER['REQUEST_URI'] . PHP_EOL . 'REMOTE_ADDR: ' . $_SERVER['REMOTE_ADDR'] . PHP_EOL . 'SERVER_ADDR: ' . $_SERVER['SERVER_ADDR']) . PHP_EOL . (is_string($logContent) ? $logContent : var_export($logContent, true)) . PHP_EOL); // CLI模式下,$_SERVER中几乎无可用值 |
|
| 79 | + fwrite($handle, $mark . ' - ' . date('Y-m-d H:i:s') . ' --> ' . (IS_CLI ? 'CLI' : 'URI: ' . $_SERVER[ 'REQUEST_URI' ] . PHP_EOL . 'REMOTE_ADDR: ' . $_SERVER[ 'REMOTE_ADDR' ] . PHP_EOL . 'SERVER_ADDR: ' . $_SERVER[ 'SERVER_ADDR' ]) . PHP_EOL . (is_string($logContent) ? $logContent : var_export($logContent, true)) . PHP_EOL); // CLI模式下,$_SERVER中几乎无可用值 |
|
| 80 | 80 | |
| 81 | 81 | fclose($handle); |
| 82 | 82 | } catch (\Exception $e) { |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | public function autoLogin() |
| 171 | 171 | { |
| 172 | 172 | $curl = new Curl(); |
| 173 | - $curl->setUserAgent(static::$config['userInfo']['userAgent']); |
|
| 173 | + $curl->setUserAgent(static::$config[ 'userInfo' ][ 'userAgent' ]); |
|
| 174 | 174 | $curl->setReferrer('https://my.freenom.com/clientarea.php'); |
| 175 | 175 | $curl->setHeaders([ |
| 176 | 176 | 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', |
@@ -178,21 +178,21 @@ discard block |
||
| 178 | 178 | ]); |
| 179 | 179 | $curl->setTimeout(static::$timeOut); |
| 180 | 180 | $curl->post(static::LOGIN_URL, [ |
| 181 | - 'username' => static::$config['userInfo']['username'], |
|
| 182 | - 'password' => static::$config['userInfo']['password'] |
|
| 181 | + 'username' => static::$config[ 'userInfo' ][ 'username' ], |
|
| 182 | + 'password' => static::$config[ 'userInfo' ][ 'password' ] |
|
| 183 | 183 | ]); |
| 184 | 184 | |
| 185 | 185 | if ($curl->error) { |
| 186 | - throw new LlfException(6001, [$curl->errorCode, $curl->errorMessage]); |
|
| 186 | + throw new LlfException(6001, [ $curl->errorCode, $curl->errorMessage ]); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | $curl->close(); |
| 190 | 190 | |
| 191 | - if (!isset($curl->responseCookies['WHMCSZH5eHTGhfvzP'])) { // freenom有几率出现未成功登录也写此cookie的情况,所以此处不能完全断定是否登录成功,这是freenom的锅。若未成功登录,会在后面匹配域名信息的时候抛出异常。 |
|
| 191 | + if (!isset($curl->responseCookies[ 'WHMCSZH5eHTGhfvzP' ])) { // freenom有几率出现未成功登录也写此cookie的情况,所以此处不能完全断定是否登录成功,这是freenom的锅。若未成功登录,会在后面匹配域名信息的时候抛出异常。 |
|
| 192 | 192 | throw new LlfException(6002); |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - static::$authCookie = $curl->responseCookies['WHMCSZH5eHTGhfvzP']; |
|
| 195 | + static::$authCookie = $curl->responseCookies[ 'WHMCSZH5eHTGhfvzP' ]; |
|
| 196 | 196 | |
| 197 | 197 | return $curl->responseCookies; |
| 198 | 198 | } |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | public function renewDomains() |
| 207 | 207 | { |
| 208 | 208 | $curl = new Curl(); |
| 209 | - $curl->setUserAgent(static::$config['userInfo']['userAgent']); |
|
| 209 | + $curl->setUserAgent(static::$config[ 'userInfo' ][ 'userAgent' ]); |
|
| 210 | 210 | $curl->setTimeout(static::$timeOut); |
| 211 | 211 | $curl->setCookies([ // 验证登录状态 |
| 212 | 212 | 'WHMCSZH5eHTGhfvzP' => static::$authCookie |
@@ -226,14 +226,14 @@ discard block |
||
| 226 | 226 | ]); |
| 227 | 227 | |
| 228 | 228 | if ($curl->error) { |
| 229 | - throw new LlfException(6003, [$curl->errorCode, $curl->errorMessage]); |
|
| 229 | + throw new LlfException(6003, [ $curl->errorCode, $curl->errorMessage ]); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | // 取得token |
| 233 | 233 | if (!preg_match(self::$tokenRegex, $curl->response, $token)) { |
| 234 | 234 | throw new LlfException(6004); |
| 235 | 235 | } |
| 236 | - $token = $token[1]; |
|
| 236 | + $token = $token[ 1 ]; |
|
| 237 | 237 | |
| 238 | 238 | // 取得域名数据 |
| 239 | 239 | if (!preg_match_all(self::$domainInfoRegex, $curl->response, $domains, PREG_SET_ORDER)) { // PREG_SET_ORDER结果排序为$matches[0]包含第一次匹配得到的所有匹配(包含子组), $matches[1]是包含第二次匹配到的所有匹配(包含子组)的数组,以此类推。 |
@@ -245,33 +245,33 @@ discard block |
||
| 245 | 245 | */ |
| 246 | 246 | $renew_log = ''; |
| 247 | 247 | foreach ($domains as $domain) { |
| 248 | - if (intval($domain[4]) <= 14) { // 免费域名只允许在到期前14天内续期 |
|
| 249 | - $curl->setReferrer('https://my.freenom.com/domains.php?a=renewdomain&domain=' . $domain[5]); |
|
| 248 | + if (intval($domain[ 4 ]) <= 14) { // 免费域名只允许在到期前14天内续期 |
|
| 249 | + $curl->setReferrer('https://my.freenom.com/domains.php?a=renewdomain&domain=' . $domain[ 5 ]); |
|
| 250 | 250 | $curl->setHeader('Content-Type', 'application/x-www-form-urlencoded'); |
| 251 | 251 | $curl->post(static::RENEW_DOMAIN_URL, [ |
| 252 | 252 | 'token' => $token, |
| 253 | - 'renewalid' => $domain[5], // 域名id |
|
| 254 | - 'renewalperiod[' . $domain[5] . ']' => '12M', // 续期一年 |
|
| 253 | + 'renewalid' => $domain[ 5 ], // 域名id |
|
| 254 | + 'renewalperiod[' . $domain[ 5 ] . ']' => '12M', // 续期一年 |
|
| 255 | 255 | 'paymentmethod' => 'credit', // 支付方式 - 信用卡 |
| 256 | 256 | ]); |
| 257 | 257 | |
| 258 | 258 | if ($curl->error) { |
| 259 | - throw new LlfException(6006, [$domain[1], $curl->errorCode, $curl->errorMessage]); |
|
| 259 | + throw new LlfException(6006, [ $domain[ 1 ], $curl->errorCode, $curl->errorMessage ]); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | sleep(1); // 防止操作过于频繁 |
| 263 | 263 | |
| 264 | 264 | if (stripos($curl->rawResponse, 'Order Confirmation') === false) { // 续期失败 |
| 265 | - $renew_log .= $domain[1] . '续期失败' . "\n"; |
|
| 266 | - $this->notRenewed .= sprintf('<a href="http://%s/" rel="noopener" target="_blank">%s</a>', $domain[1], $domain[1]); |
|
| 265 | + $renew_log .= $domain[ 1 ] . '续期失败' . "\n"; |
|
| 266 | + $this->notRenewed .= sprintf('<a href="http://%s/" rel="noopener" target="_blank">%s</a>', $domain[ 1 ], $domain[ 1 ]); |
|
| 267 | 267 | } else { |
| 268 | - $renew_log .= $domain[1] . '续期成功' . "\n"; |
|
| 269 | - $this->renewed .= sprintf('<a href="http://%s/" rel="noopener" target="_blank">%s</a>', $domain[1], $domain[1]); |
|
| 268 | + $renew_log .= $domain[ 1 ] . '续期成功' . "\n"; |
|
| 269 | + $this->renewed .= sprintf('<a href="http://%s/" rel="noopener" target="_blank">%s</a>', $domain[ 1 ], $domain[ 1 ]); |
|
| 270 | 270 | continue; |
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - $this->domainsInfo .= sprintf('<a href="http://%s/" rel="noopener" target="_blank">%s</a>' . '还有<span style="font-weight: bold; font-size: 16px;">%d</span>天到期,', $domain[1], $domain[1], intval($domain[4])); |
|
| 274 | + $this->domainsInfo .= sprintf('<a href="http://%s/" rel="noopener" target="_blank">%s</a>' . '还有<span style="font-weight: bold; font-size: 16px;">%d</span>天到期,', $domain[ 1 ], $domain[ 1 ], intval($domain[ 4 ])); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | system_log($renew_log ?: sprintf("在%s这个时刻,并没有需要续期的域名,写这条日志是为了证明我确实执行了。今次取得的域名信息如是:\n%s", date('Y-m-d H:i:s'), var_export($domains, true))); |
@@ -308,17 +308,17 @@ discard block |
||
| 308 | 308 | $mail->isSMTP(); // 告诉PHPMailer使用SMTP |
| 309 | 309 | $mail->Host = 'smtp.gmail.com'; // SMTP服务器 |
| 310 | 310 | $mail->SMTPAuth = true; // 启用SMTP身份验证 |
| 311 | - $mail->Username = static::$config['mail']['username']; // 账号 |
|
| 312 | - $mail->Password = static::$config['mail']['password']; // 密码 |
|
| 311 | + $mail->Username = static::$config[ 'mail' ][ 'username' ]; // 账号 |
|
| 312 | + $mail->Password = static::$config[ 'mail' ][ 'password' ]; // 密码 |
|
| 313 | 313 | $mail->SMTPSecure = 'tls'; // 将加密系统设置为使用 - ssl(不建议使用)或tls |
| 314 | 314 | $mail->Port = 587; // 设置SMTP端口号 - tsl使用587端口,ssl使用465端口 |
| 315 | 315 | |
| 316 | 316 | $mail->CharSet = 'UTF-8'; // 防止中文邮件乱码 |
| 317 | 317 | $mail->setLanguage('zh_cn', VENDOR_PATH . '/phpmailer/phpmailer/language/'); // 设置语言 |
| 318 | 318 | |
| 319 | - $mail->setFrom(static::$config['mail']['from'], 'im robot'); // 发件人 |
|
| 320 | - $mail->addAddress($to ?: static::$config['mail']['to'], '罗叔叔'); // 添加收件人,参数2选填 |
|
| 321 | - $mail->addReplyTo(static::$config['mail']['replyTo'], '罗飞飞'); // 备用回复地址,收到的回复的邮件将被发到此地址 |
|
| 319 | + $mail->setFrom(static::$config[ 'mail' ][ 'from' ], 'im robot'); // 发件人 |
|
| 320 | + $mail->addAddress($to ?: static::$config[ 'mail' ][ 'to' ], '罗叔叔'); // 添加收件人,参数2选填 |
|
| 321 | + $mail->addReplyTo(static::$config[ 'mail' ][ 'replyTo' ], '罗飞飞'); // 备用回复地址,收到的回复的邮件将被发到此地址 |
|
| 322 | 322 | |
| 323 | 323 | /** |
| 324 | 324 | * 抄送和密送都是添加收件人,抄送方式下,被抄送者知道除被密送者外的所有的收件人,密送方式下, |
@@ -354,7 +354,9 @@ |
||
| 354 | 354 | } |
| 355 | 355 | $mail->msgHTML($message, __DIR__ . '/mail'); |
| 356 | 356 | |
| 357 | - if (!$mail->send()) throw new \Exception($mail->ErrorInfo); |
|
| 357 | + if (!$mail->send()) { |
|
| 358 | + throw new \Exception($mail->ErrorInfo); |
|
| 359 | + } |
|
| 358 | 360 | } |
| 359 | 361 | } |
| 360 | 362 | |