From 8fa3f12d7c6a97cdac8f07b9c4f4b367a88fffdb Mon Sep 17 00:00:00 2001 From: Anyon Date: Sat, 21 Dec 2019 15:01:44 +0800 Subject: [PATCH] ComposerUpdate --- app/admin/controller/api/Upload.php | 4 +- composer.lock | 8 +-- vendor/composer/installed.json | 8 +-- vendor/services.php | 2 +- vendor/zoujingli/think-library/src/common.php | 18 +----- .../think-library/src/extend/CodeExtend.php | 22 +++---- .../think-library/src/extend/HttpExtend.php | 59 ++++++++++++++++--- .../src/storage/AliossStorage.php | 24 +++----- .../src/storage/LocalStorage.php | 2 +- .../src/storage/QiniuStorage.php | 27 +++------ 10 files changed, 92 insertions(+), 82 deletions(-) diff --git a/app/admin/controller/api/Upload.php b/app/admin/controller/api/Upload.php index 7e426a71f..d949f236a 100644 --- a/app/admin/controller/api/Upload.php +++ b/app/admin/controller/api/Upload.php @@ -132,11 +132,11 @@ class Upload extends Controller */ private function getType() { - $this->uptype = input('uptype'); + $this->uptype = strtolower(input('uptype', '')); if (!in_array($this->uptype, ['local', 'qiniu', 'alioss'])) { $this->uptype = sysconf('storage.type'); } - return $this->uptype; + return strtolower($this->uptype); } /** diff --git a/composer.lock b/composer.lock index 6ad8c06f4..4ac273251 100644 --- a/composer.lock +++ b/composer.lock @@ -909,12 +909,12 @@ "source": { "type": "git", "url": "https://github.com/zoujingli/ThinkLibrary.git", - "reference": "5df24247da39c5b68c3bce2153fe5449f1caabd1" + "reference": "b5976aed117fc4d0435723235a6cf258322a18a0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/5df24247da39c5b68c3bce2153fe5449f1caabd1", - "reference": "5df24247da39c5b68c3bce2153fe5449f1caabd1", + "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/b5976aed117fc4d0435723235a6cf258322a18a0", + "reference": "b5976aed117fc4d0435723235a6cf258322a18a0", "shasum": "", "mirrors": [ { @@ -958,7 +958,7 @@ ], "description": "ThinkPHP v6.0 Development Library", "homepage": "http://framework.thinkadmin.top", - "time": "2019-12-20T03:07:55+00:00" + "time": "2019-12-21T06:59:41+00:00" }, { "name": "zoujingli/wechat-developer", diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 666b3d2b6..160d08dcc 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -935,12 +935,12 @@ "source": { "type": "git", "url": "https://github.com/zoujingli/ThinkLibrary.git", - "reference": "5df24247da39c5b68c3bce2153fe5449f1caabd1" + "reference": "b5976aed117fc4d0435723235a6cf258322a18a0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/5df24247da39c5b68c3bce2153fe5449f1caabd1", - "reference": "5df24247da39c5b68c3bce2153fe5449f1caabd1", + "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/b5976aed117fc4d0435723235a6cf258322a18a0", + "reference": "b5976aed117fc4d0435723235a6cf258322a18a0", "shasum": "", "mirrors": [ { @@ -956,7 +956,7 @@ "ext-json": "*", "topthink/framework": "^6.0" }, - "time": "2019-12-20T03:07:55+00:00", + "time": "2019-12-21T06:59:41+00:00", "type": "library", "extra": { "think": { diff --git a/vendor/services.php b/vendor/services.php index a66b2b664..ca81da57e 100644 --- a/vendor/services.php +++ b/vendor/services.php @@ -1,5 +1,5 @@ 'think\\app\\Service', diff --git a/vendor/zoujingli/think-library/src/common.php b/vendor/zoujingli/think-library/src/common.php index 6b42f5be7..4ec8e0a70 100644 --- a/vendor/zoujingli/think-library/src/common.php +++ b/vendor/zoujingli/think-library/src/common.php @@ -33,7 +33,6 @@ if (!function_exists('p')) { SystemService::instance()->putDebug($data, $new, $file); } } - if (!function_exists('auth')) { /** * 访问权限检查 @@ -46,7 +45,6 @@ if (!function_exists('auth')) { return AdminService::instance()->check($node); } } - if (!function_exists('sysconf')) { /** * 获取或配置系统参数 @@ -66,7 +64,6 @@ if (!function_exists('sysconf')) { } } } - if (!function_exists('sysdata')) { /** * JSON 数据读取与存储 @@ -86,7 +83,6 @@ if (!function_exists('sysdata')) { } } } - if (!function_exists('sysqueue')) { /** * 注册异步处理任务 @@ -106,7 +102,6 @@ if (!function_exists('sysqueue')) { return QueueService::instance()->register($title, $command, $later, $data, $rscript); } } - if (!function_exists('systoken')) { /** * 生成 CSRF-TOKEN 参数 @@ -119,7 +114,6 @@ if (!function_exists('systoken')) { return isset($result['token']) ? $result['token'] : ''; } } - if (!function_exists('sysoplog')) { /** * 写入系统日志 @@ -132,7 +126,6 @@ if (!function_exists('sysoplog')) { return SystemService::instance()->setOplog($action, $content); } } - if (!function_exists('encode')) { /** * 加密 UTF8 字符串 @@ -146,7 +139,6 @@ if (!function_exists('encode')) { return $chars; } } - if (!function_exists('decode')) { /** * 解密 UTF8 字符串 @@ -162,7 +154,6 @@ if (!function_exists('decode')) { return iconv('GBK//TRANSLIT', 'UTF-8', $chars); } } - if (!function_exists('http_get')) { /** * 以get模拟网络请求 @@ -176,7 +167,6 @@ if (!function_exists('http_get')) { return HttpExtend::get($url, $query, $options); } } - if (!function_exists('http_post')) { /** * 以post模拟网络请求 @@ -190,7 +180,6 @@ if (!function_exists('http_post')) { return HttpExtend::post($url, $data, $options); } } - if (!function_exists('data_save')) { /** * 数据增量保存 @@ -208,7 +197,6 @@ if (!function_exists('data_save')) { return SystemService::instance()->save($dbQuery, $data, $key, $where); } } - if (!function_exists('format_datetime')) { /** * 日期格式标准输出 @@ -216,7 +204,7 @@ if (!function_exists('format_datetime')) { * @param string $format 输出格式 * @return false|string */ - function format_datetime($datetime, $format = 'Y年m月d日 H:i:s') + function format_datetime($datetime, $format = 'Y年m月d日 H:i:s'): string { if (empty($datetime)) return '-'; if (is_numeric($datetime)) { @@ -226,7 +214,6 @@ if (!function_exists('format_datetime')) { } } } - if (!function_exists('enbase64url')) { /** * Base64安全URL编码 @@ -249,7 +236,6 @@ if (!function_exists('debase64url')) { return base64_decode(str_pad(strtr($string, '-_', '+/'), strlen($string) % 4, '=', STR_PAD_RIGHT)); } } - if (!function_exists('down_file')) { /** * 下载远程文件到本地 @@ -258,7 +244,7 @@ if (!function_exists('down_file')) { * @param integer $expire 强制本地存储时间 * @return string */ - function down_file($source, $force = false, $expire = 0) + function down_file($source, $force = false, $expire = 0): string { $result = Storage::down($source, $force, $expire); return isset($result['url']) ? $result['url'] : $source; diff --git a/vendor/zoujingli/think-library/src/extend/CodeExtend.php b/vendor/zoujingli/think-library/src/extend/CodeExtend.php index 913fd981f..93b82f76b 100644 --- a/vendor/zoujingli/think-library/src/extend/CodeExtend.php +++ b/vendor/zoujingli/think-library/src/extend/CodeExtend.php @@ -24,11 +24,11 @@ class CodeExtend { /** * 获取随机字符串编码 - * @param integer $length 字符串长度 + * @param integer $size 字符串长度 * @param integer $type 字符串类型(1纯数字,2纯字母,3数字字母) * @return string */ - public static function random($length = 10, $type = 1) + public static function random($size = 10, $type = 1) { $numbs = '0123456789'; $chars = 'abcdefghijklmnopqrstuvwxyz'; @@ -36,7 +36,7 @@ class CodeExtend if (intval($type) === 2) $chars = "a{$chars}"; if (intval($type) === 3) $chars = "{$numbs}{$chars}"; $string = $chars[rand(1, strlen($chars) - 1)]; - if (isset($chars)) while (strlen($string) < $length) { + if (isset($chars)) while (strlen($string) < $size) { $string .= $chars[rand(0, strlen($chars) - 1)]; } return $string; @@ -44,28 +44,28 @@ class CodeExtend /** * 唯一日期编码 - * @param integer $length + * @param integer $size * @return string */ - public static function uniqidDate($length = 16) + public static function uniqidDate($size = 16) { - if ($length < 14) $length = 14; + if ($size < 14) $size = 14; $string = date('Ymd') . (date('H') + date('i')) . date('s'); - while (strlen($string) < $length) $string .= rand(0, 9); + while (strlen($string) < $size) $string .= rand(0, 9); return $string; } /** * 唯一数字编码 - * @param integer $length + * @param integer $size * @return string */ - public static function uniqidNumber($length = 12) + public static function uniqidNumber($size = 12) { $time = time() . ''; - if ($length < 10) $length = 10; + if ($size < 10) $size = 10; $string = ($time[0] + $time[1]) . substr($time, 2) . rand(0, 9); - while (strlen($string) < $length) $string .= rand(0, 9); + while (strlen($string) < $size) $string .= rand(0, 9); return $string; } } \ No newline at end of file diff --git a/vendor/zoujingli/think-library/src/extend/HttpExtend.php b/vendor/zoujingli/think-library/src/extend/HttpExtend.php index 1fb7496b3..944fcc3a6 100644 --- a/vendor/zoujingli/think-library/src/extend/HttpExtend.php +++ b/vendor/zoujingli/think-library/src/extend/HttpExtend.php @@ -23,7 +23,7 @@ namespace think\admin\extend; class HttpExtend { /** - * 以get模拟网络请求 + * 以GET模拟网络请求 * @param string $location HTTP请求地址 * @param array|string $query GET请求参数 * @param array $options CURL请求参数 @@ -36,7 +36,7 @@ class HttpExtend } /** - * 以post模拟网络请求 + * 以 POST 模拟网络请求 * @param string $location HTTP请求地址 * @param array|string $data POST请求数据 * @param array $options CURL请求参数 @@ -48,6 +48,23 @@ class HttpExtend return self::request('post', $location, $options); } + /** + * 以 FormData 模拟网络请求 + * @param string $url 模拟请求地址 + * @param array $data 模拟请求参数数据 + * @param array $file 提交文件 [field,name,content] + * @param array $header 请求头部信息,默认带 Content-type + * @param string $method 模拟请求的方式 [GET,POST,PUT] + * @param boolean $returnHeader 是否返回头部信息 + * @return boolean|string + */ + public static function submit($url, array $data = [], array $file = [], array $header = [], $method = 'POST', $returnHeader = true) + { + list($boundary, $content) = self::buildFormData($data, $file); + $header[] = "Content-type:multipart/form-data;boundary={$boundary}"; + return self::request($method, $url, ['data' => $content, 'returnHeader' => $returnHeader, 'headers' => $header]); + } + /** * CURL模拟网络请求 * @param string $method 请求方法 @@ -107,7 +124,7 @@ class HttpExtend } /** - * POST数据过滤处理 + * 对 POST 数据过滤处理 * @param array $data 需要处理的数据 * @param boolean $build 是否编译数据 * @return array|string @@ -115,16 +132,40 @@ class HttpExtend private static function buildQueryData($data, $build = true) { if (!is_array($data)) return $data; - foreach ($data as $key => $value) if (is_object($value) && $value instanceof \CURLFile) { - $build = false; - } elseif (is_string($value) && class_exists('CURLFile', false) && stripos($value, '@') === 0) { - if (($filename = realpath(trim($value, '@'))) && file_exists($filename)) { - list($build, $data[$key]) = [false, new \CURLFile($filename)]; - } + foreach ($data as $key => $value) { + if (is_string($value) && stripos($value, '@') === 0 && class_exists('CURLFile')) { + if (file_exists($filename = realpath(ltrim($value, '@')))) { + list($build, $data[$key]) = [false, new \CURLFile($filename)]; + } + } elseif ($value instanceof \CURLFile) $build = false; } return $build ? http_build_query($data) : $data; } + /** + * 生成 FormData 格式数据内容 + * @param array $data 表单提交的数据 + * @param array $file 表单上传的文件 + * @return array + */ + private static function buildFormData(array $data = [], array $file = []) + { + list($line, $boundary) = [[], CodeExtend::random(18)]; + foreach ($data as $key => $value) { + $line[] = "--{$boundary}"; + $line[] = "Content-Disposition: form-data; name=\"{$key}\""; + $line[] = ""; + $line[] = $value; + } + if (is_array($file) && isset($file['field']) && isset($file['name'])) { + $line[] = "--{$boundary}"; + $line[] = "Content-Disposition: form-data; name=\"{$file['field']}\"; filename=\"{$file['name']}\""; + $line[] = ""; + $line[] = $file['content']; + } + $line[] = "--{$boundary}--"; + return [$boundary, join("\r\n", $line)]; + } /** * 获取浏览器代理信息 diff --git a/vendor/zoujingli/think-library/src/storage/AliossStorage.php b/vendor/zoujingli/think-library/src/storage/AliossStorage.php index 0bf0776d0..9787538b1 100644 --- a/vendor/zoujingli/think-library/src/storage/AliossStorage.php +++ b/vendor/zoujingli/think-library/src/storage/AliossStorage.php @@ -56,6 +56,7 @@ class AliossStorage extends Storage private $secretKey; /** + * 初始化入口 * @return $this * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException @@ -103,22 +104,13 @@ class AliossStorage extends Storage public function set($name, $file, $safe = false) { $token = $this->buildUploadToken($name); - list($attrs, $frontier) = [[], uniqid()]; - foreach (['key' => $name, 'policy' => $token['policy'], 'success_action_status' => '200', 'OSSAccessKeyId' => $this->accessKey, 'Signature' => $token['signature']] as $key => $value) { - $attrs[] = "--{$frontier}"; - $attrs[] = "Content-Disposition: form-data; name=\"{$key}\""; - $attrs[] = ""; - $attrs[] = $value; - } - $attrs[] = "--{$frontier}"; - $attrs[] = "Content-Disposition: form-data; name=\"file\"; filename=\"{$name}\""; - $attrs[] = ""; - $attrs[] = $file; - $attrs[] = "--{$frontier}--"; - $result = HttpExtend::request('POST', $this->upload(), [ - 'data' => join("\r\n", $attrs), 'returnHeader' => true, 'headers' => ["Content-type:multipart/form-data;boundary={$frontier}"], - ]); - if (is_numeric(stripos($result, '200 OK'))) { + $data = ['key' => $name]; + $data['policy'] = $token['policy']; + $data['Signature'] = $token['signature']; + $data['OSSAccessKeyId'] = $this->accessKey; + $data['success_action_status'] = '200'; + $file = ['field' => 'file', 'name' => $name, 'content' => $file]; + if (is_numeric(stripos(HttpExtend::submit($this->upload(), $data, $file), '200 OK'))) { return ['file' => $this->path($name, $safe), 'url' => $this->url($name, $safe), 'key' => $name]; } else { return []; diff --git a/vendor/zoujingli/think-library/src/storage/LocalStorage.php b/vendor/zoujingli/think-library/src/storage/LocalStorage.php index ed2d0f578..d2dfebaa0 100644 --- a/vendor/zoujingli/think-library/src/storage/LocalStorage.php +++ b/vendor/zoujingli/think-library/src/storage/LocalStorage.php @@ -25,7 +25,7 @@ use think\admin\Storage; class LocalStorage extends Storage { /** - * 存储引擎初始化 + * 初始化入口 * @return LocalStorage */ protected function initialize(): Storage diff --git a/vendor/zoujingli/think-library/src/storage/QiniuStorage.php b/vendor/zoujingli/think-library/src/storage/QiniuStorage.php index de020fea1..e06051fa1 100644 --- a/vendor/zoujingli/think-library/src/storage/QiniuStorage.php +++ b/vendor/zoujingli/think-library/src/storage/QiniuStorage.php @@ -31,7 +31,7 @@ class QiniuStorage extends Storage private $secretKey; /** - * 存储引擎初始化 + * 初始化入口 * @return $this * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException @@ -82,21 +82,10 @@ class QiniuStorage extends Storage public function set($name, $file, $safe = false) { $token = $this->buildUploadToken($name); - list($attrs, $frontier) = [[], uniqid()]; - foreach (['key' => $name, 'token' => $token, 'fileName' => $name] as $key => $value) { - $attrs[] = "--{$frontier}"; - $attrs[] = "Content-Disposition:form-data; name=\"{$key}\""; - $attrs[] = ""; - $attrs[] = $value; - } - $attrs[] = "--{$frontier}"; - $attrs[] = "Content-Disposition:form-data; name=\"file\"; filename=\"{$name}\""; - $attrs[] = ""; - $attrs[] = $file; - $attrs[] = "--{$frontier}--"; - return json_decode(HttpExtend::post($this->upload(), join("\r\n", $attrs), [ - 'headers' => ["Content-type:multipart/form-data;boundary={$frontier}"], - ]), true); + $data = ['key' => $name, 'token' => $token, 'fileName' => $name]; + $file = ['field' => "file", 'name' => $name, 'content' => $file]; + $result = HttpExtend::submit($this->upload(), $data, $file, [], 'POST', false); + return json_decode($result, true); } @@ -171,7 +160,7 @@ class QiniuStorage extends Storage { list($entry, $token) = $this->getAccessToken($name); $data = json_decode(HttpExtend::get("http://rs.qiniu.com/stat/{$entry}", [], ['headers' => ["Authorization: QBox {$token}"]]), true); - return isset($data['md5']) ? ['file' => $name, 'url' => $this->url($name, $safe), 'hash' => $data['md5'], 'key' => $name] : []; + return isset($data['md5']) ? ['file' => $name, 'url' => $this->url($name, $safe), 'key' => $name] : []; } /** @@ -211,7 +200,9 @@ class QiniuStorage extends Storage { $policy = $this->safeBase64(json_encode([ "deadline" => time() + $expires, "scope" => is_null($name) ? $this->bucket : "{$this->bucket}:{$name}", - 'returnBody' => json_encode(['uploaded' => true, 'filename' => '$(key)', 'url' => "{$this->prefix}$(key)"], JSON_UNESCAPED_UNICODE), + 'returnBody' => json_encode([ + 'uploaded' => true, 'filename' => '$(key)', 'file' => $name, 'url' => "{$this->prefix}$(key)", 'key' => $name, + ], JSON_UNESCAPED_UNICODE), ])); return "{$this->accessKey}:{$this->safeBase64(hash_hmac('sha1', $policy, $this->secretKey, true))}:{$policy}"; }