Initial commit: Telegram Management System
Some checks failed
Deploy / deploy (push) Has been cancelled
Some checks failed
Deploy / deploy (push) Has been cancelled
Full-stack web application for Telegram management - Frontend: Vue 3 + Vben Admin - Backend: NestJS - Features: User management, group broadcast, statistics 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
213
frontend/public/telegram-bridge.html
Normal file
213
frontend/public/telegram-bridge.html
Normal file
@@ -0,0 +1,213 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Telegram 聊天</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
background-color: #f0f0f0;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.loading-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100vh;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
border: 3px solid #f3f3f3;
|
||||
border-top: 3px solid #3498db;
|
||||
border-radius: 50%;
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.loading-text {
|
||||
margin-top: 20px;
|
||||
color: #666;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.error-container {
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100vh;
|
||||
background: white;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.error-icon {
|
||||
font-size: 48px;
|
||||
color: #e74c3c;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
color: #333;
|
||||
font-size: 18px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.error-detail {
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.retry-button {
|
||||
background-color: #3498db;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
font-size: 16px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
.retry-button:hover {
|
||||
background-color: #2980b9;
|
||||
}
|
||||
|
||||
iframe {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
border: none;
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="loading-container" id="loading">
|
||||
<div class="spinner"></div>
|
||||
<div class="loading-text">正在准备 Telegram 聊天...</div>
|
||||
</div>
|
||||
|
||||
<div class="error-container" id="error">
|
||||
<div class="error-icon">⚠️</div>
|
||||
<div class="error-message">加载失败</div>
|
||||
<div class="error-detail" id="errorDetail"></div>
|
||||
<button class="retry-button" onclick="location.reload()">重试</button>
|
||||
</div>
|
||||
|
||||
<iframe id="telegramFrame" src="" frameborder="0" allow="camera; microphone; geolocation" allowfullscreen></iframe>
|
||||
|
||||
<script>
|
||||
// 获取URL参数
|
||||
function getQueryParam(name) {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
return urlParams.get(name);
|
||||
}
|
||||
|
||||
// 显示错误
|
||||
function showError(message) {
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
document.getElementById('error').style.display = 'flex';
|
||||
document.getElementById('errorDetail').textContent = message;
|
||||
}
|
||||
|
||||
// 初始化
|
||||
async function init() {
|
||||
const accountId = getQueryParam('accountId');
|
||||
|
||||
if (!accountId) {
|
||||
// 如果没有accountId,直接显示官方Telegram Web
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
const frame = document.getElementById('telegramFrame');
|
||||
frame.src = 'https://web.telegram.org';
|
||||
frame.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 获取账号的Web会话信息
|
||||
const response = await fetch('/api/tgAccount/getWebSession', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer ' + localStorage.getItem('token')
|
||||
},
|
||||
body: JSON.stringify({ id: accountId })
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success && result.data) {
|
||||
// 准备自动登录
|
||||
const sessionData = result.data;
|
||||
|
||||
// 显示Telegram Web
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
const frame = document.getElementById('telegramFrame');
|
||||
|
||||
// 使用官方Telegram Web
|
||||
frame.src = 'https://web.telegram.org/k/';
|
||||
frame.style.display = 'block';
|
||||
|
||||
// 等待iframe加载完成后尝试注入session
|
||||
frame.onload = function() {
|
||||
setTimeout(() => {
|
||||
try {
|
||||
// 尝试与iframe通信(可能会因为跨域限制而失败)
|
||||
console.log('Telegram Web已加载,账号信息:', sessionData.user);
|
||||
|
||||
// 更新加载文本提示用户
|
||||
if (sessionData.user && sessionData.user.phone) {
|
||||
// 创建一个临时提示
|
||||
const hint = document.createElement('div');
|
||||
hint.style.cssText = `
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
background: #4CAF50;
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
z-index: 10000;
|
||||
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
|
||||
`;
|
||||
hint.textContent = `当前账号: ${sessionData.user.phone}`;
|
||||
document.body.appendChild(hint);
|
||||
|
||||
// 5秒后移除提示
|
||||
setTimeout(() => {
|
||||
hint.remove();
|
||||
}, 5000);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('无法直接注入session,需要手动登录');
|
||||
}
|
||||
}, 2000);
|
||||
};
|
||||
} else {
|
||||
showError(result.message || '获取会话信息失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('初始化失败:', error);
|
||||
showError('网络错误,请检查连接');
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载完成后初始化
|
||||
window.addEventListener('DOMContentLoaded', init);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user