Skip to content

Commit 32f4f33

Browse files
committed
- 优化服务
1 parent 0ec70f1 commit 32f4f33

File tree

11 files changed

+88
-200
lines changed

11 files changed

+88
-200
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v6.0.127 / 2020-11-26
2+
- 优化服务
3+
14
## v6.0.127 / 2020-11-25
25
- 修复腾讯云存储
36
- 数组门面增加方法

src/common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/**
2626
* 定义当前版本
2727
*/
28-
const VERSION = '6.0.127';
28+
const VERSION = '6.0.128';
2929

3030
if (!function_exists('get_ip_info')) {
3131
/**

src/service/aliyun/OssService.php

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,33 +77,15 @@ public function bucket(string $bucket): self
7777
}
7878

7979
/**
80-
* 获取配置信息
81-
* @return $this
82-
*/
83-
private function getConfig(): self
84-
{
85-
$this->accessKeyId = config('dtapp.aliyun.oss.access_key_id');
86-
$this->accessKeySecret = config('dtapp.aliyun.oss.access_key_secret');
87-
$this->endpoint = config('dtapp.aliyun.oss.endpoint');
88-
$this->bucket = config('dtapp.aliyun.oss.bucket');
89-
return $this;
90-
}
91-
92-
/**
93-
* 上传文件
94-
* @param $object
95-
* @param $filePath
96-
* @return bool|string
80+
* @param string $object
81+
* @param string $filePath
82+
* @return string|null
9783
*/
98-
public function upload(string $object, string $filePath)
84+
public function upload(string $object, string $filePath): ?string
9985
{
100-
if (empty($this->accessKeySecret) || empty($this->accessKeySecret) || empty($this->endpoint) || empty($this->bucket)) {
101-
$this->getConfig();
102-
}
10386
try {
10487
$ossClient = new OssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint);
105-
$ossClient->uploadFile($this->bucket, $object, $filePath);
106-
return config('dtapp.aliyun.oss.url', '') . $object;
88+
return $ossClient->uploadFile($this->bucket, $object, $filePath);
10789
} catch (OssException $e) {
10890
return $e->getMessage();
10991
}

src/service/amap/AmApService.php

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
namespace DtApp\ThinkLibrary\service\amap;
2121

22-
use DtApp\ThinkLibrary\exception\DtaException;
2322
use DtApp\ThinkLibrary\Service;
2423
use DtApp\ThinkLibrary\service\curl\HttpService;
2524

@@ -50,38 +49,21 @@ class AmApService extends Service
5049
* @param string $key
5150
* @return $this
5251
*/
53-
public function key(string $key)
52+
public function key(string $key): self
5453
{
5554
$this->key = $key;
5655
return $this;
5756
}
5857

59-
/**
60-
* 获取配置信息
61-
* @return $this
62-
*/
63-
private function getConfig(): self
64-
{
65-
$this->key = config('dtapp.amap.key');
66-
return $this;
67-
}
68-
6958
/**
7059
* 天气查询
7160
* https://lbs.amap.com/api/webservice/guide/api/weatherinfo
7261
* @param string $city
7362
* @param string $extensions
7463
* @return array|bool|mixed|string
75-
* @throws DtaException
7664
*/
7765
public function weather($city = "110101", $extensions = "base")
7866
{
79-
if (empty($this->key)) {
80-
$this->getConfig();
81-
}
82-
if (empty($this->key)) {
83-
throw new DtaException('请检查key参数');
84-
}
8567
$data = http_build_query([
8668
"city" => $city,
8769
"extensions" => $extensions,
@@ -92,4 +74,42 @@ public function weather($city = "110101", $extensions = "base")
9274
->url("{$this->url}weather/weatherInfo?{$data}")
9375
->toArray();
9476
}
77+
78+
/**
79+
* 地理编码
80+
* https://lbs.amap.com/api/webservice/guide/api/georegeo#geo
81+
* @param $address
82+
* @param string $city
83+
* @return array|bool|mixed|string
84+
*/
85+
public function gCoderGeo($address, $city = '')
86+
{
87+
$data = http_build_query([
88+
"city" => $city,
89+
"address" => $address,
90+
"key" => $this->key,
91+
"output" => $this->output,
92+
]);
93+
return HttpService::instance()
94+
->url("{$this->url}geocode/geo?{$data}")
95+
->toArray();
96+
}
97+
98+
/**
99+
* 逆地理编码
100+
* https://lbs.amap.com/api/webservice/guide/api/georegeo#regeo
101+
* @param $location
102+
* @return array|bool|mixed|string
103+
*/
104+
public function gCoderReGeo($location)
105+
{
106+
$data = http_build_query([
107+
"location" => $location,
108+
"key" => $this->key,
109+
"output" => $this->output,
110+
]);
111+
return HttpService::instance()
112+
->url("{$this->url}geocode/regeo?{$data}")
113+
->toArray();
114+
}
95115
}

src/service/baidu/BosService.php

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,30 +77,13 @@ public function bucket(string $bucket)
7777
}
7878

7979
/**
80-
* 获取配置信息
81-
* @return $this
82-
*/
83-
private function getConfig(): self
84-
{
85-
$this->accessKeyId = config('dtapp.baidu.bos.access_key_id');
86-
$this->secretAccessKey = config('dtapp.baidu.bos.secret_access_key');
87-
$this->endpoint = config('dtapp.baidu.bos.endpoint');
88-
$this->bucket = config('dtapp.baidu.bos.bucket');
89-
return $this;
90-
}
91-
92-
/**
93-
* 上传文件
94-
* @param $object
95-
* @param $filePath
96-
* @return bool
80+
* @param string $object
81+
* @param string $filePath
82+
* @return mixed
9783
* @throws Exception
9884
*/
99-
public function upload(string $object, string $filePath): bool
85+
public function upload(string $object, string $filePath)
10086
{
101-
if (empty($this->accessKeyId) || empty($this->secretAccessKey) || empty($this->endpoint)) {
102-
$this->getConfig();
103-
}
10487
// 设置BosClient的Access Key ID、Secret Access Key和ENDPOINT
10588
$BOS_TEST_CONFIG = array(
10689
'credentials' => array(
@@ -111,10 +94,6 @@ public function upload(string $object, string $filePath): bool
11194
);
11295
$client = new BosClient($BOS_TEST_CONFIG);
11396
// 从文件中直接上传Object
114-
if (empty($this->bucket)) {
115-
$this->getConfig();
116-
}
117-
$client->putObjectFromFile($this->bucket, $object, $filePath);
118-
return config('dtapp.baidu.bos.url', '') . $object;
97+
return $client->putObjectFromFile($this->bucket, $object, $filePath);
11998
}
12099
}

src/service/baidu/LbsYunService.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,6 @@ public function ak(string $ak): self
5151
return $this;
5252
}
5353

