作者 lyh

gx

@@ -43,7 +43,7 @@ class TencentCosService extends BaseService @@ -43,7 +43,7 @@ class TencentCosService extends BaseService
43 public function upload_image($path,$fileName){ 43 public function upload_image($path,$fileName){
44 // 构建请求URL 44 // 构建请求URL
45 $pathname = '/'.$this->config['bucket'].$path.'/'.$fileName; 45 $pathname = '/'.$this->config['bucket'].$path.'/'.$fileName;
46 - $signature = $this->generateSignature(); 46 + $signature = $this->generateSignature($path.'/'.$fileName);
47 $url = 'https://'.$this->config['bucket'].'.cos.'.$this->config['cosRegion'].'.myqcloud.com'.$pathname.'?sign='.$signature; 47 $url = 'https://'.$this->config['bucket'].'.cos.'.$this->config['cosRegion'].'.myqcloud.com'.$pathname.'?sign='.$signature;
48 // 打开文件流 48 // 打开文件流
49 $url_path = config('filesystems.disks.upload')['root'].$path.'/'.$fileName; 49 $url_path = config('filesystems.disks.upload')['root'].$path.'/'.$fileName;
@@ -83,11 +83,11 @@ class TencentCosService extends BaseService @@ -83,11 +83,11 @@ class TencentCosService extends BaseService
83 * @method :post 83 * @method :post
84 * @time :2023/7/18 17:10 84 * @time :2023/7/18 17:10
85 */ 85 */
86 - public function generateSignature() { 86 + public function generateSignature($path) {
87 $signTime = time(); 87 $signTime = time();
88 $expiredTime = time() + 3600; 88 $expiredTime = time() + 3600;
89 - $plainText = 'a='.$this->config['appId'].'&b='.$this->config['bucket'].  
90 - '&k='.$this->config['secretId'].'&e='.$expiredTime.'&t='.$signTime.'&r='.rand().'&f=';; 89 + $plainText =
  90 + 'a='.$this->config['appId'].'&b='.$this->config['bucket']. '&k='.$this->config['secretId'].'&e='.$expiredTime.'&t='.$signTime.'&r='.rand().'&f='.$path;
91 $sign = base64_encode(hash_hmac('SHA1', $plainText, $this->config['secretKey'], true).$plainText); 91 $sign = base64_encode(hash_hmac('SHA1', $plainText, $this->config['secretKey'], true).$plainText);
92 return $sign; 92 return $sign;
93 } 93 }