buildHtml($records); // ========= 2. 保存HTML到临时文件 ========= $htmlPath = storage_path('app/lottery_temp.html'); file_put_contents($htmlPath, $html); // ========= 3. 输出图片路径 ========= $fileName = 'lottery_' . time() . '.png'; $outputPath = storage_path('app/public/lottery/' . $fileName); if (!is_dir(dirname($outputPath))) { mkdir(dirname($outputPath), 0755, true); } // ========= 4. 调用 wkhtmltoimage ========= // --quality 100 提高图片质量,可选 $cmd = sprintf( 'wkhtmltoimage --quality 100 %s %s', escapeshellarg($htmlPath), escapeshellarg($outputPath) ); exec($cmd, $output, $code); if ($code !== 0 || !file_exists($outputPath)) { throw new \Exception('图片生成失败,请检查是否已安装 wkhtmltoimage 并可在命令行执行'); } // ========= 5. 返回访问URL ========= return Storage::url('lottery/' . $fileName); } /** * 生成HTML内容 */ protected function buildHtml($records): string { $rows = ''; foreach ($records as $row) { $rows .= ''; $rows .= '' . htmlspecialchars($row['issue_no']) . '期'; $rows .= ''; foreach ($row['winning_numbers'] as $i => $num) { $color = match ($i) { 0 => '#FF8A8A', 1 => '#8AB8FF', 2 => '#FFDF80', default => '#000', }; $rows .= "{$num}"; if ($i < count($row['winning_numbers']) - 1) $rows .= ' + '; } $rows .= ' = ' . array_sum($row['winning_numbers']) . ''; $rows .= '' . $row['combo'] . ''; $rows .= ''.$row['extreme'].''; $rows .= ''.$row['tail'].''; $rows .= ''; } $time = now()->format('Y-m-d H:i:s'); return << 加拿大28开奖记录

加拿大28开奖记录

最近开奖记录
{$rows}
回合 结果 组合 极值 尾数
HTML; } }