From 32f4f3314011c98744df4efadfada84cfee44f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Thu, 26 Nov 2020 01:19:53 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BC=98=E5=8C=96=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 ++ src/common.php | 2 +- src/service/aliyun/OssService.php | 28 +++---------- src/service/amap/AmApService.php | 58 +++++++++++++++++--------- src/service/baidu/BosService.php | 31 +++----------- src/service/baidu/LbsYunService.php | 16 ------- src/service/huaweicloud/ObsService.php | 30 +++---------- src/service/ksyun/Ks3Service.php | 39 +++++++---------- src/service/qiniu/KodoService.php | 27 +++--------- src/service/tencent/CosService.php | 31 +++----------- src/service/upyun/UssService.php | 23 ++-------- 11 files changed, 88 insertions(+), 200 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87fc61b..755ae01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v6.0.127 / 2020-11-26 +- 优化服务 + ## v6.0.127 / 2020-11-25 - 修复腾讯云存储 - 数组门面增加方法 diff --git a/src/common.php b/src/common.php index c7c6689..f9430c2 100644 --- a/src/common.php +++ b/src/common.php @@ -25,7 +25,7 @@ use DtApp\ThinkLibrary\service\SystemService; /** * 定义当前版本 */ -const VERSION = '6.0.127'; +const VERSION = '6.0.128'; if (!function_exists('get_ip_info')) { /** diff --git a/src/service/aliyun/OssService.php b/src/service/aliyun/OssService.php index 8ca25a0..b92ac73 100644 --- a/src/service/aliyun/OssService.php +++ b/src/service/aliyun/OssService.php @@ -77,33 +77,15 @@ class OssService extends Service } /** - * 获取配置信息 - * @return $this - */ - private function getConfig(): self - { - $this->accessKeyId = config('dtapp.aliyun.oss.access_key_id'); - $this->accessKeySecret = config('dtapp.aliyun.oss.access_key_secret'); - $this->endpoint = config('dtapp.aliyun.oss.endpoint'); - $this->bucket = config('dtapp.aliyun.oss.bucket'); - return $this; - } - - /** - * 上传文件 - * @param $object - * @param $filePath - * @return bool|string + * @param string $object + * @param string $filePath + * @return string|null */ - public function upload(string $object, string $filePath) + public function upload(string $object, string $filePath): ?string { - if (empty($this->accessKeySecret) || empty($this->accessKeySecret) || empty($this->endpoint) || empty($this->bucket)) { - $this->getConfig(); - } try { $ossClient = new OssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint); - $ossClient->uploadFile($this->bucket, $object, $filePath); - return config('dtapp.aliyun.oss.url', '') . $object; + return $ossClient->uploadFile($this->bucket, $object, $filePath); } catch (OssException $e) { return $e->getMessage(); } diff --git a/src/service/amap/AmApService.php b/src/service/amap/AmApService.php index 15448dd..6712c0e 100644 --- a/src/service/amap/AmApService.php +++ b/src/service/amap/AmApService.php @@ -19,7 +19,6 @@ namespace DtApp\ThinkLibrary\service\amap; -use DtApp\ThinkLibrary\exception\DtaException; use DtApp\ThinkLibrary\Service; use DtApp\ThinkLibrary\service\curl\HttpService; @@ -50,38 +49,21 @@ class AmApService extends Service * @param string $key * @return $this */ - public function key(string $key) + public function key(string $key): self { $this->key = $key; return $this; } - /** - * 获取配置信息 - * @return $this - */ - private function getConfig(): self - { - $this->key = config('dtapp.amap.key'); - return $this; - } - /** * 天气查询 * https://lbs.amap.com/api/webservice/guide/api/weatherinfo * @param string $city * @param string $extensions * @return array|bool|mixed|string - * @throws DtaException */ public function weather($city = "110101", $extensions = "base") { - if (empty($this->key)) { - $this->getConfig(); - } - if (empty($this->key)) { - throw new DtaException('请检查key参数'); - } $data = http_build_query([ "city" => $city, "extensions" => $extensions, @@ -92,4 +74,42 @@ class AmApService extends Service ->url("{$this->url}weather/weatherInfo?{$data}") ->toArray(); } + + /** + * 地理编码 + * https://lbs.amap.com/api/webservice/guide/api/georegeo#geo + * @param $address + * @param string $city + * @return array|bool|mixed|string + */ + public function gCoderGeo($address, $city = '') + { + $data = http_build_query([ + "city" => $city, + "address" => $address, + "key" => $this->key, + "output" => $this->output, + ]); + return HttpService::instance() + ->url("{$this->url}geocode/geo?{$data}") + ->toArray(); + } + + /** + * 逆地理编码 + * https://lbs.amap.com/api/webservice/guide/api/georegeo#regeo + * @param $location + * @return array|bool|mixed|string + */ + public function gCoderReGeo($location) + { + $data = http_build_query([ + "location" => $location, + "key" => $this->key, + "output" => $this->output, + ]); + return HttpService::instance() + ->url("{$this->url}geocode/regeo?{$data}") + ->toArray(); + } } diff --git a/src/service/baidu/BosService.php b/src/service/baidu/BosService.php index 887946f..547e6b5 100644 --- a/src/service/baidu/BosService.php +++ b/src/service/baidu/BosService.php @@ -77,30 +77,13 @@ class BosService extends Service } /** - * 获取配置信息 - * @return $this - */ - private function getConfig(): self - { - $this->accessKeyId = config('dtapp.baidu.bos.access_key_id'); - $this->secretAccessKey = config('dtapp.baidu.bos.secret_access_key'); - $this->endpoint = config('dtapp.baidu.bos.endpoint'); - $this->bucket = config('dtapp.baidu.bos.bucket'); - return $this; - } - - /** - * 上传文件 - * @param $object - * @param $filePath - * @return bool + * @param string $object + * @param string $filePath + * @return mixed * @throws Exception */ - public function upload(string $object, string $filePath): bool + public function upload(string $object, string $filePath) { - if (empty($this->accessKeyId) || empty($this->secretAccessKey) || empty($this->endpoint)) { - $this->getConfig(); - } // 设置BosClient的Access Key ID、Secret Access Key和ENDPOINT $BOS_TEST_CONFIG = array( 'credentials' => array( @@ -111,10 +94,6 @@ class BosService extends Service ); $client = new BosClient($BOS_TEST_CONFIG); // 从文件中直接上传Object - if (empty($this->bucket)) { - $this->getConfig(); - } - $client->putObjectFromFile($this->bucket, $object, $filePath); - return config('dtapp.baidu.bos.url', '') . $object; + return $client->putObjectFromFile($this->bucket, $object, $filePath); } } diff --git a/src/service/baidu/LbsYunService.php b/src/service/baidu/LbsYunService.php index 3e2b67a..61f58ac 100644 --- a/src/service/baidu/LbsYunService.php +++ b/src/service/baidu/LbsYunService.php @@ -51,16 +51,6 @@ class LbsYunService extends Service return $this; } - /** - * 获取配置信息 - * @return $this - */ - private function getConfig(): self - { - $this->ak = config('dtapp.baidu.lbs.ak'); - return $this; - } - /** * 国内天气查询 * http://lbsyun.baidu.com/index.php?title=webapi/weather @@ -72,9 +62,6 @@ class LbsYunService extends Service */ public function weather($district_id = 110100, string $coordtype = "bd09ll", string $location = "") { - if (empty($this->ak)) { - $this->getConfig(); - } if (empty($this->ak)) { throw new DtaException('请检查ak参数'); } @@ -103,9 +90,6 @@ class LbsYunService extends Service */ public function weatherAbroad($district_id = 110100, string $coordtype = "bd09ll", string $location = "", string $language = "cn") { - if (empty($this->ak)) { - $this->getConfig(); - } if (empty($this->ak)) { throw new DtaException('请检查ak参数'); } diff --git a/src/service/huaweicloud/ObsService.php b/src/service/huaweicloud/ObsService.php index 4932fad..492cbab 100644 --- a/src/service/huaweicloud/ObsService.php +++ b/src/service/huaweicloud/ObsService.php @@ -76,45 +76,25 @@ class ObsService extends Service } /** - * 获取配置信息 - * @return $this + * @param string $object + * @param string $filePath + * @return bool|\Obs\Internal\Common\Model */ - private function getConfig(): self + public function upload(string $object, string $filePath) { - $this->key = config('dtapp.huaweicloud.obs.key'); - $this->secret = config('dtapp.huaweicloud.obs.secret'); - $this->endpoint = config('dtapp.huaweicloud.obs.endpoint'); - $this->bucket = config('dtapp.huaweicloud.obs.bucket'); - return $this; - } - - /** - * 上传到华为云 - * @param $object - * @param $filePath - * @return bool - */ - public function upload(string $object, string $filePath): bool - { - if (empty($this->key) || empty($this->secret) || empty($this->endpoint)) { - $this->getConfig(); - } // 创建ObsClient实例 $obsClient = new ObsClient([ 'key' => $this->key, 'secret' => $this->secret, 'endpoint' => $this->endpoint ]); - if (empty($this->bucket)) { - $this->getConfig(); - } $resp = $obsClient->putObject([ 'Bucket' => $this->bucket, 'Key' => $object, 'SourceFile' => $filePath // localfile为待上传的本地文件路径,需要指定到具体的文件名 ]); if (isset($resp['RequestId'])) { - return config('dtapp.huaweicloud.obs.url', '') . $object; + return $resp; } return false; diff --git a/src/service/ksyun/Ks3Service.php b/src/service/ksyun/Ks3Service.php index fb14f90..04532f9 100644 --- a/src/service/ksyun/Ks3Service.php +++ b/src/service/ksyun/Ks3Service.php @@ -77,34 +77,26 @@ class Ks3Service extends Service } /** - * 获取配置信息 - * @return $this - */ - private function getConfig(): self - { - $this->accessKeyID = config('dtapp.ksyun.ks3.access_key_iD'); - $this->accessKeySecret = config('dtapp.ksyun.ks3.access_key_secret'); - $this->endpoint = config('dtapp.ksyun.ks3.endpoint'); - $this->bucket = config('dtapp.ksyun.ks3.bucket'); - return $this; - } - - /** - * 上传文件 * @param string $object * @param string $filePath - * @return bool|string + * @return bool */ - public function upload(string $object, string $filePath) + public function upload(string $object, string $filePath): ?bool { - if (empty($this->accessKeyID) || empty($this->accessKeySecret) || empty($this->endpoint)) { - $this->getConfig(); - } + //是否使用VHOST + define("KS3_API_VHOST", FALSE); + //是否开启日志(写入日志文件) + define("KS3_API_LOG", FALSE); + //是否显示日志(直接输出日志) + define("KS3_API_DISPLAY_LOG", FALSE); + //定义日志目录(默认是该项目log下) + define("KS3_API_LOG_PATH", ""); + //是否使用HTTPS + define("KS3_API_USE_HTTPS", FALSE); + //是否开启curl debug模式 + define("KS3_API_DEBUG_MODE", FALSE); require_once(__DIR__ . "/bin/Ks3Client.class.php"); $client = new Ks3Client($this->accessKeyID, $this->accessKeySecret, $this->endpoint); - if (empty($this->bucket)) { - $this->getConfig(); - } $content = fopen($filePath, 'rb'); $args = [ "Bucket" => $this->bucket, @@ -126,8 +118,7 @@ class Ks3Service extends Service ] ]; try { - $client->putObjectByFile($args); - return config('dtapp.ksyun.ks3.url', '') . $object; + return $client->putObjectByFile($args); } catch (Ks3ServiceException $e) { return false; } diff --git a/src/service/qiniu/KodoService.php b/src/service/qiniu/KodoService.php index 6142ffc..10da7a2 100644 --- a/src/service/qiniu/KodoService.php +++ b/src/service/qiniu/KodoService.php @@ -68,29 +68,13 @@ class KodoService extends Service } /** - * 获取配置信息 - * @return $this - */ - private function getConfig(): self - { - $this->accessKey = config('dtapp.qiniu.kodo.access_key'); - $this->secretKey = config('dtapp.qiniu.kodo.secret_key'); - $this->bucket = config('dtapp.qiniu.kodo.bucket'); - return $this; - } - - /** - * 上传文件 - * @param $object - * @param $filePath - * @return bool + * @param string $object + * @param string $filePath + * @return bool|mixed * @throws Exception */ - public function upload(string $object, string $filePath): bool + public function upload(string $object, string $filePath) { - if (empty($this->accessKey) || empty($this->secretKey) || empty($this->bucket)) { - $this->getConfig(); - } // 初始化签权对象 $auth = new Auth($this->accessKey, $this->secretKey); // 生成上传Token @@ -103,6 +87,7 @@ class KodoService extends Service return false; } - return config('dtapp.qiniu.kodo.url', '') . $object; + return $ret; + } } diff --git a/src/service/tencent/CosService.php b/src/service/tencent/CosService.php index 6e54be5..ae80468 100644 --- a/src/service/tencent/CosService.php +++ b/src/service/tencent/CosService.php @@ -20,7 +20,6 @@ namespace DtApp\ThinkLibrary\service\tencent; use DtApp\ThinkLibrary\Service; -use Exception; use Qcloud\Cos\Client; /** @@ -77,30 +76,12 @@ class CosService extends Service } /** - * 获取配置信息 - * @return $this - */ - private function getConfig(): self - { - $this->secretId = config('dtapp.tencent.cos.secret_id'); - $this->secretKey = config('dtapp.tencent.cos.secret_key'); - $this->region = config('dtapp.tencent.cos.region'); - $this->bucket = config('dtapp.tencent.cos.bucket'); - return $this; - } - - /** - * 上传文件 - * @param $object - * @param $filePath + * @param string $object + * @param string $filePath * @return bool - * @throws Exception */ public function upload(string $object, string $filePath): bool { - if (empty($this->secretId) || empty($this->secretKey) || empty($this->region)) { - $this->getConfig(); - } $cosClient = new Client([ 'region' => $this->region, 'schema' => 'https', @@ -111,14 +92,14 @@ class CosService extends Service ]); $key = $object; $file = fopen($filePath, "rb"); - if ($file && empty($this->bucket)) { - $this->getConfig(); - $result = $cosClient->putObject([ + if ($file) { + return $cosClient->putObject([ 'Bucket' => $this->bucket, 'Key' => $key, 'Body' => $file ]); } - return config('dtapp.tencent.cos.url', '') . $object; + + return false; } } diff --git a/src/service/upyun/UssService.php b/src/service/upyun/UssService.php index 816ad03..b056229 100644 --- a/src/service/upyun/UssService.php +++ b/src/service/upyun/UssService.php @@ -68,33 +68,16 @@ class UssService extends Service } /** - * 获取配置信息 - * @return $this - */ - private function getConfig(): self - { - $this->serviceName = config('dtapp.upyun.uss.service_name'); - $this->operatorName = config('dtapp.upyun.uss.operator_name'); - $this->operatorPassword = config('dtapp.upyun.uss.operator_password'); - return $this; - } - - /** - * 上传文件 * @param string $object * @param string $filePath - * @return bool + * @return array|bool * @throws Exception */ - public function upload(string $object, string $filePath): bool + public function upload(string $object, string $filePath) { - if (empty($this->serviceName) || empty($this->operatorName) || empty($this->operatorPassword)) { - $this->getConfig(); - } $serviceConfig = new Config($this->serviceName, $this->operatorName, $this->operatorPassword); $client = new Upyun($serviceConfig); $file = fopen($filePath, 'r'); - $client->write($object, $file); - return config('dtapp.upyun.uss.url', '') . $object; + return $client->write($object, $file); } }