| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- // +----------------------------------------------------------------------
- // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: 萤火科技 <admin@yiovo.com>
- // +----------------------------------------------------------------------
- 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? $value : 'MP-WEIXIN';
- }
- 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 : 'https://'.$host . $uploadPath .'/' . ltrim($url, '/');
- }
- // $url = $url? preg_replace("/^(http):\/\//", '//', $url) : '';
- if(preg_match("/127.0|localhost/", $host) && $url){
- $url = preg_replace("/^\/\//", 'http://', $url);
- }
- return $url;
- }
- }
|