作者 lyh
... ... @@ -307,30 +307,31 @@ class RankDataLogic extends BaseLogic
/**
* 获取AI站点项目
*
* @author zbj
* @date 2023/5/12
*/
public function getAiProjects($domain = null)
{
$key = 'ai_projects_list';
$data = Cache::get($key);
if (!$data) {
$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, []);
$data = file_get_contents(public_path('ai_domain.text'));
$data = HttpUtils::get($api_url, []);
if ($data) {
$data = Arr::s2a($data);
Cache::put($key, $data, 4 * 3600);
file_put_contents($file_path, $data);
}
} catch (\Exception | GuzzleException $e) {
errorLog('AI站点项目获取失败', [], $e);
return false;
file_put_contents($file_path, $data);
}
}
$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;
... ...