修改云存储

This commit is contained in:
JaguarJack 2019-01-30 17:14:45 +08:00
parent 56362ae33f
commit b821d02b1a
7 changed files with 46 additions and 25 deletions

View File

@ -14,15 +14,15 @@ return [
// 又拍驱动 // 又拍驱动
'uppay' => \thinking\icloud\cloud\UpYunCloud::class, 'uppay' => \thinking\icloud\cloud\UpYunCloud::class,
// 七牛驱动认证 // 七牛驱动认证
'qinniuAuth' => \thinking\icloud\auth\QiniuAuth::class, 'qiniuAuth' => \thinking\icloud\auth\QiNiuAuth::class,
// 又拍驱动认证 // 又拍驱动认证
'uppay' => \thinking\icloud\auth\UpYunAuth::class, 'uppayAuth' => \thinking\icloud\auth\UpYunAuth::class,
], ],
/* 七牛配置信息 */ /* 七牛配置信息 */
'qiniu' => [ 'qiniu' => [
'app_key' => '', 'app_key' => 'dw1jkmtSNjxyPkMdyBfVeaWzCAOiMSOTk35adV8W',
'app_secret' => '', 'app_secret' => '_KfsmnV8d-rlYtABD27xF7y-ZNxblvdk9_VVZ67g',
//上传策略字段,上传凭证校验使用 //上传策略字段,上传凭证校验使用
'policyFields' => [ 'policyFields' => [
@ -56,11 +56,14 @@ return [
'buckets' => [''], 'buckets' => [''],
], ],
'oss' => [
'access_key' => '',
'access_secret' => '',
],
//api接口 //api接口
'host' => [ 'host' => [
//七牛host //七牛host
'rs' => 'rs.qiniu.com', 'rs' => 'rs.qbox.me',
'api' => 'api.qiniu.com', 'api' => 'api.qiniu.com',
'uc' => 'uc.qbox.me', 'uc' => 'uc.qbox.me',
'rsf' => 'rsf.qbox.me', 'rsf' => 'rsf.qbox.me',

View File

@ -7,9 +7,10 @@
*/ */
namespace thinking\icloud; namespace thinking\icloud;
use thinking\icloud\auth\AuthFactory; use thinking\icloud\factory\AuthFactory;
use thinking\icloud\Utility; use thinking\icloud\httpclient\Client;
use thinking\icloud\exception\NotFoundException; use thinking\icloud\exception\NotFoundException;
use thinking\icloud\Utility;
class AbstractCloud class AbstractCloud
{ {
@ -40,7 +41,6 @@ class AbstractCloud
if (!array_key_exists($host, $this->host)) { if (!array_key_exists($host, $this->host)) {
throw NotFoundException::NotFoundKey("Host Key '{$host}' Not Found In Config File"); throw NotFoundException::NotFoundKey("Host Key '{$host}' Not Found In Config File");
} }
return self::getHost($host, $isHttps); return self::getHost($host, $isHttps);
} }
@ -61,16 +61,14 @@ class AbstractCloud
{ {
// TODO: Implement __call() method. // TODO: Implement __call() method.
$client = new Client; $client = new Client;
$client->url = $arguments[0]; $client->uri = $arguments[0];
$this->method = $name; $client->method = $name;
if (isset($arguments[1]['headers']['Authorization'])) { if (isset($arguments[1]['headers']['Authorization'])) {
$client->params = $arguments[1]; $client->params = $arguments[1];
} else { } else {
$headers = AuthFactory::authorization($arguments[0], $name); $headers = AuthFactory::authorization($arguments[0], $name);
$client->params = array_merge_recursive(['headers' => $headers], $arguments[1]); $client->params = array_merge_recursive(['headers' => $headers], $arguments[1] ?? []);
} }
return $client->send(); return $client->send();
} }

View File

@ -32,7 +32,7 @@ trait Utility
*/ */
public static function getHost(string $host = 'rs', bool $isHttps = false) public static function getHost(string $host = 'rs', bool $isHttps = false)
{ {
return $isHttps ? 'https://' : 'http://' . config('icloud.host.'. strtolower($host)); return $isHttps ? 'https://' : 'http://' . config('cloud.host.'. strtolower($host));
} }
/** /**

View File

@ -0,0 +1,17 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/1/30
* Time: 16:32
*/
namespace thinking\icloud\auth;
use thinking\icloud\Utility;
final class OssAuth
{
use Utility;
}

View File

@ -9,7 +9,7 @@ namespace thinking\icloud\auth;
use thinking\icloud\Utility; use thinking\icloud\Utility;
final class QiniuAuth final class QiNiuAuth
{ {
use Utility; use Utility;
@ -37,9 +37,8 @@ final class QiniuAuth
*/ */
public static function getAccessToken(string $urlString, string $body, string $contentType = '') public static function getAccessToken(string $urlString, string $body, string $contentType = '')
{ {
$appKey = config('cloud.qiniu.appKey'); $appKey = config('cloud.qiniu.app_key');
$appSecret = config('cloud.qiniu.appSecret'); $appSecret = config('cloud.qiniu.app_secret');
$url = parse_url($urlString); $url = parse_url($urlString);
$data = ''; $data = '';
if (array_key_exists('path', $url)) { if (array_key_exists('path', $url)) {
@ -76,8 +75,8 @@ final class QiniuAuth
string $policy = '', string $policy = '',
bool $strictPolicy = true bool $strictPolicy = true
){ ){
$appKey = config('cloud.qiniu.appKey'); $appKey = config('cloud.qiniu.app_key');
$appSecret = config('cloud.qiniu.appSecret'); $appSecret = config('cloud.qiniu.app_secret');
$scope = $key ? sprintf('%s:%s', $bucket, $key) : $bucket; $scope = $key ? sprintf('%s:%s', $bucket, $key) : $bucket;
$deadline = time() + $expires; $deadline = time() + $expires;
@ -120,8 +119,8 @@ final class QiniuAuth
*/ */
public static function dowmloadToken(string $uri, int $expires = 3600) public static function dowmloadToken(string $uri, int $expires = 3600)
{ {
$appSecret = config('cloud.qiniu.appSecret'); $appSecret = config('cloud.qiniu.app_secret');
$appKey = config('cloud.qiniu.appKey'); $appKey = config('cloud.qiniu.app_key');
$uri = sprintf('%s?e=%s', $uri, time() + $expires); $uri = sprintf('%s?e=%s', $uri, time() + $expires);

View File

@ -20,9 +20,7 @@ class AuthFactory
public static function create(string $name, ...$argument) public static function create(string $name, ...$argument)
{ {
$defaultDriver = config('cloud.driver.default'); $defaultDriver = config('cloud.driver.default');
$auth = config('cloud.driver.' . $defaultDriver . 'Auth'); $auth = config('cloud.driver.' . $defaultDriver . 'Auth');
return $auth::$name(...$argument); return $auth::$name(...$argument);
} }

View File

@ -11,7 +11,13 @@ use GuzzleHttp\Client as HttpClient;
class Client implements \ArrayAccess class Client implements \ArrayAccess
{ {
protected $params = []; protected $params = [];
protected $client = null; protected $client = null;
protected $method = null;
protected $uri = null;
/** /**
* 发送数据 * 发送数据
* *