UpdateService.php
4.3 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
namespace App\Services\Html;
use App\Models\Project\UpdateLog;
use App\Models\Project\UpdateOldInfo;
class UpdateService
{
/**
* 获取项目升级情况
* @param $project_id
* @param $domain
* @return array
* @author Akun
* @date 2023/12/01 10:32
*/
public static function getUpdateInfo($project_id)
{
$is_update = 0;
$is_language_update = 0;
$old_domain_online = $old_domain_test = '';
$update_info = UpdateLog::where('project_id', $project_id)->whereNotIn('api_type', ['category', 'website_info', 'tag', 'category_news'])->get();
if ($update_info->count() > 0) {
$is_update = 1;
$is_language_update = 1;
foreach ($update_info as $value) {
if ($value->collect_status != 1) {
$is_language_update = 0;
}
if ($value->collect_status == 0) {
$is_update = 0;
}
}
$old_domain_arr = parse_url($update_info[0]['api_url']);
$old_info = self::getOldInfo($project_id, $old_domain_arr['host']);
$old_domain_test = $old_info['old_domain_test'];
$old_domain_online = $old_info['old_domain_online'];
}
return [
'is_update' => $is_update,
'is_language_update' => $is_language_update,
'old_domain_test' => $old_domain_test,
'old_domain_online' => $old_domain_online
];
}
public static function getOldInfo($project_id, $domain)
{
$return = [
'old_domain_test' => $domain,
'old_domain_online' => $domain
];
$info = UpdateOldInfo::where('project_id', $project_id)->first();
if (!$info) {
$url_web_config = 'https://' . $domain . '/wp-content/cache/user_config.text';
$data_config = [];
try {
$data_config = self::curlGet($url_web_config);
} catch (\Exception $e) {
}
if ($data_config) {
$link_type = $data_config['link_type'] ?? 0;
$home_url_arr = parse_url($data_config['home_url'] ?? '');
$old_domain_test = $home_url_arr['host'] ?? '';
$web_url_arr = parse_url($data_config['web_url_domain'] ?? '');
$old_domain_online = $web_url_arr['host'] ?? '';
if ($old_domain_test || $old_domain_online) {
$info = new UpdateOldInfo();
$info->project_id = $project_id;
$info->link_type = $link_type;
$info->old_domain_test = $old_domain_test ?: $domain;
$info->old_domain_online = $old_domain_online ?: $domain;
$info->save();
}
$old_domain_test && $return['old_domain_test'] = $old_domain_test;
$old_domain_online && $return['old_domain_test'] = $old_domain_online;
}
} else {
$return['old_domain_test'] = $info['old_domain_test'];
$return['old_domain_online'] = $info['old_domain_online'];
}
return $return;
}
/**
* 远程请求
* @param $url
* @return mixed
* @author Akun
* @date 2023/11/29 14:23
*/
public static function curlGet($url)
{
$header = array(
'Expect:',
'Content-Type: application/json; charset=utf-8'
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSLVERSION, 'all');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$content = curl_exec($ch);
curl_close($ch);
return json_decode($content, true);
}
}