CRMEB知识付费开源版 阿里云OSS返回资源链接是http的问题记录

期望得到返回的链接是https的,但却是http的,于是自己爬了代码:
crmeb\extend\Api\AliyunOss.php
upload()函数

 1     public function upload($fileName)
 2     {
 3         $fileHandle = request()->file($fileName);
 4         $key = $this->saveFileName($fileHandle->getRealPath(), $this->getExtension($fileHandle));
 5         try {
 6             if ($this->autoValidate) {
 7                 $fileHandle->validate($this->autoValidate);
 8                 $this->autoValidate = null;
 9             }
10             $uploadInfo = $this->init()->uploadFile($this->OssBucket, $key, $fileHandle->getRealPath());
11             if (!isset($uploadInfo['info']['url'])) {
12                 return self::setErrorInfo('Upload failure');
13             }
14             return [
15                 'url' => $uploadInfo['info']['url'],//这里返回的资源链接是http的
16                 'key' => $key
17             ];
18         } catch (\Throwable $e) {
19             return self::setErrorInfo($e);
20         }
21     }

 

这里返回的资源链接是http的,于是改了点代码:

 1     public function upload($fileName)
 2     {
 3         $fileHandle = request()->file($fileName);
 4         $key = $this->saveFileName($fileHandle->getRealPath(), $this->getExtension($fileHandle));
 5         try {
 6             if ($this->autoValidate) {
 7                 $fileHandle->validate($this->autoValidate);
 8                 $this->autoValidate = null;
 9             }
10             $uploadInfo = $this->init()->uploadFile($this->OssBucket, $key, $fileHandle->getRealPath());
11             if (!isset($uploadInfo['info']['url'])) {
12                 return self::setErrorInfo('Upload failure');
13             }
         /*******这里添加了几行-start*/
14 $arr = parse_url($uploadInfo['info']['url']); 15 if($arr['scheme'] == 'http'){ 16 $url = 'https://'.$arr['host'].$arr['path']; 17 }
         /**************end***********/
18 return [ 19 // 'url' => $uploadInfo['info']['url'], 20 'url' => $url, /*修改后的https资源链接赋给url*/ 21 'key' => $key 22 ]; 23 } catch (\Throwable $e) { 24 return self::setErrorInfo($e); 25 } 26 }

还没找到是不是有配置文件可以自定义返回http或https。先做记录,备查

posted @ 2022-09-24 22:35  chmo  阅读(233)  评论(0编辑  收藏  举报
123