From 329b1af0c0e4462627af019c6b8251ccfa8c17f2 Mon Sep 17 00:00:00 2001 From: panliang <1163816051@qq.com> Date: Wed, 18 Sep 2024 11:08:20 +0800 Subject: [PATCH] test oss --- app/Http/Controllers/Api/OssController.php | 54 ++++++++++++++++++++++ routes/api.php | 3 ++ tests/Feature/ExampleTest.php | 7 +-- 3 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 app/Http/Controllers/Api/OssController.php diff --git a/app/Http/Controllers/Api/OssController.php b/app/Http/Controllers/Api/OssController.php new file mode 100644 index 0000000..74ca3e6 --- /dev/null +++ b/app/Http/Controllers/Api/OssController.php @@ -0,0 +1,54 @@ +input('upload', 'upload/'); + // 请求有效期(30秒), 超过时间将无法上传文件 + $expire = 30; + $end = time() + $expire; + // 文件大小(1000MB), 超过将无法上传文件 + $max = 1048576000; + $arr = [ + 'expiration' => str_replace('+00:00', '.000Z', gmdate('c', $end)), + 'conditions' => [ + ['content-length-range', 0, $max], + ['starts-with', '$key', $dir] + ] + ]; + + $policy = json_encode($arr); + $base64_policy = base64_encode($policy); + $string_to_sign = $base64_policy; + $signature = base64_encode(hash_hmac('sha1', $string_to_sign, $key, true)); + + $data = [ + 'accessid' => $id, + 'host' => $host, + 'policy' => $base64_policy, + 'signature' => $signature, + 'expire' => $end, + 'dir' => $dir, + 'url' => $url, + ]; + + return $this->json($data); + } +} diff --git a/routes/api.php b/routes/api.php index 700acc6..7df45cf 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,6 +1,7 @@ make(Generator::class); - - dump($faker->name); + dump(now()); } }