You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.1 KiB
79 lines
2.1 KiB
<?php
|
|
|
|
namespace app\base\controller\oss\platform;
|
|
|
|
use app\BaseController;
|
|
use think\App;
|
|
use think\facade\Request;
|
|
|
|
class Callback extends BaseController
|
|
{
|
|
|
|
/**
|
|
* 从服务器上传到OSS服务器源文件删除
|
|
* @date 2022-06-28
|
|
*/
|
|
public function uploadCallback()
|
|
{
|
|
$header = Request::header();
|
|
$data = input('post.');
|
|
|
|
// 验证签名的参数
|
|
$authorization_base64 = $header['authorization'];
|
|
$oss_pub_key_url_base64 = $header['x-oss-pub-key-url'];
|
|
|
|
// 参数不存在,则抛出异常
|
|
if (!$authorization_base64 || !$oss_pub_key_url_base64) {
|
|
header("http/1.1 403 Forbidden");
|
|
exit();
|
|
}
|
|
|
|
// 获取公钥链接
|
|
$oss_pub_key_url = base64_decode($oss_pub_key_url_base64);
|
|
|
|
// 获取公钥
|
|
$pub_key = http_data_get($oss_pub_key_url, 0);
|
|
|
|
// 公钥不存在,抛出异常
|
|
if (!$pub_key) {
|
|
header("http/1.1 403 Forbidden");
|
|
exit();
|
|
}
|
|
|
|
// 获取回调body
|
|
$body = file_get_contents('php://input');
|
|
|
|
// 拼接待签名字符串
|
|
$auth_str = '';
|
|
// 当前完整URL
|
|
$path = Request::url();
|
|
// 返回字符串在另一个字符串中第一次出现的位置。如果没有找到该字符串,则返回 false
|
|
$pos = strpos($path, '?');
|
|
if ($pos === false) {
|
|
$auth_str = urldecode($path) . "\n" . $body;
|
|
} else {
|
|
$auth_str = urldecode(substr($path, 0, $pos)) . substr($path, $pos, strlen($path) - $pos) . "\n" . $body;
|
|
}
|
|
|
|
// 验证签名
|
|
$ok = verifySignData($auth_str, $authorization_base64, $pub_key, 0, OPENSSL_ALGO_MD5);
|
|
|
|
// 验证没有成功
|
|
if (!$ok) {
|
|
header("http/1.1 403 Forbidden");
|
|
exit();
|
|
}
|
|
|
|
// 删除文件
|
|
$file_path = $data['file_path'];
|
|
unlink($file_path);
|
|
|
|
header("Content-Type: application/json");
|
|
$data = [
|
|
"Status" => "Ok"
|
|
];
|
|
echo json_encode($data);
|
|
}
|
|
|
|
}
|