作者 lyh

gx

@@ -36,9 +36,16 @@ class TencentCosService extends BaseService @@ -36,9 +36,16 @@ class TencentCosService extends BaseService
36 $this->config['bucket'] = $this->cos['bucket']; 36 $this->config['bucket'] = $this->cos['bucket'];
37 } 37 }
38 38
  39 + /**
  40 + * @remark :上传图片
  41 + * @name :uploadToCos
  42 + * @author :lyh
  43 + * @method :post
  44 + * @time :2023/7/19 14:47
  45 + */
39 public function uploadToCos($file,$path,$filename) 46 public function uploadToCos($file,$path,$filename)
40 { 47 {
41 - $objectKey = $path.'/',$filename; 48 + $objectKey = $path.'/'.$filename;
42 // 上传到腾讯云 COS 49 // 上传到腾讯云 COS
43 $httpClient = new Client(); 50 $httpClient = new Client();
44 $response = $httpClient->request('PUT', "https://{$this->config['bucket']}.cos.{$this->config['cosRegion']}.myqcloud.com/{$objectKey}", [ 51 $response = $httpClient->request('PUT', "https://{$this->config['bucket']}.cos.{$this->config['cosRegion']}.myqcloud.com/{$objectKey}", [
@@ -52,6 +59,13 @@ class TencentCosService extends BaseService @@ -52,6 +59,13 @@ class TencentCosService extends BaseService
52 return null; 59 return null;
53 } 60 }
54 61
  62 + /**
  63 + * @remark :签名
  64 + * @name :generateHeaders
  65 + * @author :lyh
  66 + * @method :post
  67 + * @time :2023/7/19 14:47
  68 + */
55 private function generateHeaders($secretId, $secretKey) 69 private function generateHeaders($secretId, $secretKey)
56 { 70 {
57 $keyTime = time() - 1 . ';' . (time() + 300); 71 $keyTime = time() - 1 . ';' . (time() + 300);