132 lines
5.1 KiB
PHP
132 lines
5.1 KiB
PHP
<?php
|
||
// #########默认头部开始#########
|
||
// 引入 ThinkPHP 应用
|
||
require_once __DIR__ . '/../../../vendor/autoload.php';
|
||
use think\facade\Db;
|
||
use think\App;
|
||
|
||
$host = $_SERVER['HTTP_HOST'] ?? '';
|
||
$scheme = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') ? 'https' : 'http';
|
||
$baseUrl = $baseUrl ?? ($scheme . '://' . $host);
|
||
$apiUrl = $apiUrl ?? 'https://api.yunzer.cn';
|
||
|
||
/**
|
||
* 核心请求函数:fetchApiData
|
||
* 用于发送 GET 请求并解析 JSON
|
||
*/
|
||
function fetchApiData($url) {
|
||
$ch = curl_init();
|
||
curl_setopt($ch, CURLOPT_URL, $url);
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||
// 如果是 HTTPS 接口且本地环境没配置证书,可以临时跳过验证(生产环境建议配置)
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||
|
||
$response = curl_exec($ch);
|
||
$error = curl_error($ch);
|
||
curl_close($ch);
|
||
|
||
if ($error) {
|
||
return ['error' => $error];
|
||
}
|
||
|
||
return json_decode($response, true);
|
||
}
|
||
|
||
// #########默认头部结束#########
|
||
|
||
// 调用 banner 接口
|
||
$bannerUrl = $apiUrl . '/getBanners?baseUrl=' . urlencode($host);
|
||
$bannersRes = fetchApiData($bannerUrl);
|
||
$bannersList = $bannersRes['list'] ?? [];
|
||
|
||
// 调用 homeData 接口获取全局数据
|
||
$homeDataUrl = $apiUrl . '/homeData?baseUrl=' . urlencode($host);
|
||
$homeDataRes = fetchApiData($homeDataUrl);
|
||
$homeInfo = $homeDataRes['data'] ?? [];
|
||
|
||
// 调用 getCenterNews 接口获取新闻数据
|
||
$newsUrl = $apiUrl . '/getCenterNews?baseUrl=' . urlencode($host);
|
||
$newsRes = fetchApiData($newsUrl);
|
||
$newsList = $newsRes['list'] ?? [];
|
||
|
||
// 调用 文章分类 接口
|
||
$articleCategoryUrl = $apiUrl . '/getArticleCategories?baseUrl=' . urlencode($host);
|
||
$articleCategoryRes = fetchApiData($articleCategoryUrl);
|
||
$articleCategoryList = $articleCategoryRes['list'] ?? [];
|
||
|
||
// 获取特色服务
|
||
$servicesList = $homeInfo['services'] ?? [];
|
||
|
||
// 获取企业产品
|
||
$productsList = $homeInfo['products'] ?? [];
|
||
|
||
// 获取友链数据
|
||
$friendlinkList = $homeInfo['links'] ?? [];
|
||
|
||
// 动态设置 SEO 变量(优先用每个页面自己的变量)
|
||
$seoTitle = $pageTitle ?? ($homeInfo['normal']['sitename'] ?? '云泽网 默认标题');
|
||
$seoDescription = $pageDescription ?? ($homeInfo['normal']['description'] ?? '');
|
||
$seoKeywords = $pageKeywords ?? ($homeInfo['normal']['keywords'] ?? '');
|
||
|
||
?>
|
||
<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
||
<base href="/themes/template3/">
|
||
|
||
<!-- 使用页面级 SEO 变量 -->
|
||
<title><?php echo htmlspecialchars($seoTitle); ?></title>
|
||
<meta name="description" content="<?php echo htmlspecialchars($homeInfo['normal']['description']); ?>">
|
||
<meta name="keywords" content="<?php echo htmlspecialchars($seoKeywords); ?>">
|
||
|
||
<link href="<?php echo $baseUrl; ?>/themes/template3/assets/img/favicon.png" rel="icon">
|
||
<link href="<?php echo $baseUrl; ?>/themes/template3/assets/img/apple-touch-icon.png" rel="apple-touch-icon">
|
||
|
||
<link href="<?php echo $baseUrl; ?>/themes/template3/assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
|
||
<link href="<?php echo $baseUrl; ?>/themes/template3/assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
|
||
<link href="<?php echo $baseUrl; ?>/themes/template3/assets/vendor/aos/aos.css" rel="stylesheet">
|
||
<link href="<?php echo $baseUrl; ?>/themes/template3/assets/vendor/glightbox/css/glightbox.min.css" rel="stylesheet">
|
||
<link href="<?php echo $baseUrl; ?>/themes/template3/assets/vendor/swiper/swiper-bundle.min.css" rel="stylesheet">
|
||
|
||
<link href="<?php echo $baseUrl; ?>/themes/template3/assets/css/style.css" rel="stylesheet">
|
||
<link href="<?php echo $baseUrl; ?>/themes/template3/assets/css/main.css" rel="stylesheet">
|
||
</head>
|
||
|
||
<body class="blog-page">
|
||
|
||
<header id="header" class="header d-flex align-items-center fixed-top">
|
||
<div class="container-fluid container-xl position-relative d-flex align-items-center justify-content-between">
|
||
|
||
<?php
|
||
// 安全获取 logo,避免 homeInfo['normal'] 未定义时报错
|
||
$logo = '';
|
||
if (!empty($homeInfo['normal']) && !empty($homeInfo['normal']['logow'])) {
|
||
$logo = $baseUrl . $homeInfo['normal']['logow'];
|
||
} else {
|
||
// 兜底:使用模板自带的默认 logo
|
||
$logo = $baseUrl . '/themes/template3/assets/img/logo.png';
|
||
}
|
||
?>
|
||
<a href="<?php echo $baseUrl; ?>/" class="logo d-flex align-items-center">
|
||
<img src="<?php echo htmlspecialchars($logo); ?>" alt="">
|
||
</a>
|
||
|
||
<nav id="navmenu" class="navmenu">
|
||
<ul>
|
||
<li><a href="<?php echo $baseUrl; ?>/" class="active">主页</a></li>
|
||
<li><a href="<?php echo $baseUrl; ?>/blog">新闻中心</a></li>
|
||
<li><a href="<?php echo $baseUrl; ?>/portfolio">特色业务</a></li>
|
||
<li><a href="<?php echo $baseUrl; ?>/contact">联系我们</a></li>
|
||
<li><a href="<?php echo $baseUrl; ?>/about">关于我们</a></li>
|
||
</ul>
|
||
<i class="mobile-nav-toggle d-xl-none bi bi-list"></i>
|
||
</nav>
|
||
|
||
</div>
|
||
</header>
|
||
|
||
<main class="main">
|