作者 lyh
<?php
namespace App\Console\Commands\RankData;
use App\Helper\Arr;
use App\Utils\HttpUtils;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Console\Command;
class updateAiProjects extends Command
{
protected $signature = 'updateAiProjects';
protected $description = '更新AI站点域名数据';
public function handle()
{
$api_url = 'https://demosite5.globalso.com/api/domain';
try {
$data = HttpUtils::get($api_url, []);
if ($data) {
$data = Arr::s2a($data);
$file_path = public_path('ai_domains.txt');
file_put_contents($file_path, json_encode($data['data']));
}
} catch (\Exception | GuzzleException $e) {
errorLog('AI站点项目获取失败', [], $e);
return false;
}
}
}
... ...
... ... @@ -40,6 +40,9 @@ class Kernel extends ConsoleKernel
$schedule->command('delete_template_log')->monthlyOn(15, '00:01')->withoutOverlapping();
// 每日推送已完成视频任务项目生成对应界面
$schedule->command('notice_c')->dailyAt('04:00')->withoutOverlapping(1);
//更新AI站点数据
$schedule->command('updateAiProjects')->everyFourHours()->withoutOverlapping(1);
}
/**
... ...
... ... @@ -531,24 +531,12 @@ class OptimizationReportController extends BaseController
*/
public function getAiProjects($domain = null)
{
$key = 'ai_projects_list';
$data = Cache::get($key);
if (!$data) {
$api_url = 'https://demosite5.globalso.com/api/domain';
try {
$data = HttpUtils::get($api_url, []);
if ($data) {
$data = Arr::s2a($data);
Cache::put($key, $data, 4 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('AI站点项目获取失败', [], $e);
return false;
}
}
$file_path = public_path('ai_domains.txt');
$data = file_get_contents($file_path);
$data = json_decode($data, true);
if ($domain !== null) {
$domain = parse_url($domain);
$data = collect($data['data'])->where('bind_domain', $domain['host'] ?? $domain['path'])->first();
$data = collect($data)->where('bind_domain', $domain['host'] ?? $domain['path'])->first();
return $data ?: [];
}
return $data;
... ...
... ... @@ -314,20 +314,7 @@ class RankDataLogic extends BaseLogic
public function getAiProjects($domain = null)
{
$file_path = public_path('ai_domains.txt');
$update_time = filemtime($file_path);
$data = file_get_contents($file_path);
if (time() - $update_time > 4 * 3600) {
$api_url = 'https://demosite5.globalso.com/api/domain';
try {
$data = HttpUtils::get($api_url, []);
if ($data) {
file_put_contents($file_path, $data);
}
} catch (\Exception | GuzzleException $e) {
errorLog('AI站点项目获取失败', [], $e);
file_put_contents($file_path, $data);
}
}
$data = json_decode($data, true);
if ($domain !== null) {
$domain = parse_url($domain);
... ...