deploy: auto commit repo-root changes 2026-06-13 11:35:15

This commit is contained in:
hajimi
2026-06-13 11:35:15 +08:00
parent 50f0b6aff5
commit 93474019a4
3 changed files with 182 additions and 48 deletions
+6 -47
View File
@@ -11,6 +11,7 @@ use app\common\service\MTranServerService;
class AiService
{
private const LOTTERY_POST_IMAGE_TIMEOUT = 25;
// 生成类 AI 统一走 DeepSeekClient 的 OpenAI Responses 配置。
@@ -341,7 +342,7 @@ class AiService
if (!$image) {
return '';
}
return self::prepareGptImageUrl(FileService::getFileUrl($image));
return FileService::getFileUrl($image);
}, $images)));
if (empty($imageUrls)) {
@@ -366,6 +367,10 @@ class AiService
$options = self::gptModelOptions([
'max_tokens' => 2000,
'temperature' => 0.3,
'timeout' => self::LOTTERY_POST_IMAGE_TIMEOUT,
'reasoning_effort' => 'low',
'retry_times' => 0,
'retry_sleep_ms' => 0,
]);
$client = new DeepSeekClient();
@@ -380,52 +385,6 @@ class AiService
return $result;
}
protected static function prepareGptImageUrl(string $imageUrl): string
{
if (!preg_match('/^https?:\/\//i', $imageUrl)) {
return $imageUrl;
}
$dataUrl = self::downloadImageAsDataUrl($imageUrl);
return $dataUrl !== '' ? $dataUrl : $imageUrl;
}
protected static function downloadImageAsDataUrl(string $imageUrl): string
{
$ch = curl_init($imageUrl);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 25,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_USERAGENT => 'Mozilla/5.0 SportEraBot/1.0',
]);
$body = curl_exec($ch);
$httpCode = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
$contentType = (string) curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
curl_close($ch);
if ($httpCode !== 200 || !is_string($body) || $body === '' || strlen($body) > 8 * 1024 * 1024) {
return '';
}
$mime = strtolower(trim(explode(';', $contentType)[0] ?? ''));
if ($mime === '' || !str_starts_with($mime, 'image/')) {
$path = parse_url($imageUrl, PHP_URL_PATH) ?: '';
$ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
$mime = match ($ext) {
'png' => 'image/png',
'webp' => 'image/webp',
'gif' => 'image/gif',
default => 'image/jpeg',
};
}
return 'data:' . $mime . ';base64,' . base64_encode($body);
}
/**
* 保存分析结果
*/