作者 刘锟

update

@@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
9 9
10 namespace App\Console\Commands\Domain; 10 namespace App\Console\Commands\Domain;
11 11
  12 +use App\Models\Project\CountryCustom;
12 use Illuminate\Console\Command; 13 use Illuminate\Console\Command;
13 use App\Models\Domain\DomainInfo as DomainInfoModel; 14 use App\Models\Domain\DomainInfo as DomainInfoModel;
14 15
@@ -37,14 +38,17 @@ class DomainInfo extends Command @@ -37,14 +38,17 @@ class DomainInfo extends Command
37 */ 38 */
38 public function handle() 39 public function handle()
39 { 40 {
40 - //更新域名到期时间  
41 - $this->startUpdateDomain(); 41 + //更新主站域名有效时间
  42 +// $this->startUpdateDomain();
42 43
43 //主站证书到期更新 44 //主站证书到期更新
44 - $this->startUpdateCert(); 45 +// $this->startUpdateCert();
45 46
46 //AMP站证书到期更新 47 //AMP站证书到期更新
47 - $this->startUpdateAmpCert(); 48 +// $this->startUpdateAmpCert();
  49 +
  50 + //创建的自定义小语种域名证书到期更新
  51 + $this->startUpdateCustomCert();
48 52
49 return true; 53 return true;
50 } 54 }
@@ -138,7 +142,35 @@ class DomainInfo extends Command @@ -138,7 +142,35 @@ class DomainInfo extends Command
138 } 142 }
139 143
140 /** 144 /**
141 - * @remark :更新正式 145 + * 自定义小语种站证书到期更新
  146 + * @author Akun
  147 + * @date 2024/03/23 10:08
  148 + */
  149 + public function startUpdateCustomCert()
  150 + {
  151 + $customModel = new CountryCustom();
  152 + $end_day = date('Y-m-d H:i:s', time() + 2 * 24 * 3600);//2天后到期
  153 + $list = $customModel->where('status', 1)->where('is_create', 1)->where(function ($query) use ($end_day) {
  154 + $query->whereNull('certificate_end_time')->orWhere('certificate_end_time', '<', $end_day);
  155 + })->get()->toArray();
  156 + foreach ($list as $v) {
  157 + //更新证书到期时间
  158 + $data = [];
  159 + $ssl = $this->updateDomainSsl($v['domain']);
  160 + $ssl['from'] && $data['certificate_start_time'] = $ssl['from'];
  161 + $ssl['to'] && $data['certificate_end_time'] = $ssl['to'];
  162 +
  163 + $customModel->edit($data, ['id' => $v['id']]);
  164 +
  165 + if ($v['type'] == 1 && ($data['certificate_end_time'] ?? '') < $end_day) {
  166 + //申请免费证书
  167 + $this->updateCustomPrivate($v['domain']);
  168 + }
  169 + }
  170 + }
  171 +
  172 + /**
  173 + * @remark :更新主站证书
142 * @name :updatePrivate 174 * @name :updatePrivate
143 * @author :lyh 175 * @author :lyh
144 * @method :post 176 * @method :post
@@ -168,7 +200,7 @@ class DomainInfo extends Command @@ -168,7 +200,7 @@ class DomainInfo extends Command
168 } 200 }
169 201
170 /** 202 /**
171 - * 更新证书 203 + * 更新amp站证书
172 * @param $domain 204 * @param $domain
173 * @return array 205 * @return array
174 * @author Akun 206 * @author Akun
@@ -185,6 +217,26 @@ class DomainInfo extends Command @@ -185,6 +217,26 @@ class DomainInfo extends Command
185 return $this->curlRequest($url, $param); 217 return $this->curlRequest($url, $param);
186 } 218 }
187 219
  220 + /**
  221 + * 更新小语种自定义站证书
  222 + * @param $domain
  223 + * @return array
  224 + * @author Akun
  225 + * @date 2024/03/23 10:07
  226 + */
  227 + public function updateCustomPrivate($domain)
  228 + {
  229 + $url = 'http://' . $domain . '/api/applySsl';
  230 + $param = [
  231 + 'domain' => $domain,
  232 + 'rewrite' => [],
  233 + 'other_domain' => [],
  234 + 'is_https' => 1
  235 + ];
  236 +
  237 + return $this->curlRequest($url, $param);
  238 + }
  239 +
188 public static function getTopDomain($url) 240 public static function getTopDomain($url)
189 { 241 {
190 $url = strtolower($url); //首先转成小写 242 $url = strtolower($url); //首先转成小写
@@ -237,7 +289,7 @@ class DomainInfo extends Command @@ -237,7 +289,7 @@ class DomainInfo extends Command
237 } 289 }
238 290
239 /** 291 /**
240 - * @remark :更新域名证书 292 + * @remark :获取域名证书有效时间
241 * @name :updateDomainSsl 293 * @name :updateDomainSsl
242 * @author :lyh 294 * @author :lyh
243 * @method :post 295 * @method :post
@@ -273,7 +325,7 @@ class DomainInfo extends Command @@ -273,7 +325,7 @@ class DomainInfo extends Command
273 } 325 }
274 326
275 /** 327 /**
276 - * @remark :更新域名有时间 328 + * @remark :更新域名有时间
277 * @name :updateDomain 329 * @name :updateDomain
278 * @author :lyh 330 * @author :lyh
279 * @method :post 331 * @method :post