54-
/**
55-
* 获取配置信息
56-
* @return $this
57-
*/
58-
private function getConfig(): self
59-
{
60-
$this->ak = config('dtapp.baidu.lbs.ak');
61-
return $this;
62-
}
63-
6454
/**
6555
* 国内天气查询
6656
* http://lbsyun.baidu.com/index.php?title=webapi/weather
@@ -72,9 +62,6 @@ private function getConfig(): self
7262
*/
7363
public function weather($district_id = 110100, string $coordtype = "bd09ll", string $location = "")
7464
{
75-
if (empty($this->ak)) {
76-
$this->getConfig();
77-
}
7865
if (empty($this->ak)) {
7966
throw new DtaException('请检查ak参数');
8067
}
@@ -103,9 +90,6 @@ public function weather($district_id = 110100, string $coordtype = "bd09ll", str
10390
*/
10491
public function weatherAbroad($district_id = 110100, string $coordtype = "bd09ll", string $location = "", string $language = "cn")
10592
{
106-
if (empty($this->ak)) {
107-
$this->getConfig();
108-
}
10993
if (empty($this->ak)) {
11094
throw new DtaException('请检查ak参数');
11195
}

src/service/huaweicloud/ObsService.php

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,45 +76,25 @@ public function bucket(string $bucket): self
7676
}
7777

7878
/**
79-
* 获取配置信息
80-
* @return $this
79+
* @param string $object
80+
* @param string $filePath
81+
* @return bool|\Obs\Internal\Common\Model
8182
*/
82-
private function getConfig(): self
83+
public function upload(string $object, string $filePath)
8384
{
84-
$this->key = config('dtapp.huaweicloud.obs.key');
85-
$this->secret = config('dtapp.huaweicloud.obs.secret');
86-
$this->endpoint = config('dtapp.huaweicloud.obs.endpoint');
87-
$this->bucket = config('dtapp.huaweicloud.obs.bucket');
88-
return $this;
89-
}
90-
91-
/**
92-
* 上传到华为云
93-
* @param $object
94-
* @param $filePath
95-
* @return bool
96-
*/
97-
public function upload(string $object, string $filePath): bool
98-
{
99-
if (empty($this->key) || empty($this->secret) || empty($this->endpoint)) {
100-
$this->getConfig();
101-
}
10285
// 创建ObsClient实例
10386
$obsClient = new ObsClient([
10487
'key' => $this->key,
10588
'secret' => $this->secret,
10689
'endpoint' => $this->endpoint
10790
]);
108-
if (empty($this->bucket)) {
109-
$this->getConfig();
110-
}
11191
$resp = $obsClient->putObject([
11292
'Bucket' => $this->bucket,
11393
'Key' => $object,
11494
'SourceFile' => $filePath // localfile为待上传的本地文件路径,需要指定到具体的文件名
11595
]);
11696
if (isset($resp['RequestId'])) {
117-
return config('dtapp.huaweicloud.obs.url', '') . $object;
97+
return $resp;
11898
}
11999

120100
return false;

src/service/ksyun/Ks3Service.php

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,34 +77,26 @@ public function bucket(string $bucket): self
7777
}
7878

7979
/**
80-
* 获取配置信息
81-
* @return $this
82-
*/
83-
private function getConfig(): self
84-
{
85-
$this->accessKeyID = config('dtapp.ksyun.ks3.access_key_iD');
86-
$this->accessKeySecret = config('dtapp.ksyun.ks3.access_key_secret');
87-
$this->endpoint = config('dtapp.ksyun.ks3.endpoint');
88-
$this->bucket = config('dtapp.ksyun.ks3.bucket');
89-
return $this;
90-
}
91-
92-
/**
93-
* 上传文件
9480
* @param string $object
9581
* @param string $filePath
96-
* @return bool|string
82+
* @return bool
9783
*/
98-
public function upload(string $object, string $filePath)
84+
public function upload(string $object, string $filePath): ?bool
9985
{
100-
if (empty($this->accessKeyID) || empty($this->accessKeySecret) || empty($this->endpoint)) {
101-
$this->getConfig();
102-
}
86+
//是否使用VHOST
87+
define("KS3_API_VHOST", FALSE);
88+
//是否开启日志(写入日志文件)
89+
define("KS3_API_LOG", FALSE);
90+
//是否显示日志(直接输出日志)
91+
define("KS3_API_DISPLAY_LOG", FALSE);
92+
//定义日志目录(默认是该项目log下)
93+
define("KS3_API_LOG_PATH", "");
94+
//是否使用HTTPS
95+
define("KS3_API_USE_HTTPS", FALSE);
96+
//是否开启curl debug模式
97+
define("KS3_API_DEBUG_MODE", FALSE);
10398
require_once(__DIR__ . "/bin/Ks3Client.class.php");
10499
$client = new Ks3Client($this->accessKeyID, $this->accessKeySecret, $this->endpoint);
105-
if (empty($this->bucket)) {
106-
$this->getConfig();
107-
}
108100
$content = fopen($filePath, 'rb');
109101
$args = [
110102
"Bucket" => $this->bucket,
@@ -126,8 +118,7 @@ public function upload(string $object, string $filePath)
126118
]
127119
];
128120
try {
129-
$client->putObjectByFile($args);
130-
return config('dtapp.ksyun.ks3.url', '') . $object;
121+
return $client->putObjectByFile($args);
131122
} catch (Ks3ServiceException $e) {
132123
return false;
133124
}

src/service/qiniu/KodoService.php

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,29 +68,13 @@ public function bucket(string $bucket): self
6868
}
6969

7070
/**
71-
* 获取配置信息
72-
* @return $this
73-
*/
74-
private function getConfig(): self
75-
{
76-
$this->accessKey = config('dtapp.qiniu.kodo.access_key');
77-
$this->secretKey = config('dtapp.qiniu.kodo.secret_key');
78-
$this->bucket = config('dtapp.qiniu.kodo.bucket');
79-
return $this;
80-
}
81-
82-
/**
83-
* 上传文件
84-
* @param $object
85-
* @param $filePath
86-
* @return bool
71+
* @param string $object
72+
* @param string $filePath
73+
* @return bool|mixed
8774
* @throws Exception
8875
*/
89-
public function upload(string $object, string $filePath): bool
76+
public function upload(string $object, string $filePath)
9077
{
91-
if (empty($this->accessKey) || empty($this->secretKey) || empty($this->bucket)) {
92-
$this->getConfig();
93-
}
9478
// 初始化签权对象
9579
$auth = new Auth($this->accessKey, $this->secretKey);
9680
// 生成上传Token
@@ -103,6 +87,7 @@ public function upload(string $object, string $filePath): bool
10387
return false;
10488
}
10589

106-
return config('dtapp.qiniu.kodo.url', '') . $object;
90+
return $ret;
91+
10792
}
10893
}

0 commit comments

Comments
 (0)