ApiNoChecking.php 1.0 KB
<?php

namespace App\Console\Commands\Domain;

use App\Models\Project\DeployOptimize;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Http;

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

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '每日检查项目api编号是否正在监控';


    public function handle()
    {
        $api_url = 'http://api.quanqiusou.cn/api/index/weblist?key=289c1fc81c89d79c04ed4fd72822948e';

        $data = Http::timeout(60)->get($api_url)->json();

        if (is_array($data) && $data) {
            $api_no_list = array_keys($data);
            if ($api_no_list) {
                DeployOptimize::where('api_no_checking', '>', 0)->update(['api_no_checking' => 0]);

                DeployOptimize::whereIn('api_no', $api_no_list)->update(['api_no_checking' => 1]);
            }
        }

        return true;
    }
}