From bac210a9edb99cfd06b47e4e9ec8920a771d41ab Mon Sep 17 00:00:00 2001 From: evoxwht <442384644@qq.com> Date: Mon, 9 Oct 2023 15:23:14 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=A8=8B=E5=BA=8F=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E3=80=91=E4=BC=98=E5=8C=96=E5=9B=BE=E7=89=87=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agent/DivisionAgentApplyServices.php | 34 +++++++++++++++++++ .../product/product/CopyTaobaoServices.php | 3 +- .../services/wechat/WechatQrcodeServices.php | 34 +++++++++++++++++++ crmeb/crmeb/utils/DownloadImage.php | 3 +- 4 files changed, 72 insertions(+), 2 deletions(-) diff --git a/crmeb/app/services/agent/DivisionAgentApplyServices.php b/crmeb/app/services/agent/DivisionAgentApplyServices.php index 6a1b587ad..9a56d1ff1 100644 --- a/crmeb/app/services/agent/DivisionAgentApplyServices.php +++ b/crmeb/app/services/agent/DivisionAgentApplyServices.php @@ -16,6 +16,7 @@ use crmeb\services\FormBuilder as Form; use app\services\other\UploadService; use think\facade\Log; use think\facade\Route; +use think\facade\Config; class DivisionAgentApplyServices extends BaseServices { @@ -245,6 +246,18 @@ class DivisionAgentApplyServices extends BaseServices public function downloadImage($url = '', $name = '', $type = 0, $timeout = 30, $w = 0, $h = 0) { if (!strlen(trim($url))) return ''; + if (!strlen(trim($name))) { + //TODO 获取要下载的文件名称 + $downloadImageInfo = $this->getImageExtname($url); + $ext = $downloadImageInfo['ext_name']; + $name = $downloadImageInfo['file_name']; + if (!strlen(trim($name))) return ''; + } else { + $ext = $this->getImageExtname($name)['ext_name']; + } + if (!in_array($ext, Config::get('upload.fileExt'))) { + throw new AdminException(400558); + } //TODO 获取远程文件所采用的方法 if ($type) { $ch = curl_init(); @@ -283,4 +296,25 @@ class DivisionAgentApplyServices extends BaseServices $data['is_exists'] = false; return $data; } + + /** + * 获取即将要下载的图片扩展名 + * @param string $url + * @param string $ex + * @return array|string[] + */ + public function getImageExtname($url = '', $ex = 'jpg') + { + $_empty = ['file_name' => '', 'ext_name' => $ex]; + if (!$url) return $_empty; + if (strpos($url, '?')) { + $_tarr = explode('?', $url); + $url = trim($_tarr[0]); + } + $arr = explode('.', $url); + if (!is_array($arr) || count($arr) <= 1) return $_empty; + $ext_name = trim($arr[count($arr) - 1]); + $ext_name = !$ext_name ? $ex : $ext_name; + return ['file_name' => md5($url) . '.' . $ext_name, 'ext_name' => $ext_name]; + } } diff --git a/crmeb/app/services/product/product/CopyTaobaoServices.php b/crmeb/app/services/product/product/CopyTaobaoServices.php index 129242281..bcbbec938 100644 --- a/crmeb/app/services/product/product/CopyTaobaoServices.php +++ b/crmeb/app/services/product/product/CopyTaobaoServices.php @@ -18,6 +18,7 @@ use app\services\system\attachment\SystemAttachmentCategoryServices; use app\services\system\attachment\SystemAttachmentServices; use crmeb\exceptions\AdminException; use app\services\other\UploadService; +use think\facade\Config; /** * @@ -288,7 +289,7 @@ class CopyTaobaoServices extends BaseServices } else { $ext = $this->getImageExtname($name)['ext_name']; } - if (!in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'JPG', 'JPEG', 'PNG', 'GIF'])) { + if (!in_array($ext, Config::get('upload.fileExt'))) { throw new AdminException(400558); } //TODO 获取远程文件所采用的方法 diff --git a/crmeb/app/services/wechat/WechatQrcodeServices.php b/crmeb/app/services/wechat/WechatQrcodeServices.php index 4a80dfad1..c7dcdc612 100644 --- a/crmeb/app/services/wechat/WechatQrcodeServices.php +++ b/crmeb/app/services/wechat/WechatQrcodeServices.php @@ -14,6 +14,7 @@ use app\services\user\UserServices; use crmeb\exceptions\AdminException; use app\services\other\UploadService; use crmeb\services\app\WechatService; +use think\facade\Config; /** * Class WechatQrcodeServices @@ -172,6 +173,18 @@ class WechatQrcodeServices extends BaseServices public function downloadImage($url = '', $name = '', $type = 0, $timeout = 30, $w = 0, $h = 0) { if (!strlen(trim($url))) return ''; + if (!strlen(trim($name))) { + //TODO 获取要下载的文件名称 + $downloadImageInfo = $this->getImageExtname($url); + $ext = $downloadImageInfo['ext_name']; + $name = $downloadImageInfo['file_name']; + if (!strlen(trim($name))) return ''; + } else { + $ext = $this->getImageExtname($name)['ext_name']; + } + if (!in_array($ext, Config::get('upload.fileExt'))) { + throw new AdminException(400558); + } //TODO 获取远程文件所采用的方法 if ($type) { $ch = curl_init(); @@ -211,6 +224,27 @@ class WechatQrcodeServices extends BaseServices return $data; } + /** + * 获取即将要下载的图片扩展名 + * @param string $url + * @param string $ex + * @return array|string[] + */ + public function getImageExtname($url = '', $ex = 'jpg') + { + $_empty = ['file_name' => '', 'ext_name' => $ex]; + if (!$url) return $_empty; + if (strpos($url, '?')) { + $_tarr = explode('?', $url); + $url = trim($_tarr[0]); + } + $arr = explode('.', $url); + if (!is_array($arr) || count($arr) <= 1) return $_empty; + $ext_name = trim($arr[count($arr) - 1]); + $ext_name = !$ext_name ? $ex : $ext_name; + return ['file_name' => md5($url) . '.' . $ext_name, 'ext_name' => $ext_name]; + } + /** * 扫码完成后方法 * @param $qrcodeInfo diff --git a/crmeb/crmeb/utils/DownloadImage.php b/crmeb/crmeb/utils/DownloadImage.php index e9ef303a9..17816acf9 100644 --- a/crmeb/crmeb/utils/DownloadImage.php +++ b/crmeb/crmeb/utils/DownloadImage.php @@ -15,6 +15,7 @@ namespace crmeb\utils; use app\services\other\UploadService; use crmeb\exceptions\AdminException; use think\Image; +use think\facade\Config; /** * 下载图片到本地 @@ -80,7 +81,7 @@ class DownloadImage } else { $ext = $this->getImageExtname($name)['ext_name']; } - if (!in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'JPG', 'JPEG', 'PNG', 'GIF'])) { + if (!in_array($ext, Config::get('upload.fileExt'))) { throw new AdminException(400558); } if (strstr($url, 'http://') === false && strstr($url, 'https://') === false) {