192 lines
7.5 KiB
HTML
192 lines
7.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>消息历史API测试</title>
|
|
<style>
|
|
body { font-family: Arial, sans-serif; max-width: 1000px; margin: 0 auto; padding: 20px; }
|
|
.test-section { margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 5px; }
|
|
.test-button { background: #1890ff; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer; margin: 5px; }
|
|
.result { background: #f5f5f5; padding: 10px; border-radius: 4px; margin-top: 10px; white-space: pre-wrap; font-family: monospace; max-height: 400px; overflow-y: auto; }
|
|
.error { background: #fff2f0; border: 1px solid #ffccc7; color: #ff4d4f; }
|
|
.success { background: #f6ffed; border: 1px solid #b7eb8f; color: #52c41a; }
|
|
input { padding: 5px; margin: 5px; width: 300px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>消息历史API测试</h1>
|
|
|
|
<div class="test-section">
|
|
<h3>Token设置</h3>
|
|
<input type="text" id="tokenInput" placeholder="请输入JWT Token">
|
|
<button class="test-button" onclick="loadToken()">从localStorage加载</button>
|
|
<button class="test-button" onclick="saveToken()">保存到localStorage</button>
|
|
</div>
|
|
|
|
<div class="test-section">
|
|
<h3>API测试</h3>
|
|
<button class="test-button" onclick="testGetUserMessages()">测试分页查询</button>
|
|
<button class="test-button" onclick="testSearchMessages()">测试搜索消息</button>
|
|
<button class="test-button" onclick="testRecentMessages()">测试最近消息</button>
|
|
<button class="test-button" onclick="testAllAPIs()">测试所有API</button>
|
|
</div>
|
|
|
|
<div class="test-section">
|
|
<h3>测试结果</h3>
|
|
<div id="result" class="result">等待测试...</div>
|
|
</div>
|
|
|
|
<script>
|
|
function loadToken() {
|
|
const token = localStorage.getItem('token');
|
|
if (token) {
|
|
document.getElementById('tokenInput').value = token;
|
|
showResult('Token已加载', 'success');
|
|
} else {
|
|
showResult('localStorage中没有token', 'error');
|
|
}
|
|
}
|
|
|
|
function saveToken() {
|
|
const token = document.getElementById('tokenInput').value.trim();
|
|
if (token) {
|
|
localStorage.setItem('token', token);
|
|
showResult('Token已保存到localStorage', 'success');
|
|
} else {
|
|
showResult('请先输入Token', 'error');
|
|
}
|
|
}
|
|
|
|
function showResult(message, type = 'success') {
|
|
const resultDiv = document.getElementById('result');
|
|
resultDiv.textContent = message;
|
|
resultDiv.className = `result ${type}`;
|
|
}
|
|
|
|
async function makeRequest(url, options = {}) {
|
|
const token = document.getElementById('tokenInput').value.trim();
|
|
if (!token) {
|
|
throw new Error('请先输入Token');
|
|
}
|
|
|
|
const headers = {
|
|
'Authorization': `Bearer ${token}`,
|
|
'Content-Type': 'application/json',
|
|
...options.headers
|
|
};
|
|
|
|
const response = await fetch(url, { ...options, headers });
|
|
const data = await response.json();
|
|
|
|
return { status: response.status, data };
|
|
}
|
|
|
|
async function testGetUserMessages() {
|
|
try {
|
|
showResult('正在测试分页查询...', 'success');
|
|
|
|
const result = await makeRequest('/api/message/user/page?current=1&size=5');
|
|
|
|
const message = `分页查询结果:
|
|
状态码: ${result.status}
|
|
响应: ${JSON.stringify(result.data, null, 2)}`;
|
|
|
|
showResult(message, result.status === 200 ? 'success' : 'error');
|
|
} catch (error) {
|
|
showResult(`分页查询错误: ${error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
async function testSearchMessages() {
|
|
try {
|
|
showResult('正在测试搜索消息...', 'success');
|
|
|
|
const result = await makeRequest('/api/message/user/search', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ keyword: '测试', limit: 5 })
|
|
});
|
|
|
|
const message = `搜索消息结果:
|
|
状态码: ${result.status}
|
|
响应: ${JSON.stringify(result.data, null, 2)}`;
|
|
|
|
showResult(message, result.status === 200 ? 'success' : 'error');
|
|
} catch (error) {
|
|
showResult(`搜索消息错误: ${error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
async function testRecentMessages() {
|
|
try {
|
|
showResult('正在测试最近消息...', 'success');
|
|
|
|
const result = await makeRequest('/api/message/user/recent', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ limit: 5 })
|
|
});
|
|
|
|
const message = `最近消息结果:
|
|
状态码: ${result.status}
|
|
响应: ${JSON.stringify(result.data, null, 2)}`;
|
|
|
|
showResult(message, result.status === 200 ? 'success' : 'error');
|
|
} catch (error) {
|
|
showResult(`最近消息错误: ${error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
async function testAllAPIs() {
|
|
try {
|
|
showResult('正在测试所有API...', 'success');
|
|
|
|
const results = [];
|
|
|
|
// 测试分页查询
|
|
try {
|
|
const pageResult = await makeRequest('/api/message/user/page?current=1&size=5');
|
|
results.push(`✅ 分页查询: ${pageResult.status} - ${pageResult.data.message || 'OK'}`);
|
|
} catch (error) {
|
|
results.push(`❌ 分页查询: ${error.message}`);
|
|
}
|
|
|
|
// 测试搜索
|
|
try {
|
|
const searchResult = await makeRequest('/api/message/user/search', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ keyword: '测试', limit: 5 })
|
|
});
|
|
results.push(`✅ 搜索消息: ${searchResult.status} - ${searchResult.data.message || 'OK'}`);
|
|
} catch (error) {
|
|
results.push(`❌ 搜索消息: ${error.message}`);
|
|
}
|
|
|
|
// 测试最近消息
|
|
try {
|
|
const recentResult = await makeRequest('/api/message/user/recent', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ limit: 5 })
|
|
});
|
|
results.push(`✅ 最近消息: ${recentResult.status} - ${recentResult.data.message || 'OK'}`);
|
|
} catch (error) {
|
|
results.push(`❌ 最近消息: ${error.message}`);
|
|
}
|
|
|
|
const message = `所有API测试结果:
|
|
${results.join('\n')}
|
|
|
|
详细信息请查看浏览器控制台`;
|
|
|
|
showResult(message, 'success');
|
|
|
|
} catch (error) {
|
|
showResult(`测试过程中发生错误: ${error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// 页面加载时自动加载token
|
|
window.onload = loadToken;
|
|
</script>
|
|
</body>
|
|
</html>
|