ComposerUpdate

This commit is contained in:
Anyon 2019-12-21 15:01:44 +08:00
parent 10593a8603
commit 8fa3f12d7c
10 changed files with 92 additions and 82 deletions

View File

@ -132,11 +132,11 @@ class Upload extends Controller
*/ */
private function getType() private function getType()
{ {
$this->uptype = input('uptype'); $this->uptype = strtolower(input('uptype', ''));
if (!in_array($this->uptype, ['local', 'qiniu', 'alioss'])) { if (!in_array($this->uptype, ['local', 'qiniu', 'alioss'])) {
$this->uptype = sysconf('storage.type'); $this->uptype = sysconf('storage.type');
} }
return $this->uptype; return strtolower($this->uptype);
} }
/** /**

8
composer.lock generated
View File

@ -909,12 +909,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git", "url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "5df24247da39c5b68c3bce2153fe5449f1caabd1" "reference": "b5976aed117fc4d0435723235a6cf258322a18a0"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/5df24247da39c5b68c3bce2153fe5449f1caabd1", "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/b5976aed117fc4d0435723235a6cf258322a18a0",
"reference": "5df24247da39c5b68c3bce2153fe5449f1caabd1", "reference": "b5976aed117fc4d0435723235a6cf258322a18a0",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -958,7 +958,7 @@
], ],
"description": "ThinkPHP v6.0 Development Library", "description": "ThinkPHP v6.0 Development Library",
"homepage": "http://framework.thinkadmin.top", "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", "name": "zoujingli/wechat-developer",

View File

@ -935,12 +935,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git", "url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "5df24247da39c5b68c3bce2153fe5449f1caabd1" "reference": "b5976aed117fc4d0435723235a6cf258322a18a0"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/5df24247da39c5b68c3bce2153fe5449f1caabd1", "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/b5976aed117fc4d0435723235a6cf258322a18a0",
"reference": "5df24247da39c5b68c3bce2153fe5449f1caabd1", "reference": "b5976aed117fc4d0435723235a6cf258322a18a0",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -956,7 +956,7 @@
"ext-json": "*", "ext-json": "*",
"topthink/framework": "^6.0" "topthink/framework": "^6.0"
}, },
"time": "2019-12-20T03:07:55+00:00", "time": "2019-12-21T06:59:41+00:00",
"type": "library", "type": "library",
"extra": { "extra": {
"think": { "think": {

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php <?php
// This file is automatically generated at:2019-12-20 14:01:01 // This file is automatically generated at:2019-12-21 15:01:30
declare (strict_types = 1); declare (strict_types = 1);
return array ( return array (
0 => 'think\\app\\Service', 0 => 'think\\app\\Service',

View File

@ -33,7 +33,6 @@ if (!function_exists('p')) {
SystemService::instance()->putDebug($data, $new, $file); SystemService::instance()->putDebug($data, $new, $file);
} }
} }
if (!function_exists('auth')) { if (!function_exists('auth')) {
/** /**
* 访问权限检查 * 访问权限检查
@ -46,7 +45,6 @@ if (!function_exists('auth')) {
return AdminService::instance()->check($node); return AdminService::instance()->check($node);
} }
} }
if (!function_exists('sysconf')) { if (!function_exists('sysconf')) {
/** /**
* 获取或配置系统参数 * 获取或配置系统参数
@ -66,7 +64,6 @@ if (!function_exists('sysconf')) {
} }
} }
} }
if (!function_exists('sysdata')) { if (!function_exists('sysdata')) {
/** /**
* JSON 数据读取与存储 * JSON 数据读取与存储
@ -86,7 +83,6 @@ if (!function_exists('sysdata')) {
} }
} }
} }
if (!function_exists('sysqueue')) { if (!function_exists('sysqueue')) {
/** /**
* 注册异步处理任务 * 注册异步处理任务
@ -106,7 +102,6 @@ if (!function_exists('sysqueue')) {
return QueueService::instance()->register($title, $command, $later, $data, $rscript); return QueueService::instance()->register($title, $command, $later, $data, $rscript);
} }
} }
if (!function_exists('systoken')) { if (!function_exists('systoken')) {
/** /**
* 生成 CSRF-TOKEN 参数 * 生成 CSRF-TOKEN 参数
@ -119,7 +114,6 @@ if (!function_exists('systoken')) {
return isset($result['token']) ? $result['token'] : ''; return isset($result['token']) ? $result['token'] : '';
} }
} }
if (!function_exists('sysoplog')) { if (!function_exists('sysoplog')) {
/** /**
* 写入系统日志 * 写入系统日志
@ -132,7 +126,6 @@ if (!function_exists('sysoplog')) {
return SystemService::instance()->setOplog($action, $content); return SystemService::instance()->setOplog($action, $content);
} }
} }
if (!function_exists('encode')) { if (!function_exists('encode')) {
/** /**
* 加密 UTF8 字符串 * 加密 UTF8 字符串
@ -146,7 +139,6 @@ if (!function_exists('encode')) {
return $chars; return $chars;
} }
} }
if (!function_exists('decode')) { if (!function_exists('decode')) {
/** /**
* 解密 UTF8 字符串 * 解密 UTF8 字符串
@ -162,7 +154,6 @@ if (!function_exists('decode')) {
return iconv('GBK//TRANSLIT', 'UTF-8', $chars); return iconv('GBK//TRANSLIT', 'UTF-8', $chars);
} }
} }
if (!function_exists('http_get')) { if (!function_exists('http_get')) {
/** /**
* 以get模拟网络请求 * 以get模拟网络请求
@ -176,7 +167,6 @@ if (!function_exists('http_get')) {
return HttpExtend::get($url, $query, $options); return HttpExtend::get($url, $query, $options);
} }
} }
if (!function_exists('http_post')) { if (!function_exists('http_post')) {
/** /**
* 以post模拟网络请求 * 以post模拟网络请求
@ -190,7 +180,6 @@ if (!function_exists('http_post')) {
return HttpExtend::post($url, $data, $options); return HttpExtend::post($url, $data, $options);
} }
} }
if (!function_exists('data_save')) { if (!function_exists('data_save')) {
/** /**
* 数据增量保存 * 数据增量保存
@ -208,7 +197,6 @@ if (!function_exists('data_save')) {
return SystemService::instance()->save($dbQuery, $data, $key, $where); return SystemService::instance()->save($dbQuery, $data, $key, $where);
} }
} }
if (!function_exists('format_datetime')) { if (!function_exists('format_datetime')) {
/** /**
* 日期格式标准输出 * 日期格式标准输出
@ -216,7 +204,7 @@ if (!function_exists('format_datetime')) {
* @param string $format 输出格式 * @param string $format 输出格式
* @return false|string * @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 (empty($datetime)) return '-';
if (is_numeric($datetime)) { if (is_numeric($datetime)) {
@ -226,7 +214,6 @@ if (!function_exists('format_datetime')) {
} }
} }
} }
if (!function_exists('enbase64url')) { if (!function_exists('enbase64url')) {
/** /**
* Base64安全URL编码 * Base64安全URL编码
@ -249,7 +236,6 @@ if (!function_exists('debase64url')) {
return base64_decode(str_pad(strtr($string, '-_', '+/'), strlen($string) % 4, '=', STR_PAD_RIGHT)); return base64_decode(str_pad(strtr($string, '-_', '+/'), strlen($string) % 4, '=', STR_PAD_RIGHT));
} }
} }
if (!function_exists('down_file')) { if (!function_exists('down_file')) {
/** /**
* 下载远程文件到本地 * 下载远程文件到本地
@ -258,7 +244,7 @@ if (!function_exists('down_file')) {
* @param integer $expire 强制本地存储时间 * @param integer $expire 强制本地存储时间
* @return string * @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); $result = Storage::down($source, $force, $expire);
return isset($result['url']) ? $result['url'] : $source; return isset($result['url']) ? $result['url'] : $source;

View File

@ -24,11 +24,11 @@ class CodeExtend
{ {
/** /**
* 获取随机字符串编码 * 获取随机字符串编码
* @param integer $length 字符串长度 * @param integer $size 字符串长度
* @param integer $type 字符串类型(1纯数字,2纯字母,3数字字母) * @param integer $type 字符串类型(1纯数字,2纯字母,3数字字母)
* @return string * @return string
*/ */
public static function random($length = 10, $type = 1) public static function random($size = 10, $type = 1)
{ {
$numbs = '0123456789'; $numbs = '0123456789';
$chars = 'abcdefghijklmnopqrstuvwxyz'; $chars = 'abcdefghijklmnopqrstuvwxyz';
@ -36,7 +36,7 @@ class CodeExtend
if (intval($type) === 2) $chars = "a{$chars}"; if (intval($type) === 2) $chars = "a{$chars}";
if (intval($type) === 3) $chars = "{$numbs}{$chars}"; if (intval($type) === 3) $chars = "{$numbs}{$chars}";
$string = $chars[rand(1, strlen($chars) - 1)]; $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)]; $string .= $chars[rand(0, strlen($chars) - 1)];
} }
return $string; return $string;
@ -44,28 +44,28 @@ class CodeExtend
/** /**
* 唯一日期编码 * 唯一日期编码
* @param integer $length * @param integer $size
* @return string * @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'); $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; return $string;
} }
/** /**
* 唯一数字编码 * 唯一数字编码
* @param integer $length * @param integer $size
* @return string * @return string
*/ */
public static function uniqidNumber($length = 12) public static function uniqidNumber($size = 12)
{ {
$time = time() . ''; $time = time() . '';
if ($length < 10) $length = 10; if ($size < 10) $size = 10;
$string = ($time[0] + $time[1]) . substr($time, 2) . rand(0, 9); $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; return $string;
} }
} }

