307 lines
11 KiB
HTML
307 lines
11 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: 800px;
|
||
|
|
margin: 0 auto;
|
||
|
|
padding: 20px;
|
||
|
|
}
|
||
|
|
.section {
|
||
|
|
margin-bottom: 30px;
|
||
|
|
padding: 15px;
|
||
|
|
border: 1px solid #ddd;
|
||
|
|
border-radius: 5px;
|
||
|
|
}
|
||
|
|
.form-group {
|
||
|
|
margin-bottom: 15px;
|
||
|
|
}
|
||
|
|
label {
|
||
|
|
display: block;
|
||
|
|
margin-bottom: 5px;
|
||
|
|
font-weight: bold;
|
||
|
|
}
|
||
|
|
input, textarea, select, button {
|
||
|
|
width: 100%;
|
||
|
|
padding: 8px;
|
||
|
|
border: 1px solid #ddd;
|
||
|
|
border-radius: 4px;
|
||
|
|
box-sizing: border-box;
|
||
|
|
}
|
||
|
|
button {
|
||
|
|
background-color: #4CAF50;
|
||
|
|
color: white;
|
||
|
|
border: none;
|
||
|
|
cursor: pointer;
|
||
|
|
margin-top: 10px;
|
||
|
|
}
|
||
|
|
button:hover {
|
||
|
|
background-color: #45a049;
|
||
|
|
}
|
||
|
|
.result {
|
||
|
|
margin-top: 15px;
|
||
|
|
padding: 10px;
|
||
|
|
background-color: #f9f9f9;
|
||
|
|
border-radius: 4px;
|
||
|
|
white-space: pre-wrap;
|
||
|
|
font-family: monospace;
|
||
|
|
}
|
||
|
|
.error {
|
||
|
|
background-color: #ffebee;
|
||
|
|
color: #c62828;
|
||
|
|
}
|
||
|
|
.success {
|
||
|
|
background-color: #e8f5e9;
|
||
|
|
color: #2e7d32;
|
||
|
|
}
|
||
|
|
</style>
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<h1>API测试</h1>
|
||
|
|
|
||
|
|
<div class="section">
|
||
|
|
<h2>用户注册</h2>
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="username">用户名:</label>
|
||
|
|
<input type="text" id="username" value="testuser123">
|
||
|
|
</div>
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="email">邮箱:</label>
|
||
|
|
<input type="email" id="email" value="test123@example.com">
|
||
|
|
</div>
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="password">密码:</label>
|
||
|
|
<input type="password" id="password" value="password123">
|
||
|
|
</div>
|
||
|
|
<button onclick="register()">注册</button>
|
||
|
|
<div id="registerResult" class="result"></div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="section">
|
||
|
|
<h2>用户登录</h2>
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="loginUsername">用户名或邮箱:</label>
|
||
|
|
<input type="text" id="loginUsername" value="testuser123">
|
||
|
|
</div>
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="loginPassword">密码:</label>
|
||
|
|
<input type="password" id="loginPassword" value="password123">
|
||
|
|
</div>
|
||
|
|
<button onclick="login()">登录</button>
|
||
|
|
<div id="loginResult" class="result"></div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="section">
|
||
|
|
<h2>创建邮件</h2>
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="mailTitle">标题:</label>
|
||
|
|
<input type="text" id="mailTitle" value="测试邮件">
|
||
|
|
</div>
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="mailContent">内容:</label>
|
||
|
|
<textarea id="mailContent" rows="4">这是一封测试邮件内容</textarea>
|
||
|
|
</div>
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="recipientType">收件人类型:</label>
|
||
|
|
<select id="recipientType">
|
||
|
|
<option value="SELF">自己</option>
|
||
|
|
<option value="SPECIFIC">指定用户</option>
|
||
|
|
<option value="PUBLIC">公开时间胶囊</option>
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="recipientEmail">收件人邮箱 (如果是指定用户):</label>
|
||
|
|
<input type="email" id="recipientEmail">
|
||
|
|
</div>
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="sendTime">发送时间:</label>
|
||
|
|
<input type="datetime-local" id="sendTime">
|
||
|
|
</div>
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="triggerType">触发类型:</label>
|
||
|
|
<select id="triggerType">
|
||
|
|
<option value="TIME">时间</option>
|
||
|
|
<option value="LOCATION">地点</option>
|
||
|
|
<option value="EVENT">事件</option>
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="capsuleStyle">胶囊样式:</label>
|
||
|
|
<input type="text" id="capsuleStyle" value="default">
|
||
|
|
</div>
|
||
|
|
<button onclick="createMail()">创建邮件</button>
|
||
|
|
<div id="createMailResult" class="result"></div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="section">
|
||
|
|
<h2>获取邮件列表</h2>
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="mailType">邮件类型:</label>
|
||
|
|
<select id="mailType">
|
||
|
|
<option value="SENT">已发送</option>
|
||
|
|
<option value="DRAFT">草稿</option>
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
<button onclick="getMails()">获取邮件列表</button>
|
||
|
|
<div id="getMailsResult" class="result"></div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
const API_BASE_URL = 'http://localhost:5003/api/v1';
|
||
|
|
let authToken = '';
|
||
|
|
|
||
|
|
// 设置默认发送时间为明天
|
||
|
|
document.getElementById('sendTime').value = new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString().slice(0, 16);
|
||
|
|
|
||
|
|
// 显示结果
|
||
|
|
function showResult(elementId, data, isError = false) {
|
||
|
|
const element = document.getElementById(elementId);
|
||
|
|
element.textContent = typeof data === 'object' ? JSON.stringify(data, null, 2) : data;
|
||
|
|
element.className = 'result ' + (isError ? 'error' : 'success');
|
||
|
|
}
|
||
|
|
|
||
|
|
// 注册
|
||
|
|
async function register() {
|
||
|
|
const username = document.getElementById('username').value;
|
||
|
|
const email = document.getElementById('email').value;
|
||
|
|
const password = document.getElementById('password').value;
|
||
|
|
|
||
|
|
try {
|
||
|
|
const response = await fetch(`${API_BASE_URL}/auth/register`, {
|
||
|
|
method: 'POST',
|
||
|
|
headers: {
|
||
|
|
'Content-Type': 'application/json'
|
||
|
|
},
|
||
|
|
body: JSON.stringify({
|
||
|
|
username,
|
||
|
|
email,
|
||
|
|
password
|
||
|
|
})
|
||
|
|
});
|
||
|
|
|
||
|
|
const data = await response.json();
|
||
|
|
|
||
|
|
if (response.ok) {
|
||
|
|
authToken = data.data.token;
|
||
|
|
showResult('registerResult', data);
|
||
|
|
} else {
|
||
|
|
showResult('registerResult', data, true);
|
||
|
|
}
|
||
|
|
} catch (error) {
|
||
|
|
showResult('registerResult', '错误: ' + error.message, true);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 登录
|
||
|
|
async function login() {
|
||
|
|
const usernameOrEmail = document.getElementById('loginUsername').value;
|
||
|
|
const password = document.getElementById('loginPassword').value;
|
||
|
|
|
||
|
|
try {
|
||
|
|
const response = await fetch(`${API_BASE_URL}/auth/login`, {
|
||
|
|
method: 'POST',
|
||
|
|
headers: {
|
||
|
|
'Content-Type': 'application/json'
|
||
|
|
},
|
||
|
|
body: JSON.stringify({
|
||
|
|
usernameOrEmail,
|
||
|
|
password
|
||
|
|
})
|
||
|
|
});
|
||
|
|
|
||
|
|
const data = await response.json();
|
||
|
|
|
||
|
|
if (response.ok) {
|
||
|
|
authToken = data.data.token;
|
||
|
|
showResult('loginResult', data);
|
||
|
|
} else {
|
||
|
|
showResult('loginResult', data, true);
|
||
|
|
}
|
||
|
|
} catch (error) {
|
||
|
|
showResult('loginResult', '错误: ' + error.message, true);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 创建邮件
|
||
|
|
async function createMail() {
|
||
|
|
if (!authToken) {
|
||
|
|
showResult('createMailResult', '请先登录', true);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
const title = document.getElementById('mailTitle').value;
|
||
|
|
const content = document.getElementById('mailContent').value;
|
||
|
|
const recipientType = document.getElementById('recipientType').value;
|
||
|
|
const recipientEmail = document.getElementById('recipientEmail').value;
|
||
|
|
const sendTime = document.getElementById('sendTime').value;
|
||
|
|
const triggerType = document.getElementById('triggerType').value;
|
||
|
|
const capsuleStyle = document.getElementById('capsuleStyle').value;
|
||
|
|
|
||
|
|
try {
|
||
|
|
const response = await fetch(`${API_BASE_URL}/mails/create`, {
|
||
|
|
method: 'POST',
|
||
|
|
headers: {
|
||
|
|
'Content-Type': 'application/json',
|
||
|
|
'Authorization': `Bearer ${authToken}`
|
||
|
|
},
|
||
|
|
body: JSON.stringify({
|
||
|
|
title,
|
||
|
|
content,
|
||
|
|
recipientType,
|
||
|
|
recipientEmail,
|
||
|
|
sendTime: new Date(sendTime).toISOString(),
|
||
|
|
triggerType,
|
||
|
|
triggerCondition: {},
|
||
|
|
attachments: [],
|
||
|
|
isEncrypted: false,
|
||
|
|
capsuleStyle
|
||
|
|
})
|
||
|
|
});
|
||
|
|
|
||
|
|
const data = await response.json();
|
||
|
|
|
||
|
|
if (response.ok) {
|
||
|
|
showResult('createMailResult', data);
|
||
|
|
} else {
|
||
|
|
showResult('createMailResult', data, true);
|
||
|
|
}
|
||
|
|
} catch (error) {
|
||
|
|
showResult('createMailResult', '错误: ' + error.message, true);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取邮件列表
|
||
|
|
async function getMails() {
|
||
|
|
if (!authToken) {
|
||
|
|
showResult('getMailsResult', '请先登录', true);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
const mailType = document.getElementById('mailType').value;
|
||
|
|
|
||
|
|
try {
|
||
|
|
const response = await fetch(`${API_BASE_URL}/mails?type=${mailType}&page=1&size=20`, {
|
||
|
|
method: 'GET',
|
||
|
|
headers: {
|
||
|
|
'Authorization': `Bearer ${authToken}`
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
const data = await response.json();
|
||
|
|
|
||
|
|
if (response.ok) {
|
||
|
|
showResult('getMailsResult', data);
|
||
|
|
} else {
|
||
|
|
showResult('getMailsResult', data, true);
|
||
|
|
}
|
||
|
|
} catch (error) {
|
||
|
|
showResult('getMailsResult', '错误: ' + error.message, true);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
</script>
|
||
|
|
</body>
|
||
|
|
</html>
|