DomainTime.php
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace App\Console\Commands\Domain;
use App\Exceptions\AsideGlobalException;
use App\Exceptions\BsideGlobalException;
use App\Helper\AyrShare as AyrShareHelper;
use App\Http\Logic\Aside\Domain\DomainInfoLogic;
use App\Models\AyrShare\AyrRelease as AyrReleaseModel;
use Carbon\Carbon;
use App\Models\AyrShare\AyrShare as AyrShareModel;
use Illuminate\Console\Command;
class DomainTime extends Command
{
public $error = 0;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'domain_time';
/**
* The console command description.
*
* @var string
*/
protected $description = '域名定时任务 更新域名|证书到期时间';
/**
* @name :(定时执行)handle
* @author :lyh
* @method :post
* @time :2023/5/12 14:48
*/
public function handle()
{
echo $this->update_domain_time();
}
/**
* 更新域名|证书到期时间
* @return int|mixed|void
* @throws AsideGlobalException
* @throws BsideGlobalException
*/
protected function update_domain_time()
{
$domainCon = new DomainInfoLogic();
$all = $domainCon->getAllDomain();
$all = $all->toArray();
foreach ($all as $item) {
$domain = $item['domain'];
// 域名到期时间
$domainT = $domainCon->getDomainTime($domain);
if ($domainT) {
$domain_time = $item['domain_end_time'];
$domainValidFrom = $domainT['validFrom'];
$domainValidTo = $domainT['validTo'];
if (strtotime($domain_time) < strtotime($domainValidTo)) {
$this->info($domain . '域名到期时间更新成功');
$domainCon->updateDomain($item['id'], ['domain_end_time' => $domainValidTo]);
}
} else {
$this->error++;
$this->info($domain . '域名到期时间获取失败');
}
// 证书到期时间
$certificateT = $domainCon->getDomainCertificateTime($domain);
if ($certificateT) {
$certificate_time = $item['certificate_end_time'];
$certificateValidFrom = $certificateT['validFrom'];
$certificateValidTo = $certificateT['validTo'];
if (strtotime($certificate_time) < strtotime($certificateValidTo)) {
$this->info($domain . '证书到期时间更新成功');
$domainCon->updateDomain($item['id'], ['certificate_end_time' => $certificateValidTo]);
}
} else {
$this->error++;
$this->info($domain . '证书到期时间获取失败');
}
return $this->error;
}
}
}