View File

@ -23,7 +23,7 @@ namespace think\admin\extend;
class HttpExtend class HttpExtend
{ {
/** /**
* get模拟网络请求 * GET模拟网络请求
* @param string $location HTTP请求地址 * @param string $location HTTP请求地址
* @param array|string $query GET请求参数 * @param array|string $query GET请求参数
* @param array $options CURL请求参数 * @param array $options CURL请求参数
@ -36,7 +36,7 @@ class HttpExtend
} }
/** /**
* post模拟网络请求 * POST 模拟网络请求
* @param string $location HTTP请求地址 * @param string $location HTTP请求地址
* @param array|string $data POST请求数据 * @param array|string $data POST请求数据
* @param array $options CURL请求参数 * @param array $options CURL请求参数
@ -48,6 +48,23 @@ class HttpExtend
return self::request('post', $location, $options); 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模拟网络请求 * CURL模拟网络请求
* @param string $method 请求方法 * @param string $method 请求方法
@ -107,7 +124,7 @@ class HttpExtend
} }
/** /**
* POST数据过滤处理 * POST 数据过滤处理
* @param array $data 需要处理的数据 * @param array $data 需要处理的数据
* @param boolean $build 是否编译数据 * @param boolean $build 是否编译数据
* @return array|string * @return array|string
@ -115,16 +132,40 @@ class HttpExtend
private static function buildQueryData($data, $build = true) private static function buildQueryData($data, $build = true)
{ {
if (!is_array($data)) return $data; if (!is_array($data)) return $data;
foreach ($data as $key => $value) if (is_object($value) && $value instanceof \CURLFile) { foreach ($data as $key => $value) {
$build = false; if (is_string($value) && stripos($value, '@') === 0 && class_exists('CURLFile')) {
} elseif (is_string($value) && class_exists('CURLFile', false) && stripos($value, '@') === 0) { if (file_exists($filename = realpath(ltrim($value, '@')))) {
if (($filename = realpath(trim($value, '@'))) && file_exists($filename)) { list($build, $data[$key]) = [false, new \CURLFile($filename)];
list($build, $data[$key]) = [false, new \CURLFile($filename)]; }
} } elseif ($value instanceof \CURLFile) $build = false;
} }
return $build ? http_build_query($data) : $data; 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)];
}
/** /**
* 获取浏览器代理信息 * 获取浏览器代理信息

View File

@ -56,6 +56,7 @@ class AliossStorage extends Storage
private $secretKey; private $secretKey;
/** /**
* 初始化入口
* @return $this * @return $this
* @throws \think\Exception * @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
@ -103,22 +104,13 @@ class AliossStorage extends Storage
public function set($name, $file, $safe = false) public function set($name, $file, $safe = false)
{ {
$token = $this->buildUploadToken($name); $token = $this->buildUploadToken($name);
list($attrs, $frontier) = [[], uniqid()]; $data = ['key' => $name];
foreach (['key' => $name, 'policy' => $token['policy'], 'success_action_status' => '200', 'OSSAccessKeyId' => $this->accessKey, 'Signature' => $token['signature']] as $key => $value) { $data['policy'] = $token['policy'];
$attrs[] = "--{$frontier}"; $data['Signature'] = $token['signature'];
$attrs[] = "Content-Disposition: form-data; name=\"{$key}\""; $data['OSSAccessKeyId'] = $this->accessKey;
$attrs[] = ""; $data['success_action_status'] = '200';
$attrs[] = $value; $file = ['field' => 'file', 'name' => $name, 'content' => $file];
} if (is_numeric(stripos(HttpExtend::submit($this->upload(), $data, $file), '200 OK'))) {
$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'))) {
return ['file' => $this->path($name, $safe), 'url' => $this->url($name, $safe), 'key' => $name]; return ['file' => $this->path($name, $safe), 'url' => $this->url($name, $safe), 'key' => $name];
} else { } else {
return []; return [];

View File

@ -25,7 +25,7 @@ use think\admin\Storage;
class LocalStorage extends Storage class LocalStorage extends Storage
{ {
/** /**
* 存储引擎初始化 * 初始化入口
* @return LocalStorage * @return LocalStorage
*/ */
protected function initialize(): Storage protected function initialize(): Storage

View File

@ -31,7 +31,7 @@ class QiniuStorage extends Storage
private $secretKey; private $secretKey;
/** /**
* 存储引擎初始化 * 初始化入口
* @return $this * @return $this
* @throws \think\Exception * @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
@ -82,21 +82,10 @@ class QiniuStorage extends Storage
public function set($name, $file, $safe = false) public function set($name, $file, $safe = false)
{ {
$token = $this->buildUploadToken($name); $token = $this->buildUploadToken($name);
list($attrs, $frontier) = [[], uniqid()]; $data = ['key' => $name, 'token' => $token, 'fileName' => $name];
foreach (['key' => $name, 'token' => $token, 'fileName' => $name] as $key => $value) { $file = ['field' => "file", 'name' => $name, 'content' => $file];
$attrs[] = "--{$frontier}"; $result = HttpExtend::submit($this->upload(), $data, $file, [], 'POST', false);
$attrs[] = "Content-Disposition:form-data; name=\"{$key}\""; return json_decode($result, true);
$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);
} }
@ -171,7 +160,7 @@ class QiniuStorage extends Storage
{ {
list($entry, $token) = $this->getAccessToken($name); list($entry, $token) = $this->getAccessToken($name);
$data = json_decode(HttpExtend::get("http://rs.qiniu.com/stat/{$entry}", [], ['headers' => ["Authorization: QBox {$token}"]]), true); $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([ $policy = $this->safeBase64(json_encode([
"deadline" => time() + $expires, "scope" => is_null($name) ? $this->bucket : "{$this->bucket}:{$name}", "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}"; return "{$this->accessKey}:{$this->safeBase64(hash_hmac('sha1', $policy, $this->secretKey, true))}:{$policy}";
} }