This repository has been archived on 2026-06-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
wsh5485 678c79c5a7 fix(test): 修正测试页面中日志文件路径错误
将测试页面中的日志文件路径从相对路径改为绝对路径,确保能正确加载日志文件
2025-12-05 17:17:21 +08:00

263 lines
8.9 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>WPS表单Webhook测试</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.container {
background-color: #f5f5f5;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
h1 {
color: #333;
text-align: center;
}
.test-section {
margin: 20px 0;
padding: 15px;
background-color: white;
border-radius: 4px;
border: 1px solid #ddd;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
margin: 5px;
}
button:hover {
background-color: #45a049;
}
.response {
margin-top: 10px;
padding: 10px;
background-color: #f0f0f0;
border-radius: 4px;
white-space: pre-wrap;
font-family: monospace;
}
.log-section {
margin-top: 30px;
}
#log-content {
height: 300px;
overflow-y: auto;
background-color: #2d2d2d;
color: #f0f0f0;
padding: 10px;
border-radius: 4px;
font-family: monospace;
}
</style>
</head>
<body>
<div class="container">
<h1>WPS表单Webhook测试工具</h1>
<div class="test-section">
<h2>1. 验证请求测试</h2>
<p>模拟WPS表单的验证请求,Webhook应返回绑定码</p>
<button onclick="testVerification()">发送验证请求</button>
<div class="response" id="verification-response"></div>
</div>
<div class="test-section">
<h2>2. 表单数据测试</h2>
<p>模拟WPS表单发送数据,Webhook应接收并处理数据</p>
<button onclick="testFormData()">发送表单数据</button>
<div class="response" id="form-data-response"></div>
</div>
<div class="log-section">
<h2>3. Webhook日志</h2>
<button onclick="loadLog()">加载日志</button>
<button onclick="clearLog()">清空日志</button>
<div id="log-content"></div>
</div>
</div>
<script>
// Webhook URL
const webhookUrl = 'http://carwash.com/webhook.php';
// 发送验证请求
async function testVerification() {
const responseDiv = document.getElementById('verification-response');
responseDiv.innerHTML = '发送中...';
try {
const response = await fetch(webhookUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: '' // 空请求体,模拟验证请求
});
const data = await response.json();
responseDiv.innerHTML = '响应: ' + JSON.stringify(data, null, 2);
} catch (error) {
responseDiv.innerHTML = '错误: ' + error.message;
}
}
// 发送表单数据
async function testFormData() {
const responseDiv = document.getElementById('form-data-response');
responseDiv.innerHTML = '发送中...';
// 模拟WPS实际表单数据格式
const formData = {
"rid": "lAFP6N1Tap",
"formId": "20251205123619412736007",
"formTitle": "张老师撸车(私家车库)预约撸车表单",
"aid": "20251205131620432762589",
"eventTs": Date.now(),
"messageTs": Date.now(),
"creatorId": "344573037",
"creatorName": "吴展鹏",
"event": "create_answer",
"version": 2,
"answerContents": [
{
"qid": "eo513g",
"type": "input",
"title": "怎么称呼您",
"value": "吴展鹏"
},
{
"qid": "xKFUcp",
"type": "input",
"title": "车型",
"value": "比亚迪宋PRODMi"
},
{
"qid": "NFJDDT",
"type": "input",
"title": "车牌号",
"value": "新AF10365-普通输入"
},
{
"qid": "t2u2i4",
"type": "licensePlate",
"title": "车牌号",
"value": "新AF10365-车牌专用"
},
{
"qid": "7jgfmh",
"type": "telphone",
"title": "请输入手机号",
"value": "18699627661"
},
{
"qid": "3j6opi",
"type": "select",
"title": "是否有车衣",
"value": ["否,无车衣"]
},
{
"qid": "ej48lk",
"type": "select",
"title": "有无自己撸车习惯",
"value": ["有"]
},
{
"qid": "1tnljp",
"type": "select",
"title": "撸车经验",
"value": ["我是老司机啦"]
},
{
"qid": "x02g35",
"type": "select",
"title": "洗车频率",
"value": ["每2周一次(每月1-2次)"]
},
{
"qid": "54dbo7",
"type": "select",
"title": "请选择年龄段",
"value": ["26~30"]
},
{
"qid": "rwxgkc",
"type": "autoNum",
"title": "自动编号",
"value": "zlslc202512002"
},
{
"qid": "r3ft9n",
"type": "input",
"title": "备注内容",
"value": "谢谢"
}
]
};
try {
const response = await fetch(webhookUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(formData)
});
const data = await response.json();
responseDiv.innerHTML = '响应: ' + JSON.stringify(data, null, 2);
} catch (error) {
responseDiv.innerHTML = '错误: ' + error.message;
}
}
// 加载日志
async function loadLog() {
const logContent = document.getElementById('log-content');
logContent.innerHTML = '加载中...';
try {
const response = await fetch('/log/wps_form_webhook.log');
if (response.ok) {
const text = await response.text();
logContent.innerHTML = text;
} else {
logContent.innerHTML = '无法加载日志文件: ' + response.statusText;
}
} catch (error) {
logContent.innerHTML = '错误: ' + error.message;
}
}
// 清空日志
async function clearLog() {
const logContent = document.getElementById('log-content');
try {
const response = await fetch('webhook.php?action=clear_log', {
method: 'POST'
});
if (response.ok) {
logContent.innerHTML = '日志已清空';
} else {
logContent.innerHTML = '清空日志失败';
}
} catch (error) {
logContent.innerHTML = '错误: ' + error.message;
}
}
</script>
</body>
</html>