From a78f9800d2498ad39cbe0a5ae26af98ed3b2b495 Mon Sep 17 00:00:00 2001 From: wisp-x <1591788658@qq.com> Date: Fri, 9 Aug 2019 15:41:52 +0800 Subject: [PATCH] :bug: Fixing a bug. --- composer.lock | 20 +- thinkphp/library/think/App.php | 2 +- thinkphp/library/think/Controller.php | 4 +- thinkphp/library/think/Request.php | 20 +- thinkphp/library/think/Url.php | 4 +- thinkphp/library/think/db/Builder.php | 18 +- thinkphp/library/think/db/Connection.php | 6 +- thinkphp/library/think/db/Query.php | 16 +- thinkphp/library/think/db/builder/Mysql.php | 2 +- thinkphp/library/think/db/connector/Mysql.php | 22 +- .../think/exception/ValidateException.php | 2 +- thinkphp/library/think/log/driver/File.php | 14 +- .../think/model/concern/Conversion.php | 12 +- .../think/model/relation/BelongsTo.php | 12 +- .../library/think/model/relation/HasMany.php | 16 +- .../think/model/relation/HasManyThrough.php | 266 ++++++++++++-- .../library/think/model/relation/HasOne.php | 12 +- thinkphp/library/think/response/View.php | 27 +- thinkphp/library/think/route/Dispatch.php | 9 +- .../library/think/route/dispatch/Module.php | 1 - vendor/aliyuncs/oss-sdk-php/build-phar.sh | 0 vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 14 +- vendor/composer/autoload_static.php | 8 +- vendor/composer/installed.json | 24 +- .../Guzzle/Tests/Http/RedirectPluginTest.php | 0 vendor/qcloud/cos-sdk-v5/.travis.yml | 2 +- .../cos-sdk-v5/sample/putBucketCors.php | 26 +- .../src/Qcloud/Cos/BucketStyleListener.php | 4 +- .../cos-sdk-v5/src/Qcloud/Cos/Client.php | 6 +- .../src/Qcloud/Cos/ExceptionParser.php | 5 +- .../cos-sdk-v5/src/Qcloud/Cos/Signature.php | 3 +- .../cos-sdk-v5/src/Qcloud/Cos/Tests/Test.php | 1 + vendor/qiniu/php-sdk/docs/sms/example.php | 70 ++++ .../php-sdk/examples/bucket_lifecycleRule.php | 30 ++ .../qiniu/php-sdk/examples/delete_bucket.php | 20 ++ .../php-sdk/examples/delete_bucketEvent.php | 21 ++ .../examples/delete_bucketLifecycleRule.php | 21 ++ .../php-sdk/examples/get_bucketEvents.php | 20 ++ .../examples/get_bucketLifecycleRules.php | 20 ++ .../qiniu/php-sdk/examples/get_bucketList.php | 20 ++ .../php-sdk/examples/get_bucketQuota.php | 20 ++ .../qiniu/php-sdk/examples/get_bucketinfo.php | 20 ++ .../php-sdk/examples/get_bucketinfos.php | 20 ++ .../qiniu/php-sdk/examples/get_corsRules.php | 20 ++ .../php-sdk/examples/put_bucketAccessMode.php | 21 ++ .../examples/put_bucketAccessStyleMode.php | 21 ++ .../php-sdk/examples/put_bucketEvent.php | 25 ++ .../php-sdk/examples/put_bucketMaxAge.php | 21 ++ .../php-sdk/examples/put_bucketQuota.php | 22 ++ .../php-sdk/examples/put_referAntiLeech.php | 23 ++ .../qiniu/php-sdk/examples/rs_pub_domain.php | 19 + .../php-sdk/examples/rsf_v2list_bucket.php | 33 ++ .../php-sdk/examples/update_bucketEvent.php | 25 ++ .../examples/update_bucketLifecycleRule.php | 30 ++ vendor/qiniu/php-sdk/src/Qiniu/Region.php | 196 ++++++++++ vendor/qiniu/php-sdk/src/Qiniu/Sms/Sms.php | 337 ++++++++++++++++++ 57 files changed, 1510 insertions(+), 145 deletions(-) mode change 100644 => 100755 vendor/aliyuncs/oss-sdk-php/build-phar.sh mode change 100644 => 100755 vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/RedirectPluginTest.php create mode 100644 vendor/qiniu/php-sdk/docs/sms/example.php create mode 100644 vendor/qiniu/php-sdk/examples/bucket_lifecycleRule.php create mode 100644 vendor/qiniu/php-sdk/examples/delete_bucket.php create mode 100644 vendor/qiniu/php-sdk/examples/delete_bucketEvent.php create mode 100644 vendor/qiniu/php-sdk/examples/delete_bucketLifecycleRule.php create mode 100644 vendor/qiniu/php-sdk/examples/get_bucketEvents.php create mode 100644 vendor/qiniu/php-sdk/examples/get_bucketLifecycleRules.php create mode 100644 vendor/qiniu/php-sdk/examples/get_bucketList.php create mode 100644 vendor/qiniu/php-sdk/examples/get_bucketQuota.php create mode 100644 vendor/qiniu/php-sdk/examples/get_bucketinfo.php create mode 100644 vendor/qiniu/php-sdk/examples/get_bucketinfos.php create mode 100644 vendor/qiniu/php-sdk/examples/get_corsRules.php create mode 100644 vendor/qiniu/php-sdk/examples/put_bucketAccessMode.php create mode 100644 vendor/qiniu/php-sdk/examples/put_bucketAccessStyleMode.php create mode 100644 vendor/qiniu/php-sdk/examples/put_bucketEvent.php create mode 100644 vendor/qiniu/php-sdk/examples/put_bucketMaxAge.php create mode 100644 vendor/qiniu/php-sdk/examples/put_bucketQuota.php create mode 100644 vendor/qiniu/php-sdk/examples/put_referAntiLeech.php create mode 100644 vendor/qiniu/php-sdk/examples/rs_pub_domain.php create mode 100644 vendor/qiniu/php-sdk/examples/rsf_v2list_bucket.php create mode 100644 vendor/qiniu/php-sdk/examples/update_bucketEvent.php create mode 100644 vendor/qiniu/php-sdk/examples/update_bucketLifecycleRule.php create mode 100644 vendor/qiniu/php-sdk/src/Qiniu/Region.php create mode 100644 vendor/qiniu/php-sdk/src/Qiniu/Sms/Sms.php diff --git a/composer.lock b/composer.lock index bcce1824..c4b44ddf 100644 --- a/composer.lock +++ b/composer.lock @@ -490,16 +490,16 @@ }, { "name": "qcloud/cos-sdk-v5", - "version": "v1.3.2", + "version": "v1.3.3", "source": { "type": "git", "url": "https://github.com/tencentyun/cos-php-sdk-v5.git", - "reference": "0454f48629210749ae6316ab317548169dac9d8f" + "reference": "cd1b9cefa04521eaf125a82eb53552d9a87aae4d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/tencentyun/cos-php-sdk-v5/zipball/0454f48629210749ae6316ab317548169dac9d8f", - "reference": "0454f48629210749ae6316ab317548169dac9d8f", + "url": "https://api.github.com/repos/tencentyun/cos-php-sdk-v5/zipball/cd1b9cefa04521eaf125a82eb53552d9a87aae4d", + "reference": "cd1b9cefa04521eaf125a82eb53552d9a87aae4d", "shasum": "", "mirrors": [ { @@ -538,7 +538,7 @@ "php", "qcloud" ], - "time": "2019-04-25T12:23:41+00:00" + "time": "2019-08-07T10:15:47+00:00" }, { "name": "qiniu/php-sdk", @@ -711,16 +711,16 @@ }, { "name": "topthink/framework", - "version": "v5.1.37.1", + "version": "v5.1.38", "source": { "type": "git", "url": "https://github.com/top-think/framework.git", - "reference": "05eecd121d18d6705aaa10aa44fcdf7c14da4d0b" + "reference": "b538d2615794bfd05455b6f8232a359d09f5a8df" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/top-think/framework/zipball/05eecd121d18d6705aaa10aa44fcdf7c14da4d0b", - "reference": "05eecd121d18d6705aaa10aa44fcdf7c14da4d0b", + "url": "https://api.github.com/repos/top-think/framework/zipball/b538d2615794bfd05455b6f8232a359d09f5a8df", + "reference": "b538d2615794bfd05455b6f8232a359d09f5a8df", "shasum": "", "mirrors": [ { @@ -764,7 +764,7 @@ "orm", "thinkphp" ], - "time": "2019-05-28T06:57:29+00:00" + "time": "2019-08-09T07:12:36+00:00" }, { "name": "topthink/think-captcha", diff --git a/thinkphp/library/think/App.php b/thinkphp/library/think/App.php index 1fb9fbda..7766555e 100644 --- a/thinkphp/library/think/App.php +++ b/thinkphp/library/think/App.php @@ -20,7 +20,7 @@ use think\route\Dispatch; */ class App extends Container { - const VERSION = '5.1.37 LTS'; + const VERSION = '5.1.38 LTS'; /** * 当前模块路径 diff --git a/thinkphp/library/think/Controller.php b/thinkphp/library/think/Controller.php index d16a1ed5..966eaaa8 100644 --- a/thinkphp/library/think/Controller.php +++ b/thinkphp/library/think/Controller.php @@ -158,7 +158,7 @@ class Controller */ protected function fetch($template = '', $vars = [], $config = []) { - return $this->view->fetch($template, $vars, $config); + return Response::create($template, 'view')->assign($vars)->config($config); } /** @@ -171,7 +171,7 @@ class Controller */ protected function display($content = '', $vars = [], $config = []) { - return $this->view->display($content, $vars, $config); + return Response::create($content, 'view')->assign($vars)->config($config)->isContent(true); } /** diff --git a/thinkphp/library/think/Request.php b/thinkphp/library/think/Request.php index f6529d03..e0488e77 100644 --- a/thinkphp/library/think/Request.php +++ b/thinkphp/library/think/Request.php @@ -682,6 +682,7 @@ class Request // 判断URL里面是否有兼容模式参数 $pathinfo = $_GET[$this->config['var_pathinfo']]; unset($_GET[$this->config['var_pathinfo']]); + unset($this->get[$this->config['var_pathinfo']]); } elseif ($this->isCli()) { // CLI模式下 index.php module/controller/action/params/... $pathinfo = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : ''; @@ -702,6 +703,10 @@ class Request } } + if (!empty($pathinfo)) { + unset($this->get[$pathinfo], $this->request[$pathinfo]); + } + $this->pathinfo = empty($pathinfo) || '/' == $pathinfo ? '' : ltrim($pathinfo, '/'); } @@ -1039,7 +1044,7 @@ class Request protected function getInputData($content) { - if (false !== strpos($this->contentType(), 'application/json') || 0 === strpos($content, '{"')) { + if ($this->isJson()) { return (array) json_decode($content, true); } elseif (strpos($content, '=')) { parse_str($content, $data); @@ -1631,6 +1636,19 @@ class Request return false; } + /** + * 当前是否JSON请求 + * @access public + * @return bool + */ + public function isJson() + { + $contentType = $this->contentType(); + $acceptType = $this->type(); + + return false !== strpos($contentType, 'json') || false !== strpos($acceptType, 'json'); + } + /** * 当前是否Ajax请求 * @access public diff --git a/thinkphp/library/think/Url.php b/thinkphp/library/think/Url.php index a339f8de..cccabc22 100644 --- a/thinkphp/library/think/Url.php +++ b/thinkphp/library/think/Url.php @@ -130,7 +130,9 @@ class Url // 匹配路由命名标识 $url = $match[0]; - $domain = $match[1]; + if ($domain) { + $domain = $match[1]; + } if (!is_null($match[2])) { $suffix = $match[2]; diff --git a/thinkphp/library/think/db/Builder.php b/thinkphp/library/think/db/Builder.php index b742506a..09df1a07 100644 --- a/thinkphp/library/think/db/Builder.php +++ b/thinkphp/library/think/db/Builder.php @@ -407,7 +407,7 @@ abstract class Builder $jsonType = $query->getJsonFieldType($field); $bindType = $this->connection->getFieldBindType($jsonType); } else { - $bindType = isset($binds[$field]) ? $binds[$field] : PDO::PARAM_STR; + $bindType = isset($binds[$field]) && 'LIKE' != $exp ? $binds[$field] : PDO::PARAM_STR; } if (is_scalar($value) && !in_array($exp, ['EXP', 'NOT NULL', 'NULL', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN']) && strpos($exp, 'TIME') === false) { @@ -450,7 +450,7 @@ abstract class Builder // 模糊匹配 if (is_array($value)) { foreach ($value as $item) { - $name = $query->bind($item, $bindType); + $name = $query->bind($item, PDO::PARAM_STR); $array[] = $key . ' ' . $exp . ' :' . $name; } @@ -604,6 +604,10 @@ abstract class Builder $value = $this->parseClosure($query, $value); } + if ('=' == $exp && is_null($value)) { + return $key . ' IS NULL'; + } + return $key . ' ' . $exp . ' ' . $value; } @@ -651,7 +655,6 @@ abstract class Builder $value = $value->getValue(); } else { $value = array_unique(is_array($value) ? $value : explode(',', $value)); - $array = []; foreach ($value as $k => $v) { @@ -659,9 +662,12 @@ abstract class Builder $array[] = ':' . $name; } - $zone = implode(',', $array); - - $value = empty($zone) ? "''" : $zone; + if (count($array) == 1) { + return $key . ('IN' == $exp ? ' = ' : ' <> ') . $array[0]; + } else { + $zone = implode(',', $array); + $value = empty($zone) ? "''" : $zone; + } } return $key . ' ' . $exp . ' (' . $value . ')'; diff --git a/thinkphp/library/think/db/Connection.php b/thinkphp/library/think/db/Connection.php index d6b3c7ed..18b4885a 100644 --- a/thinkphp/library/think/db/Connection.php +++ b/thinkphp/library/think/db/Connection.php @@ -1467,9 +1467,7 @@ abstract class Connection $value = is_array($val) ? $val[0] : $val; $type = is_array($val) ? $val[1] : PDO::PARAM_STR; - if (self::PARAM_FLOAT == $type) { - $value = (float) $value; - } elseif (PDO::PARAM_STR == $type) { + if ((self::PARAM_FLOAT == $type || PDO::PARAM_STR == $type) && is_string($value)) { $value = '\'' . addslashes($value) . '\''; } elseif (PDO::PARAM_INT == $type && '' === $value) { $value = 0; @@ -1503,7 +1501,7 @@ abstract class Connection if (PDO::PARAM_INT == $val[1] && '' === $val[0]) { $val[0] = 0; } elseif (self::PARAM_FLOAT == $val[1]) { - $val[0] = (float) $val[0]; + $val[0] = is_string($val[0]) ? (float) $val[0] : $val[0]; $val[1] = PDO::PARAM_STR; } diff --git a/thinkphp/library/think/db/Query.php b/thinkphp/library/think/db/Query.php index 5b1785e4..4d632909 100644 --- a/thinkphp/library/think/db/Query.php +++ b/thinkphp/library/think/db/Query.php @@ -95,14 +95,14 @@ class Query * @var array */ protected $timeRule = [ - 'today' => ['today', 'tomorrow'], - 'yesterday' => ['yesterday', 'today'], - 'week' => ['this week 00:00:00', 'next week 00:00:00'], - 'last week' => ['last week 00:00:00', 'this week 00:00:00'], - 'month' => ['first Day of this month 00:00:00', 'first Day of next month 00:00:00'], - 'last month' => ['first Day of last month 00:00:00', 'first Day of this month 00:00:00'], - 'year' => ['this year 1/1', 'next year 1/1'], - 'last year' => ['last year 1/1', 'this year 1/1'], + 'today' => ['today', 'tomorrow -1second'], + 'yesterday' => ['yesterday', 'today -1second'], + 'week' => ['this week 00:00:00', 'next week 00:00:00 -1second'], + 'last week' => ['last week 00:00:00', 'this week 00:00:00 -1second'], + 'month' => ['first Day of this month 00:00:00', 'first Day of next month 00:00:00 -1second'], + 'last month' => ['first Day of last month 00:00:00', 'first Day of this month 00:00:00 -1second'], + 'year' => ['this year 1/1', 'next year 1/1 -1second'], + 'last year' => ['last year 1/1', 'this year 1/1 -1second'], ]; /** diff --git a/thinkphp/library/think/db/builder/Mysql.php b/thinkphp/library/think/db/builder/Mysql.php index 22f33900..c715aa34 100644 --- a/thinkphp/library/think/db/builder/Mysql.php +++ b/thinkphp/library/think/db/builder/Mysql.php @@ -129,7 +129,7 @@ class Mysql extends Builder // JSON字段支持 list($field, $name) = explode('->', $key, 2); - return 'json_extract(' . $this->parseKey($query, $field, true) . ', \'$.' . str_replace('->', '.', $name) . '\')'; + return 'json_extract(' . $this->parseKey($query, $field, true) . ', \'$' . (strpos($name, '[') === 0 ? '' : '.') . str_replace('->', '.', $name) . '\')'; } elseif (strpos($key, '.') && !preg_match('/[,\'\"\(\)`\s]/', $key)) { list($table, $key) = explode('.', $key, 2); diff --git a/thinkphp/library/think/db/connector/Mysql.php b/thinkphp/library/think/db/connector/Mysql.php index 93b8a182..1713b99b 100644 --- a/thinkphp/library/think/db/connector/Mysql.php +++ b/thinkphp/library/think/db/connector/Mysql.php @@ -136,7 +136,27 @@ class Mysql extends Connection */ protected function getExplain($sql) { - $pdo = $this->linkID->query("EXPLAIN " . $sql); + $pdo = $this->linkID->prepare("EXPLAIN " . $this->queryStr); + + foreach ($this->bind as $key => $val) { + // 占位符 + $param = is_int($key) ? $key + 1 : ':' . $key; + + if (is_array($val)) { + if (PDO::PARAM_INT == $val[1] && '' === $val[0]) { + $val[0] = 0; + } elseif (self::PARAM_FLOAT == $val[1]) { + $val[0] = is_string($val[0]) ? (float) $val[0] : $val[0]; + $val[1] = PDO::PARAM_STR; + } + + $result = $pdo->bindValue($param, $val[0], $val[1]); + } else { + $result = $pdo->bindValue($param, $val); + } + } + + $pdo->execute(); $result = $pdo->fetch(PDO::FETCH_ASSOC); $result = array_change_key_case($result); diff --git a/thinkphp/library/think/exception/ValidateException.php b/thinkphp/library/think/exception/ValidateException.php index e3f84374..81ddfe21 100644 --- a/thinkphp/library/think/exception/ValidateException.php +++ b/thinkphp/library/think/exception/ValidateException.php @@ -18,7 +18,7 @@ class ValidateException extends \RuntimeException public function __construct($error, $code = 0) { $this->error = $error; - $this->message = is_array($error) ? implode("\n\r", $error) : $error; + $this->message = is_array($error) ? implode(PHP_EOL, $error) : $error; $this->code = $code; } diff --git a/thinkphp/library/think/log/driver/File.php b/thinkphp/library/think/log/driver/File.php index c506105f..3f6522d1 100644 --- a/thinkphp/library/think/log/driver/File.php +++ b/thinkphp/library/think/log/driver/File.php @@ -107,7 +107,7 @@ class File $info['timestamp'] = date($this->config['time_format']); foreach ($message as $type => $msg) { - $msg = is_array($msg) ? implode("\r\n", $msg) : $msg; + $msg = is_array($msg) ? implode(PHP_EOL, $msg) : $msg; if (PHP_SAPI == 'cli') { $info['msg'] = $msg; $info['type'] = $type; @@ -212,14 +212,14 @@ class File protected function parseCliLog($info) { if ($this->config['json']) { - $message = json_encode($info, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . "\r\n"; + $message = json_encode($info, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL; } else { $now = $info['timestamp']; unset($info['timestamp']); - $message = implode("\r\n", $info); + $message = implode(PHP_EOL, $info); - $message = "[{$now}]" . $message . "\r\n"; + $message = "[{$now}]" . $message . PHP_EOL; } return $message; @@ -242,13 +242,13 @@ class File if ($this->config['json']) { $info = $requestInfo + $info; - return json_encode($info, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . "\r\n"; + return json_encode($info, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL; } - array_unshift($info, "---------------------------------------------------------------\r\n[{$info['timestamp']}] {$requestInfo['ip']} {$requestInfo['method']} {$requestInfo['host']}{$requestInfo['uri']}"); + array_unshift($info, "---------------------------------------------------------------" . PHP_EOL . "\r\n[{$info['timestamp']}] {$requestInfo['ip']} {$requestInfo['method']} {$requestInfo['host']}{$requestInfo['uri']}"); unset($info['timestamp']); - return implode("\r\n", $info) . "\r\n"; + return implode(PHP_EOL, $info) . PHP_EOL; } protected function getDebugLog(&$info, $append, $apart) diff --git a/thinkphp/library/think/model/concern/Conversion.php b/thinkphp/library/think/model/concern/Conversion.php index 922d5b0e..28a6f999 100644 --- a/thinkphp/library/think/model/concern/Conversion.php +++ b/thinkphp/library/think/model/concern/Conversion.php @@ -189,10 +189,12 @@ trait Conversion if (!$relation) { $relation = $this->getAttr($key); - $relation->visible($name); + if ($relation) { + $relation->visible($name); + } } - $item[$key] = $relation->append($name)->toArray(); + $item[$key] = $relation ? $relation->append($name)->toArray() : []; } elseif (strpos($name, '.')) { list($key, $attr) = explode('.', $name); // 追加关联对象属性 @@ -200,10 +202,12 @@ trait Conversion if (!$relation) { $relation = $this->getAttr($key); - $relation->visible([$attr]); + if ($relation) { + $relation->visible([$attr]); + } } - $item[$key] = $relation->append([$attr])->toArray(); + $item[$key] = $relation ? $relation->append([$attr])->toArray() : []; } else { $item[$name] = $this->getAttr($name, $item); } diff --git a/thinkphp/library/think/model/relation/BelongsTo.php b/thinkphp/library/think/model/relation/BelongsTo.php index 98d176e8..1dea3b3b 100644 --- a/thinkphp/library/think/model/relation/BelongsTo.php +++ b/thinkphp/library/think/model/relation/BelongsTo.php @@ -140,13 +140,17 @@ class BelongsTo extends OneToOne $relation = basename(str_replace('\\', '/', $this->model)); $localKey = $this->localKey; $foreignKey = $this->foreignKey; + $softDelete = $this->query->getOptions('soft_delete'); return $this->parent->db() ->alias($model) ->whereExists(function ($query) use ($table, $model, $relation, $localKey, $foreignKey) { $query->table([$table => $relation]) ->field($relation . '.' . $localKey) - ->whereExp($model . '.' . $foreignKey, '=' . $relation . '.' . $localKey); + ->whereExp($model . '.' . $foreignKey, '=' . $relation . '.' . $localKey) + ->when($softDelete, function ($query) use ($softDelete, $relation) { + $query->where($relation . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null); + }); }); } @@ -167,12 +171,16 @@ class BelongsTo extends OneToOne $this->getQueryWhere($where, $relation); } - $fields = $this->getRelationQueryFields($fields, $model); + $fields = $this->getRelationQueryFields($fields, $model); + $softDelete = $this->query->getOptions('soft_delete'); return $this->parent->db() ->alias($model) ->field($fields) ->join([$table => $relation], $model . '.' . $this->foreignKey . '=' . $relation . '.' . $this->localKey, $this->joinType) + ->when($softDelete, function ($query) use ($softDelete, $relation) { + $query->where($relation . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null); + }) ->where($where); } diff --git a/thinkphp/library/think/model/relation/HasMany.php b/thinkphp/library/think/model/relation/HasMany.php index f97623b8..728ca181 100644 --- a/thinkphp/library/think/model/relation/HasMany.php +++ b/thinkphp/library/think/model/relation/HasMany.php @@ -292,14 +292,18 @@ class HasMany extends Relation */ public function has($operator = '>=', $count = 1, $id = '*', $joinType = 'INNER') { - $table = $this->query->getTable(); - $model = basename(str_replace('\\', '/', get_class($this->parent))); - $relation = basename(str_replace('\\', '/', $this->model)); + $table = $this->query->getTable(); + $model = basename(str_replace('\\', '/', get_class($this->parent))); + $relation = basename(str_replace('\\', '/', $this->model)); + $softDelete = $this->query->getOptions('soft_delete'); return $this->parent->db() ->alias($model) ->field($model . '.*') ->join([$table => $relation], $model . '.' . $this->localKey . '=' . $relation . '.' . $this->foreignKey, $joinType) + ->when($softDelete, function ($query) use ($softDelete, $relation) { + $query->where($relation . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null); + }) ->group($relation . '.' . $this->foreignKey) ->having('count(' . $id . ')' . $operator . $count); } @@ -321,13 +325,17 @@ class HasMany extends Relation $this->getQueryWhere($where, $relation); } - $fields = $this->getRelationQueryFields($fields, $model); + $fields = $this->getRelationQueryFields($fields, $model); + $softDelete = $this->query->getOptions('soft_delete'); return $this->parent->db() ->alias($model) ->group($model . '.' . $this->localKey) ->field($fields) ->join([$table => $relation], $model . '.' . $this->localKey . '=' . $relation . '.' . $this->foreignKey) + ->when($softDelete, function ($query) use ($softDelete, $relation) { + $query->where($relation . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null); + }) ->where($where); } diff --git a/thinkphp/library/think/model/relation/HasManyThrough.php b/thinkphp/library/think/model/relation/HasManyThrough.php index 7c7acaa0..c048eb91 100644 --- a/thinkphp/library/think/model/relation/HasManyThrough.php +++ b/thinkphp/library/think/model/relation/HasManyThrough.php @@ -12,7 +12,6 @@ namespace think\model\relation; use think\db\Query; -use think\Exception; use think\Loader; use think\Model; use think\model\Relation; @@ -24,6 +23,12 @@ class HasManyThrough extends Relation // 中间表模型 protected $through; + /** + * 中间主键 + * @var string + */ + protected $throughPk; + /** * 架构函数 * @access public @@ -38,9 +43,10 @@ class HasManyThrough extends Relation { $this->parent = $parent; $this->model = $model; - $this->through = $through; + $this->through = (new $through)->db(); $this->foreignKey = $foreignKey; $this->throughKey = $throughKey; + $this->throughPk = $this->through->getPk(); $this->localKey = $localKey; $this->query = (new $model)->db(); } @@ -74,7 +80,28 @@ class HasManyThrough extends Relation */ public function has($operator = '>=', $count = 1, $id = '*', $joinType = 'INNER') { - return $this->parent; + $model = App::parseName(App::classBaseName($this->parent)); + $throughTable = $this->through->getTable(); + $pk = $this->throughPk; + $throughKey = $this->throughKey; + $relation = (new $this->model)->db(); + $relationTable = $relation->getTable(); + $softDelete = $this->query->getOptions('soft_delete'); + + if ('*' != $id) { + $id = $relationTable . '.' . $relation->getPk(); + } + + return $this->parent->db() + ->alias($model) + ->field($model . '.*') + ->join($throughTable, $throughTable . '.' . $this->foreignKey . '=' . $model . '.' . $this->localKey) + ->join($relationTable, $relationTable . '.' . $throughKey . '=' . $throughTable . '.' . $this->throughPk) + ->when($softDelete, function ($query) use ($softDelete, $relationTable) { + $query->where($relationTable . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null); + }) + ->group($relationTable . '.' . $this->throughKey) + ->having('count(' . $id . ')' . $operator . $count); } /** @@ -86,45 +113,225 @@ class HasManyThrough extends Relation */ public function hasWhere($where = [], $fields = null) { - throw new Exception('relation not support: hasWhere'); + $model = App::parseName(App::classBaseName($this->parent)); + $throughTable = $this->through->getTable(); + $pk = $this->throughPk; + $throughKey = $this->throughKey; + $modelTable = (new $this->model)->db()->getTable(); + + if (is_array($where)) { + $this->getQueryWhere($where, $modelTable); + } + + $fields = $this->getRelationQueryFields($fields, $model); + $softDelete = $this->query->getOptions('soft_delete'); + + return $this->parent->db() + ->alias($model) + ->join($throughTable, $throughTable . '.' . $this->foreignKey . '=' . $model . '.' . $this->localKey) + ->join($modelTable, $modelTable . '.' . $throughKey . '=' . $throughTable . '.' . $this->throughPk) + ->when($softDelete, function ($query) use ($softDelete, $modelTable) { + $query->where($modelTable . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null); + }) + ->group($modelTable . '.' . $this->throughKey) + ->where($where) + ->field($fields); } /** - * 预载入关联查询 - * @access public - * @param array $resultSet 数据集 - * @param string $relation 当前关联名 - * @param string $subRelation 子关联名 - * @param \Closure $closure 闭包 + * 预载入关联查询(数据集) + * @access protected + * @param array $resultSet 数据集 + * @param string $relation 当前关联名 + * @param array $subRelation 子关联名 + * @param Closure $closure 闭包 * @return void */ - public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure) - {} + public function eagerlyResultSet(array &$resultSet, $relation, array $subRelation = [], $closure = null) + { + $localKey = $this->localKey; + $foreignKey = $this->foreignKey; + + $range = []; + foreach ($resultSet as $result) { + // 获取关联外键列表 + if (isset($result->$localKey)) { + $range[] = $result->$localKey; + } + } + + if (!empty($range)) { + $this->query->removeWhereField($foreignKey); + + $data = $this->eagerlyWhere([ + [$this->foreignKey, 'in', $range], + ], $foreignKey, $relation, $subRelation, $closure); + + // 关联属性名 + $attr = App::parseName($relation); + + // 关联数据封装 + foreach ($resultSet as $result) { + $pk = $result->$localKey; + if (!isset($data[$pk])) { + $data[$pk] = []; + } + + foreach ($data[$pk] as &$relationModel) { + $relationModel->setParent(clone $result); + } + + // 设置关联属性 + $result->setRelation($attr, $this->resultSetBuild($data[$pk])); + } + } + } /** - * 预载入关联查询 返回模型对象 - * @access public - * @param Model $result 数据对象 - * @param string $relation 当前关联名 - * @param string $subRelation 子关联名 - * @param \Closure $closure 闭包 + * 预载入关联查询(数据) + * @access protected + * @param Model $result 数据对象 + * @param string $relation 当前关联名 + * @param array $subRelation 子关联名 + * @param Closure $closure 闭包 * @return void */ - public function eagerlyResult(&$result, $relation, $subRelation, $closure) - {} + public function eagerlyResult($result, $relation, array $subRelation = [], $closure = null) + { + $localKey = $this->localKey; + $foreignKey = $this->foreignKey; + $pk = $result->$localKey; + + $this->query->removeWhereField($foreignKey); + + $data = $this->eagerlyWhere([ + [$foreignKey, '=', $pk], + ], $foreignKey, $relation, $subRelation, $closure); + + // 关联数据封装 + if (!isset($data[$pk])) { + $data[$pk] = []; + } + + foreach ($data[$pk] as &$relationModel) { + $relationModel->setParent(clone $result); + } + + $result->setRelation(App::parseName($relation), $this->resultSetBuild($data[$pk])); + } + + /** + * 关联模型预查询 + * @access public + * @param array $where 关联预查询条件 + * @param string $key 关联键名 + * @param string $relation 关联名 + * @param array $subRelation 子关联 + * @param Closure $closure + * @return array + */ + protected function eagerlyWhere(array $where, $key, $relation, array $subRelation = [], $closure = null) + { + // 预载入关联查询 支持嵌套预载入 + $throughList = $this->through->where($where)->select(); + $keys = $throughList->column($this->throughPk, $this->throughPk); + + if ($closure) { + $closure($this->query); + } + + $list = $this->query->where($this->throughKey, 'in', $keys)->select(); + + // 组装模型数据 + $data = []; + $keys = $throughList->column($this->foreignKey, $this->throughPk); + + foreach ($list as $set) { + $data[$keys[$set->{$this->throughKey}]][] = $set; + } + + return $data; + } /** * 关联统计 * @access public - * @param Model $result 数据对象 - * @param \Closure $closure 闭包 - * @param string $aggregate 聚合查询方法 - * @param string $field 字段 - * @param string $name 统计字段别名 + * @param Model $result 数据对象 + * @param Closure $closure 闭包 + * @param string $aggregate 聚合查询方法 + * @param string $field 字段 + * @param string $name 统计字段别名 * @return integer */ - public function relationCount($result, $closure, $aggregate = 'count', $field = '*', &$name = '') - {} + public function relationCount($result, $closure, $aggregate = 'count', $field = '*', &$name = null) + { + $localKey = $this->localKey; + + if (!isset($result->$localKey)) { + return 0; + } + + if ($closure) { + $return = $closure($this->query); + if ($return && is_string($return)) { + $name = $return; + } + } + + $alias = App::parseName(App::classBaseName($this->model)); + $throughTable = $this->through->getTable(); + $pk = $this->throughPk; + $throughKey = $this->throughKey; + $modelTable = $this->parent->getTable(); + + if (false === strpos($field, '.')) { + $field = $alias . '.' . $field; + } + + return $this->query + ->alias($alias) + ->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey) + ->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey) + ->where($throughTable . '.' . $this->foreignKey, $result->$localKey) + ->$aggregate($field); + } + + /** + * 创建关联统计子查询 + * @access public + * @param Closure $closure 闭包 + * @param string $aggregate 聚合查询方法 + * @param string $field 字段 + * @param string $name 统计字段别名 + * @return string + */ + public function getRelationCountQuery($closure = null, $aggregate = 'count', $field = '*', &$name = null) + { + if ($closure) { + $return = $closure($this->query); + if ($return && is_string($return)) { + $name = $return; + } + } + + $alias = App::parseName(App::classBaseName($this->model)); + $throughTable = $this->through->getTable(); + $pk = $this->throughPk; + $throughKey = $this->throughKey; + $modelTable = $this->parent->getTable(); + + if (false === strpos($field, '.')) { + $field = $alias . '.' . $field; + } + + return $this->query + ->alias($alias) + ->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey) + ->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey) + ->whereExp($throughTable . '.' . $this->foreignKey, '=' . $this->parent->getTable() . '.' . $this->localKey) + ->fetchSql() + ->$aggregate($field); + } /** * 执行基础查询(仅执行一次) @@ -134,10 +341,9 @@ class HasManyThrough extends Relation protected function baseQuery() { if (empty($this->baseQuery) && $this->parent->getData()) { - $through = $this->through; $alias = Loader::parseName(basename(str_replace('\\', '/', $this->model))); - $throughTable = $through::getTable(); - $pk = (new $through)->getPk(); + $throughTable = $this->through->getTable(); + $pk = $this->throughPk; $throughKey = $this->throughKey; $modelTable = $this->parent->getTable(); $fields = $this->getQueryFields($alias); diff --git a/thinkphp/library/think/model/relation/HasOne.php b/thinkphp/library/think/model/relation/HasOne.php index d8e3ec79..7d582a14 100644 --- a/thinkphp/library/think/model/relation/HasOne.php +++ b/thinkphp/library/think/model/relation/HasOne.php @@ -139,13 +139,17 @@ class HasOne extends OneToOne $relation = basename(str_replace('\\', '/', $this->model)); $localKey = $this->localKey; $foreignKey = $this->foreignKey; + $softDelete = $this->query->getOptions('soft_delete'); return $this->parent->db() ->alias($model) ->whereExists(function ($query) use ($table, $model, $relation, $localKey, $foreignKey) { $query->table([$table => $relation]) ->field($relation . '.' . $foreignKey) - ->whereExp($model . '.' . $localKey, '=' . $relation . '.' . $foreignKey); + ->whereExp($model . '.' . $localKey, '=' . $relation . '.' . $foreignKey) + ->when($softDelete, function ($query) use ($softDelete, $relation) { + $query->where($relation . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null); + }); }); } @@ -166,12 +170,16 @@ class HasOne extends OneToOne $this->getQueryWhere($where, $relation); } - $fields = $this->getRelationQueryFields($fields, $model); + $fields = $this->getRelationQueryFields($fields, $model); + $softDelete = $this->query->getOptions('soft_delete'); return $this->parent->db() ->alias($model) ->field($fields) ->join([$table => $relation], $model . '.' . $this->localKey . '=' . $relation . '.' . $this->foreignKey, $this->joinType) + ->when($softDelete, function ($query) use ($softDelete, $relation) { + $query->where($relation . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null); + }) ->where($where); } diff --git a/thinkphp/library/think/response/View.php b/thinkphp/library/think/response/View.php index c836ccb5..3d54c735 100644 --- a/thinkphp/library/think/response/View.php +++ b/thinkphp/library/think/response/View.php @@ -18,9 +18,16 @@ class View extends Response // 输出参数 protected $options = []; protected $vars = []; + protected $config = []; protected $filter; protected $contentType = 'text/html'; + /** + * 是否内容渲染 + * @var bool + */ + protected $isContent = false; + /** * 处理数据 * @access protected @@ -32,7 +39,19 @@ class View extends Response // 渲染模板输出 return $this->app['view'] ->filter($this->filter) - ->fetch($data, $this->vars); + ->fetch($data, $this->vars, $this->config, $this->isContent); + } + + /** + * 设置是否为内容渲染 + * @access public + * @param bool $content + * @return $this + */ + public function isContent($content = true) + { + $this->isContent = $content; + return $this; } /** @@ -68,6 +87,12 @@ class View extends Response return $this; } + public function config($config) + { + $this->config = $config; + return $this; + } + /** * 视图内容过滤 * @access public diff --git a/thinkphp/library/think/route/Dispatch.php b/thinkphp/library/think/route/Dispatch.php index 93afe73b..7323c98d 100644 --- a/thinkphp/library/think/route/Dispatch.php +++ b/thinkphp/library/think/route/Dispatch.php @@ -11,9 +11,9 @@ namespace think\route; +use think\App; use think\Container; use think\exception\ValidateException; -use think\App; use think\Request; use think\Response; @@ -181,9 +181,10 @@ abstract class Dispatch $response = Response::create($data, $type); } else { - $data = ob_get_clean(); - $content = false === $data ? '' : $data; - $status = '' === $content && $this->request->isAjax() ? 204 : 200; + $data = ob_get_clean(); + $content = false === $data ? '' : $data; + $status = '' === $content && $this->request->isJson() ? 204 : 200; + $response = Response::create($content, '', $status); } diff --git a/thinkphp/library/think/route/dispatch/Module.php b/thinkphp/library/think/route/dispatch/Module.php index e8842cd3..40bd7759 100644 --- a/thinkphp/library/think/route/dispatch/Module.php +++ b/thinkphp/library/think/route/dispatch/Module.php @@ -12,7 +12,6 @@ namespace think\route\dispatch; use ReflectionMethod; -use think\Controller; use think\exception\ClassNotFoundException; use think\exception\HttpException; use think\Loader; diff --git a/vendor/aliyuncs/oss-sdk-php/build-phar.sh b/vendor/aliyuncs/oss-sdk-php/build-phar.sh old mode 100644 new mode 100755 diff --git a/vendor/autoload.php b/vendor/autoload.php index d224ed8b..5eafad26 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit04f78adc0d26d025ab398ddde054e232::getLoader(); +return ComposerAutoloaderInitf4c14462dd5d252f636d41b5c1345996::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index f7d0a788..82c10fb0 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit04f78adc0d26d025ab398ddde054e232 +class ComposerAutoloaderInitf4c14462dd5d252f636d41b5c1345996 { private static $loader; @@ -19,15 +19,15 @@ class ComposerAutoloaderInit04f78adc0d26d025ab398ddde054e232 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit04f78adc0d26d025ab398ddde054e232', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInitf4c14462dd5d252f636d41b5c1345996', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); - spl_autoload_unregister(array('ComposerAutoloaderInit04f78adc0d26d025ab398ddde054e232', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInitf4c14462dd5d252f636d41b5c1345996', 'loadClassLoader')); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { require_once __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit04f78adc0d26d025ab398ddde054e232::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInitf4c14462dd5d252f636d41b5c1345996::getInitializer($loader)); } else { $map = require __DIR__ . '/autoload_namespaces.php'; foreach ($map as $namespace => $path) { @@ -48,19 +48,19 @@ class ComposerAutoloaderInit04f78adc0d26d025ab398ddde054e232 $loader->register(true); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInit04f78adc0d26d025ab398ddde054e232::$files; + $includeFiles = Composer\Autoload\ComposerStaticInitf4c14462dd5d252f636d41b5c1345996::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequire04f78adc0d26d025ab398ddde054e232($fileIdentifier, $file); + composerRequiref4c14462dd5d252f636d41b5c1345996($fileIdentifier, $file); } return $loader; } } -function composerRequire04f78adc0d26d025ab398ddde054e232($fileIdentifier, $file) +function composerRequiref4c14462dd5d252f636d41b5c1345996($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { require $file; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 4e4ef451..7d72d96e 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit04f78adc0d26d025ab398ddde054e232 +class ComposerStaticInitf4c14462dd5d252f636d41b5c1345996 { public static $files = array ( '7b11c4dc42b3b3023073cb14e519683c' => __DIR__ . '/..' . '/ralouphie/getallheaders/src/getallheaders.php', @@ -134,9 +134,9 @@ class ComposerStaticInit04f78adc0d26d025ab398ddde054e232 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit04f78adc0d26d025ab398ddde054e232::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit04f78adc0d26d025ab398ddde054e232::$prefixDirsPsr4; - $loader->prefixesPsr0 = ComposerStaticInit04f78adc0d26d025ab398ddde054e232::$prefixesPsr0; + $loader->prefixLengthsPsr4 = ComposerStaticInitf4c14462dd5d252f636d41b5c1345996::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInitf4c14462dd5d252f636d41b5c1345996::$prefixDirsPsr4; + $loader->prefixesPsr0 = ComposerStaticInitf4c14462dd5d252f636d41b5c1345996::$prefixesPsr0; }, null, ClassLoader::class); } diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 2811bb5c..f66d2bb0 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -497,17 +497,17 @@ }, { "name": "qcloud/cos-sdk-v5", - "version": "v1.3.2", - "version_normalized": "1.3.2.0", + "version": "v1.3.3", + "version_normalized": "1.3.3.0", "source": { "type": "git", "url": "https://github.com/tencentyun/cos-php-sdk-v5.git", - "reference": "0454f48629210749ae6316ab317548169dac9d8f" + "reference": "cd1b9cefa04521eaf125a82eb53552d9a87aae4d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/tencentyun/cos-php-sdk-v5/zipball/0454f48629210749ae6316ab317548169dac9d8f", - "reference": "0454f48629210749ae6316ab317548169dac9d8f", + "url": "https://api.github.com/repos/tencentyun/cos-php-sdk-v5/zipball/cd1b9cefa04521eaf125a82eb53552d9a87aae4d", + "reference": "cd1b9cefa04521eaf125a82eb53552d9a87aae4d", "shasum": "", "mirrors": [ { @@ -520,7 +520,7 @@ "guzzle/guzzle": "~3.7", "php": ">=5.3.0" }, - "time": "2019-04-25T12:23:41+00:00", + "time": "2019-08-07T10:15:47+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -726,17 +726,17 @@ }, { "name": "topthink/framework", - "version": "v5.1.37.1", - "version_normalized": "5.1.37.1", + "version": "v5.1.38", + "version_normalized": "5.1.38.0", "source": { "type": "git", "url": "https://github.com/top-think/framework.git", - "reference": "05eecd121d18d6705aaa10aa44fcdf7c14da4d0b" + "reference": "b538d2615794bfd05455b6f8232a359d09f5a8df" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/top-think/framework/zipball/05eecd121d18d6705aaa10aa44fcdf7c14da4d0b", - "reference": "05eecd121d18d6705aaa10aa44fcdf7c14da4d0b", + "url": "https://api.github.com/repos/top-think/framework/zipball/b538d2615794bfd05455b6f8232a359d09f5a8df", + "reference": "b538d2615794bfd05455b6f8232a359d09f5a8df", "shasum": "", "mirrors": [ { @@ -758,7 +758,7 @@ "sebastian/phpcpd": "2.*", "squizlabs/php_codesniffer": "2.*" }, - "time": "2019-05-28T06:57:29+00:00", + "time": "2019-08-09T07:12:36+00:00", "type": "think-framework", "installation-source": "dist", "notification-url": "https://packagist.org/downloads/", diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/RedirectPluginTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/RedirectPluginTest.php old mode 100644 new mode 100755 diff --git a/vendor/qcloud/cos-sdk-v5/.travis.yml b/vendor/qcloud/cos-sdk-v5/.travis.yml index 0392843c..99220f26 100644 --- a/vendor/qcloud/cos-sdk-v5/.travis.yml +++ b/vendor/qcloud/cos-sdk-v5/.travis.yml @@ -1,6 +1,6 @@ language: php php: - - 5.4 + - 5.6 script: - composer install - phpunit -v diff --git a/vendor/qcloud/cos-sdk-v5/sample/putBucketCors.php b/vendor/qcloud/cos-sdk-v5/sample/putBucketCors.php index 1135bb9b..375077bf 100644 --- a/vendor/qcloud/cos-sdk-v5/sample/putBucketCors.php +++ b/vendor/qcloud/cos-sdk-v5/sample/putBucketCors.php @@ -15,27 +15,15 @@ $cosClient = new Qcloud\Cos\Client( try { $result = $cosClient->putBucketCors(array( 'Bucket' => 'examplebucket-125000000', //格式:BucketName-APPID - 'Rules' => array( + 'CORSRules' => array( array( - 'Expiration' => array( - 'Days' => integer, - ), - 'ID' => 'string', - 'Filter' => array( - 'Prefix' => 'string' - ), - 'Status' => 'string', - 'Transitions' => array( - array( - 'Days' => integer, - 'StorageClass' => 'string' - ), - // ... repeated - ), + 'ID' => '1234', + 'AllowedHeaders' => array('*'), + 'AllowedMethods' => array('PUT'), + 'AllowedOrigins' => array('http://www.qq.com'), ), - // ... repeated - ) - ); + ), + )); // 请求成功 print_r($result); } catch (\Exception $e) { diff --git a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/BucketStyleListener.php b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/BucketStyleListener.php index b1bd5667..a7f29b8e 100644 --- a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/BucketStyleListener.php +++ b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/BucketStyleListener.php @@ -73,13 +73,13 @@ class BucketStyleListener implements EventSubscriberInterface { } } $request->setHeader('Date', gmdate('D, d M Y H:i:s T')); - $request->setPath(preg_replace("#^/{$bucket}#", '', $request->getPath())); + $url_bucket = rawurlencode($bucket); + $request->setPath(preg_replace("#^/{$url_bucket}#", '', $request->getPath())); if ($this->appId != null && endWith($bucket,'-'.$this->appId) == False) { $bucket = $bucket.'-'.$this->appId; } -// $request->setPath(urldecode($request->getPath())); $request->getParams()->set('bucket', $bucket)->set('key', $key); $realHost = $bucket. '.' . $request->getHost(); diff --git a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Client.php b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Client.php index 2ec9218b..53bb78db 100644 --- a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Client.php +++ b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Client.php @@ -12,7 +12,7 @@ use Qcloud\Cos\Signature; use Qcloud\Cos\TokenListener; class Client extends GSClient { - const VERSION = '1.3.2'; + const VERSION = '1.3.3'; private $region; // string: region. private $credentials; @@ -66,7 +66,6 @@ class Client extends GSClient { $this->addSubscriber(new TokenListener($this->token)); $this->addSubscriber(new SignatureListener($this->secretId, $this->secretKey)); $this->addSubscriber(new BucketStyleListener($this->appId, $this->ip, $this->port, $this->endpoint)); - // Allow for specifying bodies with file paths and file handles $this->addSubscriber(new UploadBodyListener(array('PutObject', 'UploadPart'))); } @@ -122,6 +121,7 @@ class Client extends GSClient { ) + $options['params']); $rt['Location'] = $rt['ObjectURL']; + $rt['Location'] = ltrim($rt['Location'], $this->schema. "://"); unset($rt['ObjectURL']); } else { @@ -132,6 +132,8 @@ class Client extends GSClient { ) + $options['params']); $rt = $multipartUpload->performUploading(); + unset($rt['Bucket']); + unset($rt['Key']); } return $rt; } diff --git a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/ExceptionParser.php b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/ExceptionParser.php index ab1cd9b4..be65eedb 100644 --- a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/ExceptionParser.php +++ b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/ExceptionParser.php @@ -27,13 +27,10 @@ class ExceptionParser { } try { - $xml = new \SimpleXMLElement($body); + $xml = new \SimpleXMLElement(utf8_encode($body)); $this->parseBody($xml, $data); return $data; } catch (\Exception $e) { - // Gracefully handle parse errors. This could happen when the - // server responds with a non-XML response (e.g., private beta - // services). $data['code'] = 'PhpInternalXmlParseError'; $data['message'] = 'A non-XML response was received'; return $data; diff --git a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Signature.php b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Signature.php index ae5fa10d..2b1b46cf 100644 --- a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Signature.php +++ b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Signature.php @@ -11,7 +11,6 @@ class Signature { public function __destruct() { } public function signRequest(RequestInterface $request) { - $signTime = (string)(time() - 60) . ';' . (string)(time() + 3600); $httpString = strtolower($request->getMethod()) . "\n" . urldecode($request->getPath()) . "\n\nhost=" . $request->getHost() . "\n"; @@ -48,4 +47,4 @@ class Signature { $request->getQuery()->add('sign', $authorization); return $request->getUrl(); } -} \ No newline at end of file +} diff --git a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Tests/Test.php b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Tests/Test.php index 4a8462ec..8b50b18d 100644 --- a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Tests/Test.php +++ b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Tests/Test.php @@ -606,6 +606,7 @@ class BucketTest extends \PHPUnit_Framework_TestCase ) ) )); + sleep(3); $result = $this->cosClient->getBucketLifecycle(array( // Bucket is required 'Bucket' => $this->bucket, diff --git a/vendor/qiniu/php-sdk/docs/sms/example.php b/vendor/qiniu/php-sdk/docs/sms/example.php new file mode 100644 index 00000000..541c0d6c --- /dev/null +++ b/vendor/qiniu/php-sdk/docs/sms/example.php @@ -0,0 +1,70 @@ + 'code' ); +try { + //发送短信 + $resp = $client->sendMessage($template_id, $mobiles, $code); + print_r($resp); +} catch (\Exception $e) { + echo "Error:", $e, "\n"; +}exit; +//模板模块 +$name="tstest001"; +$template="tesy001 ${code}"; +$type="notification"; +$description="tstest001"; +$signature_id="1131464448834277376"; +$id="1131810682442883072"; + +try { + //创建模板 + $resp = $client->createTemplate($name, $template, $type, $description, $signature_id); + print_r($resp); + //查询模板 + $resp = $client->queryTemplate(); + print_r($resp); + //修改模板 + $resp = $client->updateTemplate($id, $name, $template, $description, $signature_id); + print_r($resp); + //删除模板 + $resp = $client->deleteTemplate($id); + print_r($resp); +} catch (\Exception $e) { + echo "Error:", $e, "\n"; +} +//签名模块 +$signature = 'lfxlive2'; +$source = 'enterprises_and_institutions'; +$pic="/Users/Desktop/sss.jpg"; +$audit_status="passed"; +$page=1; +$page_size=1; +$id="1131464448834277376"; + +try { + //创建签名 + $resp = $client->createSignature($signature, $source, $pic); + print_r($resp); + //查询签名 + $resp = $client->checkSignature($audit_status); + //修改签名 + $resp = $client->updateSignature($id, $signature, $source, $pic); + print_r($resp); + //删除ID + $resp = $client->deleteSignature($id); + print_r($resp); +} catch (\Exception $e) { + echo "Error:", $e, "\n"; +} diff --git a/vendor/qiniu/php-sdk/examples/bucket_lifecycleRule.php b/vendor/qiniu/php-sdk/examples/bucket_lifecycleRule.php new file mode 100644 index 00000000..3f7fefd5 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/bucket_lifecycleRule.php @@ -0,0 +1,30 @@ +bucketLifecycleRule( + $bucket, + $name, + $prefix, + $delete_after_days, + $to_line_after_days +); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/delete_bucket.php b/vendor/qiniu/php-sdk/examples/delete_bucket.php new file mode 100644 index 00000000..dc2e3050 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/delete_bucket.php @@ -0,0 +1,20 @@ +deleteBucket($name); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/delete_bucketEvent.php b/vendor/qiniu/php-sdk/examples/delete_bucketEvent.php new file mode 100644 index 00000000..00df6cae --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/delete_bucketEvent.php @@ -0,0 +1,21 @@ +deleteBucketEvent($bucket, $name); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/delete_bucketLifecycleRule.php b/vendor/qiniu/php-sdk/examples/delete_bucketLifecycleRule.php new file mode 100644 index 00000000..a5369926 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/delete_bucketLifecycleRule.php @@ -0,0 +1,21 @@ +deleteBucketLifecycleRule($bucket, $name); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/get_bucketEvents.php b/vendor/qiniu/php-sdk/examples/get_bucketEvents.php new file mode 100644 index 00000000..53a5c88d --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/get_bucketEvents.php @@ -0,0 +1,20 @@ +getBucketEvents($bucket); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/get_bucketLifecycleRules.php b/vendor/qiniu/php-sdk/examples/get_bucketLifecycleRules.php new file mode 100644 index 00000000..652bee8c --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/get_bucketLifecycleRules.php @@ -0,0 +1,20 @@ +getBucketLifecycleRules($bucket); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/get_bucketList.php b/vendor/qiniu/php-sdk/examples/get_bucketList.php new file mode 100644 index 00000000..74aaa65f --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/get_bucketList.php @@ -0,0 +1,20 @@ +listbuckets($region); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/get_bucketQuota.php b/vendor/qiniu/php-sdk/examples/get_bucketQuota.php new file mode 100644 index 00000000..563395d6 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/get_bucketQuota.php @@ -0,0 +1,20 @@ +getBucketQuota($bucket); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/get_bucketinfo.php b/vendor/qiniu/php-sdk/examples/get_bucketinfo.php new file mode 100644 index 00000000..ff052a43 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/get_bucketinfo.php @@ -0,0 +1,20 @@ +bucketInfo($bucket); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/get_bucketinfos.php b/vendor/qiniu/php-sdk/examples/get_bucketinfos.php new file mode 100644 index 00000000..0ad65032 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/get_bucketinfos.php @@ -0,0 +1,20 @@ +bucketInfos($region); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/get_corsRules.php b/vendor/qiniu/php-sdk/examples/get_corsRules.php new file mode 100644 index 00000000..fbfde2d2 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/get_corsRules.php @@ -0,0 +1,20 @@ +getCorsRules($bucket); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/put_bucketAccessMode.php b/vendor/qiniu/php-sdk/examples/put_bucketAccessMode.php new file mode 100644 index 00000000..b4539264 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/put_bucketAccessMode.php @@ -0,0 +1,21 @@ +putBucketAccessMode($bucket, $private); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/put_bucketAccessStyleMode.php b/vendor/qiniu/php-sdk/examples/put_bucketAccessStyleMode.php new file mode 100644 index 00000000..2f7c27f2 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/put_bucketAccessStyleMode.php @@ -0,0 +1,21 @@ +putBucketAccessStyleMode($bucket, $mode); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/put_bucketEvent.php b/vendor/qiniu/php-sdk/examples/put_bucketEvent.php new file mode 100644 index 00000000..33dbb44c --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/put_bucketEvent.php @@ -0,0 +1,25 @@ +putBucketEvent($bucket, $name, $prefix, $suffix, $event, $callbackURL); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/put_bucketMaxAge.php b/vendor/qiniu/php-sdk/examples/put_bucketMaxAge.php new file mode 100644 index 00000000..77092e90 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/put_bucketMaxAge.php @@ -0,0 +1,21 @@ +putBucketMaxAge($bucket, $maxAge); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/put_bucketQuota.php b/vendor/qiniu/php-sdk/examples/put_bucketQuota.php new file mode 100644 index 00000000..18082b63 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/put_bucketQuota.php @@ -0,0 +1,22 @@ +putBucketQuota($bucket, $size, $count); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/put_referAntiLeech.php b/vendor/qiniu/php-sdk/examples/put_referAntiLeech.php new file mode 100644 index 00000000..6828bc9a --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/put_referAntiLeech.php @@ -0,0 +1,23 @@ +putReferAntiLeech($bucket, $mode, $norefer, $pattern); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/rs_pub_domain.php b/vendor/qiniu/php-sdk/examples/rs_pub_domain.php new file mode 100644 index 00000000..2e81922e --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/rs_pub_domain.php @@ -0,0 +1,19 @@ +publishDomain($bucket, $domain); +if ($err) { + print_r($err); +} diff --git a/vendor/qiniu/php-sdk/examples/rsf_v2list_bucket.php b/vendor/qiniu/php-sdk/examples/rsf_v2list_bucket.php new file mode 100644 index 00000000..4dcf2709 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/rsf_v2list_bucket.php @@ -0,0 +1,33 @@ +listFilesv2($bucket, $prefix, $marker, $limit, $delimiter, true); + +if ($err) { + print_r($err); +} else { + print_r($ret); +} diff --git a/vendor/qiniu/php-sdk/examples/update_bucketEvent.php b/vendor/qiniu/php-sdk/examples/update_bucketEvent.php new file mode 100644 index 00000000..26347ac4 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/update_bucketEvent.php @@ -0,0 +1,25 @@ +updateBucketEvent($bucket, $name, $prefix, $suffix, $event, $callbackURL); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/update_bucketLifecycleRule.php b/vendor/qiniu/php-sdk/examples/update_bucketLifecycleRule.php new file mode 100644 index 00000000..85eb07a6 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/update_bucketLifecycleRule.php @@ -0,0 +1,30 @@ +updateBucketLifecycleRule( + $bucket, + $name, + $prefix, + $delete_after_days, + $to_line_after_days +); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/src/Qiniu/Region.php b/vendor/qiniu/php-sdk/src/Qiniu/Region.php new file mode 100644 index 00000000..eae21d19 --- /dev/null +++ b/vendor/qiniu/php-sdk/src/Qiniu/Region.php @@ -0,0 +1,196 @@ +srcUpHosts = $srcUpHosts; + $this->cdnUpHosts = $cdnUpHosts; + $this->rsHost = $rsHost; + $this->rsfHost = $rsfHost; + $this->apiHost = $apiHost; + $this->iovipHost = $iovipHost; + } + + //华东机房 + public static function regionHuadong() + { + $regionHuadong = new Region( + array("up.qiniup.com", 'up-jjh.qiniup.com', 'up-xs.qiniup.com'), + array('upload.qiniup.com', 'upload-jjh.qiniup.com', 'upload-xs.qiniup.com'), + 'rs.qbox.me', + 'rsf.qbox.me', + 'api.qiniu.com', + 'iovip.qbox.me' + ); + return $regionHuadong; + } + + //华东机房内网上传 + public static function qvmRegionHuadong() + { + $qvmRegionHuadong = new Region( + array("free-qvm-z0-xs.qiniup.com"), + 'rs.qbox.me', + 'rsf.qbox.me', + 'api.qiniu.com', + 'iovip.qbox.me' + ); + return $qvmRegionHuadong; + } + + //华北机房内网上传 + public static function qvmRegionHuabei() + { + $qvmRegionHuabei = new Region( + array("free-qvm-z1-zz.qiniup.com"), + "rs-z1.qbox.me", + "rsf-z1.qbox.me", + "api-z1.qiniu.com", + "iovip-z1.qbox.me" + ); + return $qvmRegionHuabei; + } + + //华北机房 + public static function regionHuabei() + { + $regionHuabei = new Region( + array('up-z1.qiniup.com'), + array('upload-z1.qiniup.com'), + "rs-z1.qbox.me", + "rsf-z1.qbox.me", + "api-z1.qiniu.com", + "iovip-z1.qbox.me" + ); + + return $regionHuabei; + } + + //华南机房 + public static function regionHuanan() + { + $regionHuanan = new Region( + array('up-z2.qiniup.com', 'up-dg.qiniup.com', 'up-fs.qiniup.com'), + array('upload-z2.qiniup.com', 'upload-dg.qiniup.com', 'upload-fs.qiniup.com'), + "rs-z2.qbox.me", + "rsf-z2.qbox.me", + "api-z2.qiniu.com", + "iovip-z2.qbox.me" + ); + return $regionHuanan; + } + + //北美机房 + public static function regionNorthAmerica() + { + //北美机房 + $regionNorthAmerica = new Region( + array('up-na0.qiniup.com'), + array('upload-na0.qiniup.com'), + "rs-na0.qbox.me", + "rsf-na0.qbox.me", + "api-na0.qiniu.com", + "iovip-na0.qbox.me" + ); + return $regionNorthAmerica; + } + + //新加坡机房 + public static function regionSingapore() + { + //新加坡机房 + $regionSingapore = new Region( + array('up-as0.qiniup.com'), + array('upload-as0.qiniup.com'), + "rs-as0.qbox.me", + "rsf-as0.qbox.me", + "api-as0.qiniu.com", + "iovip-as0.qbox.me" + ); + return $regionSingapore; + } + + /* + * GET /v2/query?ak=&&bucket= + **/ + public static function queryRegion($ak, $bucket) + { + $Region = new Region(); + $url = Config::API_HOST . '/v2/query' . "?ak=$ak&bucket=$bucket"; + $ret = Client::Get($url); + if (!$ret->ok()) { + return array(null, new Error($url, $ret)); + } + $r = ($ret->body === null) ? array() : $ret->json(); + //parse Region; + + $iovipHost = $r['io']['src']['main'][0]; + $Region->iovipHost = $iovipHost; + $accMain = $r['up']['acc']['main'][0]; + array_push($Region->cdnUpHosts, $accMain); + if (isset($r['up']['acc']['backup'])) { + foreach ($r['up']['acc']['backup'] as $key => $value) { + array_push($Region->cdnUpHosts, $value); + } + } + $srcMain = $r['up']['src']['main'][0]; + array_push($Region->srcUpHosts, $srcMain); + if (isset($r['up']['src']['backup'])) { + foreach ($r['up']['src']['backup'] as $key => $value) { + array_push($Region->srcUpHosts, $value); + } + } + + //set specific hosts + if (strstr($Region->iovipHost, "z1") !== false) { + $Region->rsHost = "rs-z1.qbox.me"; + $Region->rsfHost = "rsf-z1.qbox.me"; + $Region->apiHost = "api-z1.qiniu.com"; + } elseif (strstr($Region->iovipHost, "z2") !== false) { + $Region->rsHost = "rs-z2.qbox.me"; + $Region->rsfHost = "rsf-z2.qbox.me"; + $Region->apiHost = "api-z2.qiniu.com"; + } elseif (strstr($Region->iovipHost, "na0") !== false) { + $Region->rsHost = "rs-na0.qbox.me"; + $Region->rsfHost = "rsf-na0.qbox.me"; + $Region->apiHost = "api-na0.qiniu.com"; + } elseif (strstr($Region->iovipHost, "as0") !== false) { + $Region->rsHost = "rs-as0.qbox.me"; + $Region->rsfHost = "rsf-as0.qbox.me"; + $Region->apiHost = "api-as0.qiniu.com"; + } else { + $Region->rsHost = "rs.qbox.me"; + $Region->rsfHost = "rsf.qbox.me"; + $Region->apiHost = "api.qiniu.com"; + } + + return $Region; + } +} diff --git a/vendor/qiniu/php-sdk/src/Qiniu/Sms/Sms.php b/vendor/qiniu/php-sdk/src/Qiniu/Sms/Sms.php new file mode 100644 index 00000000..592d6ba7 --- /dev/null +++ b/vendor/qiniu/php-sdk/src/Qiniu/Sms/Sms.php @@ -0,0 +1,337 @@ +auth = $auth; + + $this->baseURL = sprintf("%s/%s/", Config::SMS_HOST, Config::SMS_VERSION); + } + + /* + * 创建签名 + * signature: string 类型,必填,【长度限制8个字符内】超过长度会报错 + * source: string 类型,必填,申请签名时必须指定签名来源。取值范围为: + nterprises_and_institutions 企事业单位的全称或简称 + website 工信部备案网站的全称或简称 + app APP应用的全称或简称 + public_number_or_small_program 公众号或小程序的全称或简称 + store_name 电商平台店铺名的全称或简称 + trade_name 商标名的全称或简称, + * pics: 本地的图片路径 string 类型,可选 + *@return: 类型array { + "signature_id": + } + */ + public function createSignature(string $signature, string $source, string $pics = null) + { + $params['signature'] = $signature; + $params['source'] = $source; + if (!empty($pics)) { + $params['pics'] = $this->imgToBase64($pics); + } + $body = json_encode($params); + $url =$this->baseURL.'signature'; + $ret = $this->post($url, $body); + return $ret; + } + + /* + * 编辑签名 + * id 签名id : string 类型,必填, + * signature: string 类型,必填, + * source: string 类型,必填,申请签名时必须指定签名来源。取值范围为: + enterprises_and_institutions 企事业单位的全称或简称 + website 工信部备案网站的全称或简称 + app APP应用的全称或简称 + public_number_or_small_program 公众号或小程序的全称或简称 + store_name 电商平台店铺名的全称或简称 + trade_name 商标名的全称或简称, + * pics: 本地的图片路径 string 类型,可选, + * @return: 类型array { + "signature": string + } + */ + public function updateSignature(string $id, string $signature, string $source, string $pics = null) + { + $params['signature'] = $signature; + $params['source'] = $source; + if (!empty($pics)) { + $params['pics'] = $this->imgToBase64($pics); + } + $body = json_encode($params); + $url =$this->baseURL.'signature/'.$id; + $ret = $this->PUT($url, $body); + return $ret; + } + + /* + * 查询签名 + * audit_status: 审核状态 string 类型,可选, + 取值范围为: "passed"(通过), "rejected"(未通过), "reviewing"(审核中) + * page:页码 int 类型, + * page_size: 分页大小 int 类型,可选, 默认为20 + *@return: 类型array { + "items": [{ + "id": string, + "signature": string, + "source": string, + "audit_status": string, + "reject_reason": string, + "created_at": int64, + "updated_at": int64 + }...], + "total": int, + "page": int, + "page_size": int, + } + */ + public function checkSignature(string $audit_status = null, int $page = 1, int $page_size = 20) + { + + $url = sprintf( + "%s?audit_status=%s&page=%s&page_size=%s", + $this->baseURL.'signature', + $audit_status, + $page, + $page_size + ); + $ret = $this->get($url); + return $ret; + } + + + /* + * 删除签名 + * id 签名id string 类型,必填, + * @retrun : 请求成功 HTTP 状态码为 200 + */ + public function deleteSignature(string $id) + { + $url = $this->baseURL . 'signature/' . $id; + list(, $err) = $this->delete($url); + return $err; + } + + + + + /* + * 创建模板 + * name : 模板名称 string 类型 ,必填 + * template: 模板内容 string 类型,必填 + * type: 模板类型 string 类型,必填, + 取值范围为: notification (通知类短信), verification (验证码短信), marketing (营销类短信) + * description: 申请理由简述 string 类型,必填 + * signature_id: 已经审核通过的签名 string 类型,必填 + * @return: 类型 array { + "template_id": string + } + */ + public function createTemplate( + string $name, + string $template, + string $type, + string $description, + string $signture_id + ) { + $params['name'] = $name; + $params['template'] = $template; + $params['type'] = $type; + $params['description'] = $description; + $params['signature_id'] = $signture_id; + + $body = json_encode($params); + $url =$this->baseURL.'template'; + $ret = $this->post($url, $body); + return $ret; + } + + /* + * 查询模板 + * audit_status: 审核状态 string 类型 ,可选, + 取值范围为: passed (通过), rejected (未通过), reviewing (审核中) + * page: 页码 int 类型,可选,默认为 1 + * page_size: 分页大小 int 类型,可选,默认为 20 + * @return: 类型array{ + "items": [{ + "id": string, + "name": string, + "template": string, + "audit_status": string, + "reject_reason": string, + "type": string, + "signature_id": string, // 模版绑定的签名ID + "signature_text": string, // 模版绑定的签名内容 + "created_at": int64, + "updated_at": int64 + }...], + "total": int, + "page": int, + "page_size": int + } + */ + public function queryTemplate(string $audit_status = null, int $page = 1, int $page_size = 20) + { + + $url = sprintf( + "%s?audit_status=%s&page=%s&page_size=%s", + $this->baseURL.'template', + $audit_status, + $page, + $page_size + ); + $ret = $this->get($url); + return $ret; + } + + /* + * 编辑模板 + * id :模板id + * name : 模板名称 string 类型 ,必填 + * template: 模板内容 string 类型,必填 + * description: 申请理由简述 string 类型,必填 + * signature_id: 已经审核通过的签名 string 类型,必填 + * @retrun : 请求成功 HTTP 状态码为 200 + */ + public function updateTemplate( + string $id, + string $name, + string $template, + string $description, + string $signature_id + ) { + $params['name'] = $name; + $params['template'] = $template; + $params['description'] = $description; + $params['signature_id'] = $signature_id; + $body = json_encode($params); + $url =$this->baseURL.'template/'.$id; + $ret = $this->PUT($url, $body); + return $ret; + } + + /* + * 删除模板 + * id :模板id string 类型,必填, + * @retrun : 请求成功 HTTP 状态码为 200 + */ + public function deleteTemplate(string $id) + { + $url = $this->baseURL . 'template/' . $id; + list(, $err) = $this->delete($url); + return $err; + } + + /* + * 发送短信 + * 编辑模板 + * template_id :模板id string类型,必填 + * mobiles : 手机号数组 []string 类型 ,必填 + * parameters: 模板内容 map[string]string 类型,可选 + * @return: 类型json { + "job_id": string + } + */ + public function sendMessage(string $template_id, array $mobiles, array $parameters = null) + { + $params['template_id'] = $template_id; + $params['mobiles'] = $mobiles; + if (!empty($parameters)) { + $params['parameters'] = $parameters; + } + $body = json_encode($params); + $url =$this->baseURL.'message'; + $ret = $this->post($url, $body); + return $ret; + } + + public function imgToBase64(string $img_file) + { + $img_base64 = ''; + if (file_exists($img_file)) { + $app_img_file = $img_file; // 图片路径 + $img_info = getimagesize($app_img_file); // 取得图片的大小,类型等 + $fp = fopen($app_img_file, "r"); // 图片是否可读权限 + if ($fp) { + $filesize = filesize($app_img_file); + if ($filesize > 5*1024*1024) { + die("pic size < 5M !"); + } + $content = fread($fp, $filesize); + $file_content = chunk_split(base64_encode($content)); // base64编码 + switch ($img_info[2]) { //判读图片类型 + case 1: + $img_type = 'gif'; + break; + case 2: + $img_type = 'jpg'; + break; + case 3: + $img_type = 'png'; + break; + } + //合成图片的base64编码 + $img_base64 = 'data:image/' . $img_type . ';base64,' . $file_content; + } + fclose($fp); + } + + return $img_base64; + } + + private function get($url, $cType = null) + { + $rtcToken = $this->auth->authorizationV2($url, "GET", null, $cType); + $rtcToken['Content-Type'] = $cType; + $ret = Client::get($url, $rtcToken); + if (!$ret->ok()) { + return array(null, new Error($url, $ret)); + } + return array($ret->json(), null); + } + + private function delete($url, $contentType = 'application/json') + { + $rtcToken = $this->auth->authorizationV2($url, "DELETE", null, $contentType); + $rtcToken['Content-Type'] = $contentType; + $ret = Client::delete($url, $rtcToken); + if (!$ret->ok()) { + return array(null, new Error($url, $ret)); + } + return array($ret->json(), null); + } + + private function post($url, $body, $contentType = 'application/json') + { + $rtcToken = $this->auth->authorizationV2($url, "POST", $body, $contentType); + $rtcToken['Content-Type'] = $contentType; + $ret = Client::post($url, $body, $rtcToken); + if (!$ret->ok()) { + return array(null, new Error($url, $ret)); + } + $r = ($ret->body === null) ? array() : $ret->json(); + return array($r, null); + } + private function PUT($url, $body, $contentType = 'application/json') + { + $rtcToken = $this->auth->authorizationV2($url, "PUT", $body, $contentType); + $rtcToken['Content-Type'] = $contentType; + $ret = Client::put($url, $body, $rtcToken); + if (!$ret->ok()) { + return array(null, new Error($url, $ret)); + } + $r = ($ret->body === null) ? array() : $ret->json(); + return array($r, null); + } +}