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
c6761656
Commit
c6761656
authored
Jun 10, 2026
by
刘小敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
获取 OBS 临时上传凭证接口
parent
f6f3ed86
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
0 deletions
+61
-0
User.php
addons/shopro/controller/user/User.php
+55
-0
config.php
application/config.php
+6
-0
No files found.
addons/shopro/controller/user/User.php
View file @
c6761656
...
...
@@ -27,6 +27,61 @@ class User extends Common
}
/**
* 获取 OBS 临时上传凭证
* 小程序端使用此凭证直接调用 OBS 服务上传文件
*
* @return array
*/
public
function
getObsToken
()
{
// 获取华为云 OBS 配置
$accessKey
=
config
(
'obs.access_key'
,
''
);
$secretKey
=
config
(
'obs.secret_key'
,
''
);
$endpoint
=
config
(
'obs.endpoint'
,
''
);
$bucket
=
config
(
'obs.bucket'
,
''
);
// 检查配置是否完整
if
(
empty
(
$accessKey
)
||
empty
(
$secretKey
)
||
empty
(
$endpoint
)
||
empty
(
$bucket
))
{
$this
->
error
(
'OBS 配置未完成'
);
}
try
{
// 1. 生成上传目录(按日期分目录)
$dir
=
'upload/'
.
date
(
'Ymd'
)
.
'/'
;
// 2. 生成 Policy(有效期 1 小时)
$expireTime
=
time
()
+
3600
;
// 1小时后过期
$policy
=
[
'expiration'
=>
gmdate
(
'Y-m-d\TH:i:s\Z'
,
$expireTime
),
'conditions'
=>
[
[
'bucket'
=>
$bucket
],
[
'starts-with'
,
'$key'
,
$dir
],
[
'content-length-range'
,
0
,
104857600
]
// 限制最大 100MB
]
];
$policyBase64
=
base64_encode
(
json_encode
(
$policy
));
// 3. 生成 Signature(使用 HMAC-SHA1 签名)
$signature
=
base64_encode
(
hash_hmac
(
'sha1'
,
$policyBase64
,
$secretKey
,
true
));
// 4. 构建返回数据
$result
=
[
'accessKeyId'
=>
$accessKey
,
'policy'
=>
$policyBase64
,
'signature'
=>
$signature
,
'dir'
=>
$dir
,
'host'
=>
"https://
{
$bucket
}
.
{
$endpoint
}
"
];
$this
->
success
(
'获取成功'
,
$result
);
}
catch
(
\Exception
$e
)
{
$this
->
error
(
'获取 OBS 凭证失败: '
.
$e
->
getMessage
());
}
}
/**
* 用户数据
*/
public
function
data
()
...
...
application/config.php
View file @
c6761656
...
...
@@ -329,4 +329,10 @@ return [
'ai_hook'
=>
Env
::
get
(
'app.ai_hook'
,
''
),
],
'obs'
=>
[
'access_key'
=>
'HPUAWU3GPS8HEWX9JFLG'
,
'secret_key'
=>
'Jj7Vt1WnU69pWG6QplBmHBkaw6WM4oLU1AZa9Z9n'
,
'endpoint'
=>
'obs.cn-east-3.myhuaweicloud.com'
,
// 根据区域修改
'bucket'
=>
'beevera'
]
];
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