作者 lyh

gx

... ... @@ -2,6 +2,8 @@
namespace App\Services;
use Illuminate\Http\Request;
/**
* @remark :腾讯cos上传
* @class :TencentCosService.php
... ... @@ -41,19 +43,21 @@ class TencentCosService extends BaseService
* @time :2023/7/18 16:56
*/
public function upload_image($path,$fileName,$image_type){
// 构建请求URL
$httpVerb = 'PUT';
$contentMd5 = '';
$contentType = 'image/'.$image_type;
date_default_timezone_set('Asia/Shanghai');
$date = date('D, d M Y H:i:s \G\M\T');
$time = time();
$expiredTime = time() + 3600000;
$date = gmdate('D, d M Y H:i:s \G\M\T');
//生成 KeyTime
$signTime = ( string )( time() - 60 ) . ';' . ( string )( strtotime( '+30 minutes' ) );
//生成 SignKey
$signKey = hash_hmac( 'sha1', $signTime, trim($this->config['secretKey']) );
//生成 UrlParamList 和 HttpParameters
$filePath = $path.'/'.$fileName;
$stringToSign = "{$httpVerb}\n{$contentMd5}\n{$contentType}\n{$date}\n/{$this->config['bucket']}/{$filePath}";
$sign = base64_encode(hash_hmac('sha1', $stringToSign, $this->config['secretKey'], true));
$stringToSign = "{$httpVerb}\n\n\n{$date}\n/{$this->config['bucket']}/{$filePath}";
$sign = hash_hmac( 'sha1', $stringToSign, $signKey );
var_dump($sign);
die();
$authorization =
"q-sign-algorithm=sha1&q-ak={$this->config['secretId']}&q-sign-time={$time};{$expiredTime}&q-key-time={$time};{$expiredTime}&q-header-list=&q-url-param-list=&q-signature={$sign}";
"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}";
// 打开文件流
$filePathUrl = config('filesystems.disks.upload')['root'].$path.'/'.$fileName;
... ...