正在显示
1 个修改的文件
包含
7 行增加
和
7 行删除
| @@ -43,8 +43,8 @@ class TencentCosService extends BaseService | @@ -43,8 +43,8 @@ class TencentCosService extends BaseService | ||
| 43 | public function upload_image($path,$fileName){ | 43 | public function upload_image($path,$fileName){ |
| 44 | // 构建请求URL | 44 | // 构建请求URL |
| 45 | $expiredTime = time() + 3600; | 45 | $expiredTime = time() + 3600; |
| 46 | - $pathname = '/'.$this->config['bucket'].'/'.$fileName; | ||
| 47 | - $signature = $this->generateSignature($this->config['secretKey'], $pathname, $path ,$expiredTime); | 46 | + $pathname = '/'.$this->config['bucket'].$path.'/'.$fileName; |
| 47 | + $signature = $this->generateSignature(); | ||
| 48 | $url = 'https://'.$this->config['bucket'].'.cos.'.$this->config['cosRegion'].'.myqcloud.com'.$pathname.'?sign='.$signature; | 48 | $url = 'https://'.$this->config['bucket'].'.cos.'.$this->config['cosRegion'].'.myqcloud.com'.$pathname.'?sign='.$signature; |
| 49 | // 打开文件流 | 49 | // 打开文件流 |
| 50 | $url_path = config('filesystems.disks.upload')['root'].$path.'/'.$fileName; | 50 | $url_path = config('filesystems.disks.upload')['root'].$path.'/'.$fileName; |
| @@ -84,12 +84,12 @@ class TencentCosService extends BaseService | @@ -84,12 +84,12 @@ class TencentCosService extends BaseService | ||
| 84 | * @method :post | 84 | * @method :post |
| 85 | * @time :2023/7/18 17:10 | 85 | * @time :2023/7/18 17:10 |
| 86 | */ | 86 | */ |
| 87 | - public function generateSignature($secretKey, $pathname, $path ,$expiredTime) { | 87 | + public function generateSignature() { |
| 88 | $signTime = time(); | 88 | $signTime = time(); |
| 89 | - $plainText = "a=".$this->config['secretId']."&k=".$secretKey."&e=".$expiredTime."&t=".$signTime."&r=".$pathname."&f=".$path; | ||
| 90 | - $bin = hash_hmac("SHA1", $plainText, $secretKey, true); | ||
| 91 | - $bin = $bin . $plainText; | ||
| 92 | - $sign = base64_encode($bin); | 89 | + $expiredTime = time() + 3600; |
| 90 | + $plainText = 'a='.$this->config['appId'].'&b='.$this->config['bucket']. | ||
| 91 | + '&k='.$this->config['secretId'].'&e='.$expiredTime.'&t='.$signTime.'&r='.rand().'&f=';; | ||
| 92 | + $sign = base64_encode(hash_hmac('SHA1', $plainText, $this->config['secretKey'], true).$plainText); | ||
| 93 | return $sign; | 93 | return $sign; |
| 94 | } | 94 | } |
| 95 | } | 95 | } |
-
请 注册 或 登录 后发表评论