|
...
|
...
|
@@ -3,6 +3,7 @@ |
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :腾讯cos上传
|
|
...
|
...
|
@@ -47,22 +48,63 @@ class TencentCosService extends BaseService |
|
|
|
$httpVerb = 'PUT';
|
|
|
|
$date = gmdate('D, d M Y H:i:s \G\M\T');
|
|
|
|
//生成 KeyTime
|
|
|
|
$signTime = ( string )( time() - 60 ) . ';' . ( string )( strtotime( '+30 minutes' ) );
|
|
|
|
$keyTime = ( string )( time() - 60 ) . ';' . ( string )( strtotime( '+30 minutes' ) );
|
|
|
|
//生成 SignKey
|
|
|
|
$signKey = hash_hmac( 'sha1', $signTime, trim($this->config['secretKey']) );
|
|
|
|
$signKey = hash_hmac( 'sha1', $keyTime, trim($this->config['secretKey']) );
|
|
|
|
//生成 UrlParamList 和 HttpParameters
|
|
|
|
$filePath = $path.'/'.$fileName;
|
|
|
|
$stringToSign = "{$httpVerb}\n\n\n{$date}\n/{$this->config['bucket']}/{$filePath}";
|
|
|
|
$queryParameters = \request()->query();
|
|
|
|
$sortedKeys = collect($queryParameters)->keys()->sort()->all();
|
|
|
|
$urlParamList = "";
|
|
|
|
$httpParameters = "";
|
|
|
|
foreach ($sortedKeys as $key) {
|
|
|
|
$encodedKey = Str::lower(rawurlencode($key));
|
|
|
|
$value = isset($queryParameters[$key]) ? rawurlencode($queryParameters[$key]) : "";
|
|
|
|
$urlParamList .= $encodedKey . ";";
|
|
|
|
$httpParameters .= $encodedKey . "=" . $value . "&";
|
|
|
|
}
|
|
|
|
$urlParamList = rtrim($urlParamList, ";");
|
|
|
|
$httpParameters = rtrim($httpParameters, "&");
|
|
|
|
// 生成 HeaderList 和 HttpHeaders
|
|
|
|
$headers = \request()->headers->all();
|
|
|
|
$sortedKeys = collect($headers)->keys()->sort()->all();
|
|
|
|
$headerList = "";
|
|
|
|
$httpHeaders = "";
|
|
|
|
foreach ($sortedKeys as $key) {
|
|
|
|
$encodedKey = Str::lower(rawurlencode($key));
|
|
|
|
$value = rawurlencode($headers[$key][0]);
|
|
|
|
$headerList .= $encodedKey . ";";
|
|
|
|
$httpHeaders .= $encodedKey . "=" . $value . "&";
|
|
|
|
}
|
|
|
|
$headerList = rtrim($headerList, ";");
|
|
|
|
$httpHeaders = rtrim($httpHeaders, "&");
|
|
|
|
//生成HttpString
|
|
|
|
$httpMethod = Str::lower($httpVerb);
|
|
|
|
$uriPathname = $path.'/'.$fileName;
|
|
|
|
$httpString = $httpMethod . "\n" . $uriPathname . "\n" . $httpParameters . "\n" . $httpHeaders . "\n";
|
|
|
|
//生成 StringToSign
|
|
|
|
$sha1String = sha1($httpString);
|
|
|
|
$stringToSign = "sha1\n" . $keyTime . "\n" . $sha1String . "\n";
|
|
|
|
$sign = hash_hmac( 'sha1', $stringToSign, $signKey );
|
|
|
|
$authorization =
|
|
|
|
"q-sign-algorithm=sha1&q-ak={$this->config['secretId']}&q-sign-time={$signTime}&q-key-time={$signTime}&q-header-list=&q-url-param-list=&q-signature={$sign}";
|
|
|
|
$url = "https://{$this->config['bucket']}.cos.{$this->config['cosRegion']}.myqcloud.com{$filePath}";
|
|
|
|
"q-sign-algorithm=sha1&q-ak={$this->config['secretId']}&q-sign-time={$keyTime}&q-key-time={$keyTime}&q-header-list=&q-url-param-list=&q-signature={$sign}";
|
|
|
|
$url = "https://{$this->config['bucket']}.cos.{$this->config['cosRegion']}.myqcloud.com{$uriPathname}";
|
|
|
|
// 打开文件流
|
|
|
|
$filePathUrl = config('filesystems.disks.upload')['root'].$path.'/'.$fileName;
|
|
|
|
return $this->http_put($url,$contentType,$authorization,$date,$filePathUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Request $request
|
|
|
|
* @remark :生成$urlParamList + $httpParameters
|
|
|
|
* @name :ceshi
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/7/19 14:05
|
|
|
|
*/
|
|
|
|
public function queryParameters(Request $request){
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @remark :上传文件到第三方
|
|
|
|
* @name : (http_put
|
|
|
|
* @author :lyh
|
|
...
|
...
|
@@ -86,8 +128,6 @@ class TencentCosService extends BaseService |
|
|
|
curl_close($ch);
|
|
|
|
// 检查响应结果
|
|
|
|
if ($response) {
|
|
|
|
var_dump($response);
|
|
|
|
die();
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
...
|
...
|
|