InquiryRelateDomain.php
2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace App\Models\Inquiry;
use App\Helper\Arr;
use App\Helper\Translate;
use App\Models\Base;
use App\Utils\HttpUtils;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;
/**
* Class InquiryRelateDomain
* @package App\Models\Inquiry
* @author zbj
* @date 2025/4/12
*/
class InquiryRelateDomain extends Base
{
//设置关联表名
protected $table = 'gl_inquiry_relate_domain';
/**
* 获取关联域名
* @throws \Exception
* @author zbj
* @date 2025/4/12
*/
public static function getRelateDomain($domain, $k = 'domain'){
$list_cache_key = 'RelateDomainList_' . $k;
$data = Cache::get($list_cache_key);
if(!$data){
$data = [];
$page = 1;
while (true) {
try {
$res = HttpUtils::get('https://www.cmer.site/api/globalso_site', ['pagesize' => 100, 'page' => $page]);
if($res) {
$res = Arr::s2a($res);
$arr = [];
foreach ($res['data']['data'] as $item){
if($k == 'domain'){
$arr[$item['domain']] = $item['globalso_domain'];
}else{
$arr[$item['globalso_domain']] = $item['domain'];
}
}
$data = array_merge($data, $arr);
if ($res['data']['last_page'] == $page) {
break;
}
}
$page++;
} catch (\Exception | GuzzleException $e) {
throw new \Exception('关联域名接口错误' . $e->getMessage());
}
}
Cache::put($list_cache_key, $data, 3600);
}
if(empty($data[$domain])){
$domainPrefix = explode(".",$domain);
if (!empty($domainPrefix)){
if($domainPrefix[0] == 'm'){
$domain = "www.".$domainPrefix[1].".".$domainPrefix[2];
}else{
$isLang = Translate::getTls($domainPrefix[0]);
if ($isLang) {
$domain = "www.".$domainPrefix[1].".".$domainPrefix[2];
}
}
}
if(!Str::startsWith($domain, 'www')){
$domain = 'www.' . $domain;
}
}
return $data[$domain]??'';
}
}