Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
loveisland
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘小敏
loveisland
Commits
00042cf1
Commit
00042cf1
authored
Jul 01, 2026
by
刘小敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(hwobs): 支持 V4 签名算法并添加调试日志
parent
a7408baf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
4 deletions
+32
-4
bootstrap.js
addons/hwobs/bootstrap.js
+2
-2
Index.php
addons/hwobs/controller/Index.php
+30
-2
No files found.
addons/hwobs/bootstrap.js
View file @
00042cf1
...
@@ -252,8 +252,8 @@ if (typeof Config.upload.storage !== 'undefined' && Config.upload.storage === 'h
...
@@ -252,8 +252,8 @@ if (typeof Config.upload.storage !== 'undefined' && Config.upload.storage === 'h
this
.
on
(
"sending"
,
function
(
file
,
xhr
,
formData
)
{
this
.
on
(
"sending"
,
function
(
file
,
xhr
,
formData
)
{
var
that
=
this
;
var
that
=
this
;
var
_send
=
xhr
.
send
;
var
_send
=
xhr
.
send
;
//仅允许部分字段
//仅允许部分字段
(V4签名需要额外字段)
var
allowFields
=
[
'partNumber'
,
'uploadId'
,
'key'
,
'AccessKeyId'
,
'policy'
,
'signature'
,
'file'
];
var
allowFields
=
[
'partNumber'
,
'uploadId'
,
'key'
,
'AccessKeyId'
,
'policy'
,
'signature'
,
'
X-Amz-Algorithm'
,
'X-Amz-Credential'
,
'X-Amz-Date'
,
'acl'
,
'
file'
];
formData
.
forEach
(
function
(
value
,
key
)
{
formData
.
forEach
(
function
(
value
,
key
)
{
if
(
allowFields
.
indexOf
(
key
)
<
0
)
{
if
(
allowFields
.
indexOf
(
key
)
<
0
)
{
formData
.
delete
(
key
);
formData
.
delete
(
key
);
...
...
addons/hwobs/controller/Index.php
View file @
00042cf1
...
@@ -61,7 +61,10 @@ class Index extends Controller
...
@@ -61,7 +61,10 @@ class Index extends Controller
$obs
=
new
ObsClient
([
$obs
=
new
ObsClient
([
'key'
=>
$config
[
'accessKey'
],
'key'
=>
$config
[
'accessKey'
],
'secret'
=>
$config
[
'secretKey'
],
'secret'
=>
$config
[
'secretKey'
],
'endpoint'
=>
$config
[
'endpoint'
]
'endpoint'
=>
$config
[
'endpoint'
],
'region'
=>
'cn-east-3'
,
'region'
=>
'cn-east-3'
,
// ← 新增:V4 签名必需
'signature'
=>
'v4'
// ← 新增:使用 V4 签名算法
]);
]);
if
(
$chunk
)
{
if
(
$chunk
)
{
$partSize
=
$this
->
request
->
post
(
"chunksize"
);
$partSize
=
$this
->
request
->
post
(
"chunksize"
);
...
@@ -92,10 +95,33 @@ class Index extends Controller
...
@@ -92,10 +95,33 @@ class Index extends Controller
$params
[
'AccessKeyId'
]
=
$config
[
'accessKey'
];
$params
[
'AccessKeyId'
]
=
$config
[
'accessKey'
];
$params
[
'policy'
]
=
$signature
[
'Policy'
];
$params
[
'policy'
]
=
$signature
[
'Policy'
];
$params
[
'signature'
]
=
$signature
[
'Signature'
];
$params
[
'signature'
]
=
$signature
[
'Signature'
];
// V4 签名需要额外传递以下字段给前端
if
(
isset
(
$signature
[
'Algorithm'
]))
{
$params
[
'X-Amz-Algorithm'
]
=
$signature
[
'Algorithm'
];
$params
[
'X-Amz-Credential'
]
=
$signature
[
'Credential'
];
$params
[
'X-Amz-Date'
]
=
$signature
[
'Date'
];
}
$params
[
'acl'
]
=
'public-read'
;
// 传递 ACL 参数给前端
$params
[
'acl'
]
=
'public-read'
;
// 传递 ACL 参数给前端
}
}
// DEBUG: 写日志排查签名内容
file_put_contents
(
ROOT_PATH
.
'addons'
.
DS
.
'hwobs'
.
DS
.
'debug.log'
,
date
(
'Y-m-d H:i:s'
)
.
"
\n
"
.
"Method: "
.
(
isset
(
$signature
[
'Algorithm'
])
?
'V4'
:
'V2'
)
.
"
\n
"
.
"Algorithm: "
.
(
isset
(
$signature
[
'Algorithm'
])
?
$signature
[
'Algorithm'
]
:
'N/A'
)
.
"
\n
"
.
"Credential: "
.
(
isset
(
$signature
[
'Credential'
])
?
$signature
[
'Credential'
]
:
'N/A'
)
.
"
\n
"
.
"Date: "
.
(
isset
(
$signature
[
'Date'
])
?
$signature
[
'Date'
]
:
'N/A'
)
.
"
\n
"
.
"Policy base64: "
.
substr
(
$signature
[
'Policy'
],
0
,
50
)
.
"...
\n
"
.
"Signature: "
.
substr
(
$signature
[
'Signature'
],
0
,
20
)
.
"...
\n
"
.
"---
\n
"
,
FILE_APPEND
);
$params
[
'headers'
]
=
$headers
;
$params
[
'headers'
]
=
$headers
;
$params
[
'date'
]
=
$date
;
$params
[
'date'
]
=
$date
;
// DEBUG: 记录返回给前端的 params 里 V4 字段情况
file_put_contents
(
ROOT_PATH
.
'addons'
.
DS
.
'hwobs'
.
DS
.
'debug.log'
,
"params keys: "
.
implode
(
', '
,
array_keys
(
$params
))
.
"
\n
"
.
"has X-Amz-Algorithm: "
.
(
isset
(
$params
[
'X-Amz-Algorithm'
])
?
'YES'
:
'NO'
)
.
"
\n
"
.
"has X-Amz-Credential: "
.
(
isset
(
$params
[
'X-Amz-Credential'
])
?
'YES'
:
'NO'
)
.
"
\n
"
.
"has X-Amz-Date: "
.
(
isset
(
$params
[
'X-Amz-Date'
])
?
'YES'
:
'NO'
)
.
"
\n
"
.
"=== END DEBUG ===
\n\n
"
,
FILE_APPEND
);
$this
->
success
(
''
,
null
,
$params
);
$this
->
success
(
''
,
null
,
$params
);
}
}
...
@@ -118,7 +144,9 @@ class Index extends Controller
...
@@ -118,7 +144,9 @@ class Index extends Controller
$obs
=
new
ObsClient
([
$obs
=
new
ObsClient
([
'key'
=>
$config
[
'accessKey'
],
'key'
=>
$config
[
'accessKey'
],
'secret'
=>
$config
[
'secretKey'
],
'secret'
=>
$config
[
'secretKey'
],
'endpoint'
=>
$config
[
'endpoint'
]
'endpoint'
=>
$config
[
'endpoint'
],
'region'
=>
'cn-east-3'
,
'signature'
=>
'v4'
]);
]);
//检测删除文件或附件
//检测删除文件或附件
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment