切换导航条
此项目
正在载入...
登录
周海龙
/
globalso-v6-c-customer
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
刘锟
8 months ago
提交
ae10b156bf4a7f361abde10596f9f95e93ae2415
1 个父辈
3285eaf2
update
隐藏空白字符变更
内嵌
并排对比
正在显示
2 个修改的文件
包含
32 行增加
和
55 行删除
app/Console/Commands/DownloadFile.php
app/Http/Controllers/Api/NoticeController.php
app/Console/Commands/DownloadFile.php
查看文件 @
ae10b15
...
...
@@ -52,18 +52,7 @@ public function websiteHandle()
$this
->
output
(
'网站更新开始'
);
$noticeController
=
new
NoticeController
();
$infoArr
=
json_decode
(
$info
,
true
);
if
(
$infoArr
[
"num"
]
<
3
)
{
$isSuccess
=
$noticeController
->
websiteHtmlHandle
(
$infoArr
[
"url"
],
$infoArr
[
"domain"
]);
if
(
$isSuccess
)
{
Redis
::
del
(
'handle_html'
);
}
else
{
$infoArr
[
"num"
]
++
;
Redis
::
set
(
'handle_html'
,
json_encode
(
$infoArr
));
}
}
else
{
Redis
::
del
(
'handle_html'
);
Log
::
info
(
"网站处理失败!"
,
$infoArr
);
}
$noticeController
->
websiteHtmlHandle
(
$infoArr
[
"zip_count"
],
$infoArr
[
"domain"
]);
$this
->
output
(
'网站更新结束'
);
}
return
true
;
...
...
app/Http/Controllers/Api/NoticeController.php
查看文件 @
ae10b15
...
...
@@ -215,6 +215,7 @@ public function websiteHtml(Request $request)
{
$domain
=
$request
->
getHost
();
$site_token
=
$request
->
input
(
'site_token'
);
$zip_count
=
$request
->
input
(
'zip_count'
);
$token
=
env
(
"SECRET_TOKEN"
);
$pid
=
env
(
"MERCHANT_NUMBER"
);
$apiUrl
=
env
(
"API_URL"
);
...
...
@@ -232,8 +233,7 @@ public function websiteHtml(Request $request)
try
{
$res
=
$this
->
curlGet
(
$requestUrl
);
$url
=
isset
(
$res
[
"data"
][
"url"
])
&&
!
empty
(
$res
[
"data"
][
"url"
])
?
urldecode
(
$res
[
"data"
][
"url"
])
:
""
;
if
(
$res
[
"status"
]
!=
self
::
SUCCESS
||
$url
==
""
)
{
if
(
$res
[
"status"
]
!=
self
::
SUCCESS
)
{
$msg
=
isset
(
$res
[
"message"
])
&&
!
empty
(
$res
[
"message"
])
?
$res
[
"message"
]
:
"请求失败!"
;
return
$this
->
error
(
$msg
);
}
...
...
@@ -242,60 +242,48 @@ public function websiteHtml(Request $request)
}
$info
=
[
"url"
=>
$url
,
"domain"
=>
$domain
,
"
num"
=>
0
,
"
zip_count"
=>
$zip_count
];
$info
=
json_encode
(
$info
);
Redis
::
set
(
'handle_html'
,
$info
);
Redis
::
set
(
'handle_html'
,
$info
);
return
$this
->
success
();
//return $this->websiteHtmlHandle($url, $domain);
}
/**
* 网站html解压
* @param $
url
* @param $
zip_count
* @param $domain
* @return string
*/
public
function
websiteHtmlHandle
(
$
url
,
$domain
)
public
function
websiteHtmlHandle
(
$
zip_count
,
$domain
)
{
$pathInfo
=
pathinfo
(
$url
);
$extension
=
$pathInfo
[
'extension'
];
//只允许解压zip格式文件
if
(
in_array
(
$extension
,
[
"zip"
]))
{
try
{
$targetFile
=
$this
->
downLoadFile
(
$url
);
if
(
$targetFile
==
""
){
return
false
;
}
$zip
=
new
ZipArchive
();
if
(
$zip
->
open
(
$targetFile
)
===
TRUE
)
{
$outputFolder
=
public_path
(
$domain
);
if
(
!
is_dir
(
$outputFolder
))
{
mkdir
(
$outputFolder
,
0777
,
true
);
}
// 解压缩文件,保留原文件结构
$zip
->
extractTo
(
$outputFolder
);
$zip
->
close
();
$this
->
deleteDirectory
(
$targetFile
);
$transmitUrl
=
env
(
"TRANSMIT_URL"
);
$this
->
httpPost
(
$transmitUrl
.
"api/selfSiteNotify/"
,
json_encode
([
'domain'
=>
$domain
]));
}
else
{
// 处理打开压缩文件失败的情况
$this
->
output
(
"解压失败!"
);
return
false
;
$api_url
=
env
(
'API_URL'
);
for
(
$i
=
0
;
$i
<=
$zip_count
;
$i
++
)
{
$targetFile
=
$this
->
downLoadFile
(
$api_url
.
$domain
.
'_part'
.
$i
.
'.zip'
);
if
(
$targetFile
==
""
)
{
$this
->
output
(
'文件 '
.
$targetFile
.
' 不存在'
);
continue
;
}
$zip
=
new
ZipArchive
();
if
(
$zip
->
open
(
$targetFile
)
===
TRUE
)
{
$outputFolder
=
public_path
(
$domain
);
if
(
!
is_dir
(
$outputFolder
))
{
mkdir
(
$outputFolder
,
0777
,
true
);
}
}
catch
(
\Exception
$e
)
{
$this
->
output
(
$this
->
error
(
$e
->
getMessage
()));
return
false
;
// 解压缩文件,保留原文件结构
$zip
->
extractTo
(
$outputFolder
);
$zip
->
close
();
$this
->
deleteDirectory
(
$targetFile
);
}
else
{
// 处理打开压缩文件失败的情况
$this
->
output
(
'解压文件 '
.
$targetFile
.
' 失败'
);
continue
;
}
}
else
{
$this
->
output
(
"不允许解压改格式压缩包!"
);
return
false
;
}
return
true
;
$transmitUrl
=
env
(
"TRANSMIT_URL"
);
$this
->
httpPost
(
$transmitUrl
.
"api/selfSiteNotify/"
,
json_encode
([
'domain'
=>
$domain
]));
}
/**
...
...
@@ -310,7 +298,7 @@ public function downLoadFile($url)
mkdir
(
$savePath
,
0777
,
true
);
}
$targetFile
=
$savePath
.
'/'
.
basename
(
$url
);
if
(
!
file_exists
(
$targetFile
))
{
if
(
!
file_exists
(
$targetFile
))
{
$file
=
fopen
(
$targetFile
,
'w'
);
fclose
(
$file
);
chmod
(
$targetFile
,
0755
);
...
...
请
注册
或
登录
后发表评论