作者 刘锟

update

@@ -79,7 +79,7 @@ class HtmlCollect extends Command @@ -79,7 +79,7 @@ class HtmlCollect extends Command
79 $web_url_domain = $collect_info->domain; 79 $web_url_domain = $collect_info->domain;
80 $home_url = $collect_info->domain; 80 $home_url = $collect_info->domain;
81 $url_web_config = 'https://' . $collect_info->domain . '/wp-content/cache/user_config.text'; 81 $url_web_config = 'https://' . $collect_info->domain . '/wp-content/cache/user_config.text';
82 - $data_config = http_get($url_web_config, ['charset' => 'UTF-8']); 82 + $data_config = curl_c($url_web_config);
83 if ($data_config) { 83 if ($data_config) {
84 $web_url_arr = parse_url($data_config['web_url_domain'] ?? ''); 84 $web_url_arr = parse_url($data_config['web_url_domain'] ?? '');
85 if (isset($web_url_arr['host'])) { 85 if (isset($web_url_arr['host'])) {
@@ -94,20 +94,11 @@ class HtmlCollect extends Command @@ -94,20 +94,11 @@ class HtmlCollect extends Command
94 94
95 //采集html页面,下载资源到本地并替换 95 //采集html页面,下载资源到本地并替换
96 try { 96 try {
97 - $opts = [  
98 - 'http' => [  
99 - 'header' => 'User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0'  
100 - ],  
101 - 'ssl' => [  
102 - 'verify_peer' => false,  
103 - 'verify_peer_name' => false,  
104 - ]  
105 - ];  
106 - $html = file_get_contents('https://' . $collect_info->domain . $collect_info->route, false, stream_context_create($opts)); 97 + $html = curl_c('https://' . $collect_info->domain . $collect_info->route, false);
107 $source_list = $this->html_preg($html, $project_id, $collect_info->domain, $web_url_domain, $home_url); 98 $source_list = $this->html_preg($html, $project_id, $collect_info->domain, $web_url_domain, $home_url);
108 99
109 if ($source_list) { 100 if ($source_list) {
110 - $html = $this->upload_source($html, $source_list, $project_id, $opts); 101 + $html = $this->upload_source($html, $source_list, $project_id);
111 } 102 }
112 } catch (\Exception $e) { 103 } catch (\Exception $e) {
113 $collect_info->status = CollectTask::STATUS_FAIL; 104 $collect_info->status = CollectTask::STATUS_FAIL;
@@ -280,7 +271,7 @@ class HtmlCollect extends Command @@ -280,7 +271,7 @@ class HtmlCollect extends Command
280 } 271 }
281 272
282 //下载并替换资源 273 //下载并替换资源
283 - protected function upload_source($html, $source, $project_id, $opts) 274 + protected function upload_source($html, $source, $project_id)
284 { 275 {
285 foreach ($source as $vs) { 276 foreach ($source as $vs) {
286 277
@@ -298,7 +289,7 @@ class HtmlCollect extends Command @@ -298,7 +289,7 @@ class HtmlCollect extends Command
298 289
299 if (substr($new_source, -3, 3) == 'css') { 290 if (substr($new_source, -3, 3) == 'css') {
300 // 下载css文件中的资源 291 // 下载css文件中的资源
301 - $css_html = file_get_contents($vs['url_complete'], false, stream_context_create($opts)); 292 + $css_html = curl_c($vs['url_complete'], false);
302 preg_match_all("/url\(['\"](\s*[^>]+?)['\"]\)/i", $css_html, $result_css_source); 293 preg_match_all("/url\(['\"](\s*[^>]+?)['\"]\)/i", $css_html, $result_css_source);
303 $css_source = $result_css_source[1] ?? []; 294 $css_source = $result_css_source[1] ?? [];
304 295