提交 32f4f331 编写于 作者: 李光春's avatar 李光春

- 优化服务

上级 0ec70f1f
## v6.0.127 / 2020-11-26
- 优化服务
## v6.0.127 / 2020-11-25 ## v6.0.127 / 2020-11-25
- 修复腾讯云存储 - 修复腾讯云存储
- 数组门面增加方法 - 数组门面增加方法
......
...@@ -25,7 +25,7 @@ use DtApp\ThinkLibrary\service\SystemService; ...@@ -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')) { if (!function_exists('get_ip_info')) {
/** /**
......
...@@ -77,33 +77,15 @@ class OssService extends Service ...@@ -77,33 +77,15 @@ class OssService extends Service
} }
/** /**
* 获取配置信息 * @param string $object
* @return $this * @param string $filePath
*/ * @return string|null
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
*/ */
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 { try {
$ossClient = new OssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint); $ossClient = new OssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint);
$ossClient->uploadFile($this->bucket, $object, $filePath); return $ossClient->uploadFile($this->bucket, $object, $filePath);
return config('dtapp.aliyun.oss.url', '') . $object;
} catch (OssException $e) { } catch (OssException $e) {
return $e->getMessage(); return $e->getMessage();
} }
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
namespace DtApp\ThinkLibrary\service\amap; namespace DtApp\ThinkLibrary\service\amap;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service; use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService; use DtApp\ThinkLibrary\service\curl\HttpService;
...@@ -50,38 +49,21 @@ class AmApService extends Service ...@@ -50,38 +49,21 @@ class AmApService extends Service
* @param string $key * @param string $key
* @return $this * @return $this
*/ */
public function key(string $key) public function key(string $key): self
{ {
$this->key = $key; $this->key = $key;
return $this; 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 * https://lbs.amap.com/api/webservice/guide/api/weatherinfo
* @param string $city * @param string $city
* @param string $extensions * @param string $extensions
* @return array|bool|mixed|string * @return array|bool|mixed|string
* @throws DtaException
*/ */
public function weather($city = "110101", $extensions = "base") 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([ $data = http_build_query([
"city" => $city, "city" => $city,
"extensions" => $extensions, "extensions" => $extensions,
...@@ -92,4 +74,42 @@ class AmApService extends Service ...@@ -92,4 +74,42 @@ class AmApService extends Service
->url("{$this->url}weather/weatherInfo?{$data}") ->url("{$this->url}weather/weatherInfo?{$data}")
->toArray(); ->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();
}
} }
...@@ -77,30 +77,13 @@ class BosService extends Service ...@@ -77,30 +77,13 @@ class BosService extends Service
} }
/** /**
* 获取配置信息 * @param string $object
* @return $this * @param string $filePath
*/ * @return mixed
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
* @throws Exception * @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 // 设置BosClient的Access Key ID、Secret Access Key和ENDPOINT
$BOS_TEST_CONFIG = array( $BOS_TEST_CONFIG = array(
'credentials' => array( 'credentials' => array(
...@@ -111,10 +94,6 @@ class BosService extends Service ...@@ -111,10 +94,6 @@ class BosService extends Service
); );
$client = new BosClient($BOS_TEST_CONFIG); $client = new BosClient($BOS_TEST_CONFIG);
// 从文件中直接上传Object // 从文件中直接上传Object
if (empty($this->bucket)) { return $client->putObjectFromFile($this->bucket, $object, $filePath);
$this->getConfig();
}
$client->putObjectFromFile($this->bucket, $object, $filePath);
return config('dtapp.baidu.bos.url', '') . $object;
} }
} }
...@@ -51,16 +51,6 @@ class LbsYunService extends Service ...@@ -51,16 +51,6 @@ class LbsYunService extends Service
return $this; 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 * http://lbsyun.baidu.com/index.php?title=webapi/weather
...@@ -72,9 +62,6 @@ class LbsYunService extends Service ...@@ -72,9 +62,6 @@ class LbsYunService extends Service
*/ */
public function weather($district_id = 110100, string $coordtype = "bd09ll", string $location = "") public function weather($district_id = 110100, string $coordtype = "bd09ll", string $location = "")
{ {
if (empty($this->ak)) {
$this->getConfig();
}
if (empty($this->ak)) { if (empty($this->ak)) {
throw new DtaException('请检查ak参数'); throw new DtaException('请检查ak参数');
} }
...@@ -103,9 +90,6 @@ class LbsYunService extends Service ...@@ -103,9 +90,6 @@ class LbsYunService extends Service
*/ */
public function weatherAbroad($district_id = 110100, string $coordtype = "bd09ll", string $location = "", string $language = "cn") public function weatherAbroad($district_id = 110100, string $coordtype = "bd09ll", string $location = "", string $language = "cn")
{ {
if (empty($this->ak)) {
$this->getConfig();
}
if (empty($this->ak)) { if (empty($this->ak)) {
throw new DtaException('请检查ak参数'); throw new DtaException('请检查ak参数');
} }
......
...@@ -76,45 +76,25 @@ class ObsService extends Service ...@@ -76,45 +76,25 @@ class ObsService extends Service
} }
/** /**
* 获取配置信息 * @param string $object
* @return $this * @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实例
$obsClient = new ObsClient([ $obsClient = new ObsClient([
'key' => $this->key, 'key' => $this->key,
'secret' => $this->secret, 'secret' => $this->secret,
'endpoint' => $this->endpoint 'endpoint' => $this->endpoint
]); ]);
if (empty($this->bucket)) {
$this->getConfig();
}
$resp = $obsClient->putObject([ $resp = $obsClient->putObject([
'Bucket' => $this->bucket, 'Bucket' => $this->bucket,
'Key' => $object, 'Key' => $object,
'SourceFile' => $filePath // localfile为待上传的本地文件路径,需要指定到具体的文件名 'SourceFile' => $filePath // localfile为待上传的本地文件路径,需要指定到具体的文件名
]); ]);
if (isset($resp['RequestId'])) { if (isset($resp['RequestId'])) {
return config('dtapp.huaweicloud.obs.url', '') . $object; return $resp;
} }
return false; return false;
......
...@@ -77,34 +77,26 @@ class Ks3Service extends Service ...@@ -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 $object
* @param string $filePath * @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)) { //是否使用VHOST
$this->getConfig(); 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"); require_once(__DIR__ . "/bin/Ks3Client.class.php");
$client = new Ks3Client($this->accessKeyID, $this->accessKeySecret, $this->endpoint); $client = new Ks3Client($this->accessKeyID, $this->accessKeySecret, $this->endpoint);
if (empty($this->bucket)) {
$this->getConfig();
}
$content = fopen($filePath, 'rb'); $content = fopen($filePath, 'rb');
$args = [ $args = [
"Bucket" => $this->bucket, "Bucket" => $this->bucket,
...@@ -126,8 +118,7 @@ class Ks3Service extends Service ...@@ -126,8 +118,7 @@ class Ks3Service extends Service
] ]
]; ];
try { try {
$client->putObjectByFile($args); return $client->putObjectByFile($args);
return config('dtapp.ksyun.ks3.url', '') . $object;
} catch (Ks3ServiceException $e) { } catch (Ks3ServiceException $e) {
return false; return false;
} }
......
...@@ -68,29 +68,13 @@ class KodoService extends Service ...@@ -68,29 +68,13 @@ class KodoService extends Service
} }
/** /**
* 获取配置信息 * @param string $object
* @return $this * @param string $filePath
*/ * @return bool|mixed
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
* @throws Exception * @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); $auth = new Auth($this->accessKey, $this->secretKey);
// 生成上传Token // 生成上传Token
...@@ -103,6 +87,7 @@ class KodoService extends Service ...@@ -103,6 +87,7 @@ class KodoService extends Service
return false; return false;
} }
return config('dtapp.qiniu.kodo.url', '') . $object; return $ret;
} }
} }
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
namespace DtApp\ThinkLibrary\service\tencent; namespace DtApp\ThinkLibrary\service\tencent;
use DtApp\ThinkLibrary\Service; use DtApp\ThinkLibrary\Service;
use Exception;
use Qcloud\Cos\Client; use Qcloud\Cos\Client;
/** /**
...@@ -77,30 +76,12 @@ class CosService extends Service ...@@ -77,30 +76,12 @@ class CosService extends Service
} }
/** /**
* 获取配置信息 * @param string $object
* @return $this * @param string $filePath
*/
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
* @return bool * @return bool
* @throws Exception
*/ */
public function upload(string $object, string $filePath): bool public function upload(string $object, string $filePath): bool
{ {
if (empty($this->secretId) || empty($this->secretKey) || empty($this->region)) {
$this->getConfig();
}
$cosClient = new Client([ $cosClient = new Client([
'region' => $this->region, 'region' => $this->region,
'schema' => 'https', 'schema' => 'https',
...@@ -111,14 +92,14 @@ class CosService extends Service ...@@ -111,14 +92,14 @@ class CosService extends Service
]); ]);
$key = $object; $key = $object;
$file = fopen($filePath, "rb"); $file = fopen($filePath, "rb");
if ($file && empty($this->bucket)) { if ($file) {
$this->getConfig(); return $cosClient->putObject([
$result = $cosClient->putObject([
'Bucket' => $this->bucket, 'Bucket' => $this->bucket,
'Key' => $key, 'Key' => $key,
'Body' => $file 'Body' => $file
]); ]);
} }
return config('dtapp.tencent.cos.url', '') . $object;
return false;
} }
} }
...@@ -68,33 +68,16 @@ class UssService extends Service ...@@ -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 $object
* @param string $filePath * @param string $filePath
* @return bool * @return array|bool
* @throws Exception * @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); $serviceConfig = new Config($this->serviceName, $this->operatorName, $this->operatorPassword);
$client = new Upyun($serviceConfig); $client = new Upyun($serviceConfig);
$file = fopen($filePath, 'r'); $file = fopen($filePath, 'r');
$client->write($object, $file); return $client->write($object, $file);
return config('dtapp.upyun.uss.url', '') . $object;
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册