// +---------------------------------------------------------------------- declare (strict_types = 1); // 应用公共函数库文件 /** * 获取当前访问的渠道(微信小程序、H5、APP等) * @return string|null */ function getPlatform() { static $value = null; // 从header中获取 channel empty($value) && $value = request()->header('platform'); // 调试模式下可通过param中获取 if (is_debug() && empty($value)) { $value = request()->param('platform'); } return $value; } if (!function_exists('getPreview')) { /** * 图片资源预览地址 * @param $url 原始地址 * @return null|string|string[] */ function getPreview($url){ if ($url) { $host = request()->header('host'); $fileConfig = config('filesystem.disks'); $uploadPath = (isset($fileConfig['public']) && $fileConfig['public']['url'])? $fileConfig['public']['url']:'/uploads'; $url = preg_match("/^(https|http):\/\//", trim($url,'//')) ? $url : '//'.$host . $uploadPath .'/' . ltrim($url, '/'); } $url = $url? preg_replace("/^(https|http):\/\//", '//', $url) : ''; if(preg_match("/127.0|localhost/", $host) && $url){ $url = preg_replace("/^\/\//", 'http://', $url); } return $url; } }