|
|
@@ -0,0 +1,161 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Services;
|
|
|
+
|
|
|
+use Illuminate\Support\Facades\Storage;
|
|
|
+
|
|
|
+class LotteryImageService
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 生成开奖记录图片
|
|
|
+ * @param array $records 开奖记录数组
|
|
|
+ * @return string 图片的访问URL
|
|
|
+ */
|
|
|
+ public function generate(array $records): string
|
|
|
+ {
|
|
|
+ // ========= 1. 生成HTML内容 =========
|
|
|
+ $html = $this->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. 调用Chromium截图 =========
|
|
|
+ $cmd = sprintf(
|
|
|
+ 'chromium --headless --disable-gpu --screenshot=%s --window-size=1200,2000 file://%s',
|
|
|
+ escapeshellarg($outputPath),
|
|
|
+ escapeshellarg($htmlPath)
|
|
|
+ );
|
|
|
+ exec($cmd, $output, $code);
|
|
|
+
|
|
|
+ if ($code !== 0) {
|
|
|
+ throw new \Exception('图片生成失败,请检查是否安装chromium命令');
|
|
|
+ }
|
|
|
+
|
|
|
+ // ========= 5. 返回访问URL =========
|
|
|
+ return Storage::url('lottery/' . $fileName);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成HTML内容
|
|
|
+ */
|
|
|
+ protected function buildHtml(array $records): string
|
|
|
+ {
|
|
|
+ $rows = '';
|
|
|
+ foreach ($records as $row) {
|
|
|
+ $rows .= '<tr>';
|
|
|
+ $rows .= '<td>' . htmlspecialchars($row['period']) . '</td>';
|
|
|
+ $rows .= '<td>';
|
|
|
+ foreach ($row['numbers'] as $i => $num) {
|
|
|
+ $color = match ($i) {
|
|
|
+ 0 => '#FF8A8A',
|
|
|
+ 1 => '#8AB8FF',
|
|
|
+ 2 => '#FFE699',
|
|
|
+ default => '#000',
|
|
|
+ };
|
|
|
+ $rows .= "<span style='color: {$color};'>{$num}</span>";
|
|
|
+ if ($i < count($row['numbers']) - 1) $rows .= ' + ';
|
|
|
+ }
|
|
|
+ $rows .= ' = ' . $row['sum'] . '</td>';
|
|
|
+ $rows .= '<td>' . $row['combo'] . '</td>';
|
|
|
+ $rows .= '<td>' . $row['extreme'] . '</td>';
|
|
|
+ $rows .= '<td>' . $row['tail'] . '</td>';
|
|
|
+ $rows .= '</tr>';
|
|
|
+ }
|
|
|
+
|
|
|
+ $time = now()->format('Y-m-d H:i:s');
|
|
|
+
|
|
|
+ return <<<HTML
|
|
|
+<!DOCTYPE html>
|
|
|
+<html>
|
|
|
+<head>
|
|
|
+<meta charset="UTF-8">
|
|
|
+<title>加拿大28开奖记录</title>
|
|
|
+<style>
|
|
|
+body {
|
|
|
+ font-family: "Microsoft YaHei", Arial, sans-serif;
|
|
|
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
|
+ margin: 0;
|
|
|
+ padding: 20px;
|
|
|
+ min-height: 100vh;
|
|
|
+}
|
|
|
+.container {
|
|
|
+ max-width: 800px;
|
|
|
+ margin: 0 auto;
|
|
|
+ background: white;
|
|
|
+ border-radius: 15px;
|
|
|
+ box-shadow: 0 10px 30px rgba(0,0,0,0.3);
|
|
|
+ overflow: hidden;
|
|
|
+}
|
|
|
+.header {
|
|
|
+ background: linear-gradient(45deg, #e74c3c, #c0392b);
|
|
|
+ color: white;
|
|
|
+ padding: 20px;
|
|
|
+ text-align: center;
|
|
|
+}
|
|
|
+.header h1 {
|
|
|
+ margin: 0;
|
|
|
+ font-size: 28px;
|
|
|
+ text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
|
|
|
+}
|
|
|
+.results-table {
|
|
|
+ width: 100%;
|
|
|
+ border-collapse: collapse;
|
|
|
+}
|
|
|
+.results-table th {
|
|
|
+ background: #34495e;
|
|
|
+ color: white;
|
|
|
+ padding: 15px 10px;
|
|
|
+ text-align: center;
|
|
|
+}
|
|
|
+.results-table td {
|
|
|
+ padding: 12px 10px;
|
|
|
+ text-align: center;
|
|
|
+ border-bottom: 1px solid #e0e0e0;
|
|
|
+ font-weight: 900;
|
|
|
+}
|
|
|
+.footer {
|
|
|
+ background: #ecf0f1;
|
|
|
+ padding: 15px;
|
|
|
+ text-align: center;
|
|
|
+ color: #7f8c8d;
|
|
|
+ font-size: 12px;
|
|
|
+}
|
|
|
+</style>
|
|
|
+</head>
|
|
|
+<body>
|
|
|
+<div class="container">
|
|
|
+ <div class="header">
|
|
|
+ <h1>🎯 加拿大28开奖记录</h1>
|
|
|
+ <div class="subtitle">最近开奖记录</div>
|
|
|
+ </div>
|
|
|
+ <table class="results-table">
|
|
|
+ <thead>
|
|
|
+ <tr>
|
|
|
+ <th>回合</th>
|
|
|
+ <th>结果</th>
|
|
|
+ <th>组合</th>
|
|
|
+ <th>极值</th>
|
|
|
+ <th>尾数</th>
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ <tbody>
|
|
|
+ {$rows}
|
|
|
+ </tbody>
|
|
|
+ </table>
|
|
|
+ <div class="footer">
|
|
|
+ 生成时间: {$time} | 数据仅供参考
|
|
|
+ </div>
|
|
|
+</div>
|
|
|
+</body>
|
|
|
+</html>
|
|
|
+HTML;
|
|
|
+ }
|
|
|
+}
|