DomainInfo.php 1.6 KB
<?php
/**
 * @remark :
 * @name   :DomainInfo.php
 * @author :lyh
 * @method :post
 * @time   :2023/9/11 14:37
 */

namespace App\Console\Commands\Domain;

use Illuminate\Console\Command;
use App\Models\Domain\DomainInfo as DomainInfoModel;

class DomainInfo extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'domain_info';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '域名相关';

    public function handle(){
        $domainModel = new DomainInfoModel();
        $map = [];
        $list = $domainModel->list($map);
        $context = stream_context_create([
            'ssl' => [
                'capture_peer_cert' => true,
                'capture_peer_cert_chain' => false,
            ],
        ]);
        $stream = stream_socket_client('ssl://oa.quanqiusou.cn:443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
        if(!$stream) {
            die("Failed to connect: $errno - $errstr");
        }
        $remote_cert = stream_context_get_params($stream)['options']['ssl']['peer_certificate'];
        if(!$remote_cert) {
            die("Failed to retrieve certificate");
        }
        $valid_from = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validFrom_time_t']);
        $valid_to = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validTo_time_t']);
        fclose($stream);
        echo "Certificate Valid From: $valid_from<br>";
        echo "Certificate Valid To: $valid_to<br>";
    }
}