// 获取当前站点URL基础部分
function getSiteBaseUrl() {
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$domainName = $_SERVER['HTTP_HOST'];
return $protocol . $domainName;
}
// 生成微信分享链接
$baseUrl = getSiteBaseUrl();
// 我们使用与原链接相同的 token 和 id
if (isset($link) && !empty($link)) {
// 尝试提取token参数 (假设token在URL路径中或作为参数)
$tokenMatch = [];
if (preg_match('/token=([^&]+)/', $link, $tokenMatch)) {
// Token作为参数
$token = $tokenMatch[1];
} else {
// 尝试从路径中提取
$token = basename($link, ".php");
}
// 提取 id 参数
$idMatch = [];
if (preg_match('/id=(\d+)/', $link, $idMatch)) {
$reportId = $idMatch[1];
$wechatShareLink = $baseUrl . "/wechat_share.php?token=" . urlencode($token) . "&id=" . $reportId;
} else {
// 如果没有找到ID,使用默认的分享链接
$wechatShareLink = $baseUrl . "/wechat_share.php?token=" . urlencode($token);
}
} else {
// 如果$link不存在,创建一个占位符链接
$wechatShareLink = "#";
}
?>
<html lang="zh-CN">
<head>
链接 - = isset($site_title) ? $site_title : '系统' ?>
<link rel="stylesheet" href="../assets/css/admin.css">
<link rel="stylesheet" >
|