45 lines
985 B
PHP
Executable File
45 lines
985 B
PHP
Executable File
<?php
|
|
|
|
namespace App\Helpers;
|
|
|
|
use function Hyperf\Config\config;
|
|
|
|
class AppHelper
|
|
{
|
|
public static function getImageBaseUrl(): string
|
|
{
|
|
return config('upload.qiniu.base_url');
|
|
}
|
|
|
|
public static function setImageUrl(string $imageUrl)
|
|
{
|
|
$imageUrl = self::extractImagePath($imageUrl);
|
|
return self::getImageBaseUrl() . $imageUrl;
|
|
}
|
|
|
|
public static function extractImagePath(string $url): string
|
|
{
|
|
// 解析URL
|
|
$parsedUrl = parse_url($url);
|
|
|
|
// 获取路径部分
|
|
$path = $parsedUrl['path'];
|
|
|
|
// 去除路径前的 "/"
|
|
return ltrim($path, '/');
|
|
}
|
|
|
|
public static function generateAid(): string
|
|
{
|
|
return strtr(uniqid(more_entropy: true), [
|
|
'.' => ''
|
|
]);
|
|
}
|
|
|
|
public static function getYear(string $title)
|
|
{
|
|
preg_match('/([0-9]+)/', $title, $y);
|
|
|
|
return $y[1] ?? date('Y');
|
|
}
|
|
} |