123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>工伤接口调试工具</title>
- <style>
- body { font-family: 'Microsoft YaHei', sans-serif; margin: 20px; background: #f5f5f5; }
- .container { max-width: 1200px; margin: 0 auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
- .debug-section { margin: 15px 0; padding: 15px; border: 1px solid #ddd; border-radius: 5px; }
- .debug-section h3 { margin-top: 0; color: #333; }
- button { padding: 10px 20px; margin: 5px; border: none; border-radius: 4px; cursor: pointer; font-size: 14px; }
- .btn-test { background: #007bff; color: white; }
- .btn-test:hover { background: #0056b3; }
- textarea { width: 100%; height: 200px; font-family: 'Consolas', monospace; font-size: 12px; border: 1px solid #ddd; border-radius: 4px; padding: 10px; }
- .status-success { background-color: #d4edda; border-color: #c3e6cb; color: #155724; }
- .status-error { background-color: #f8d7da; border-color: #f5c6cb; color: #721c24; }
- .status-warning { background-color: #fff3cd; border-color: #ffeaa7; color: #856404; }
- .info-box { padding: 10px; margin: 10px 0; border-radius: 4px; border: 1px solid; }
- .timestamp { font-size: 12px; color: #666; float: right; }
- </style>
- </head>
- <body>
- <div class="container">
- <h1>🔧 江苏工伤联网接口调试工具</h1>
- <p>专门用于诊断Status 200但无响应体的问题</p>
- <div class="debug-section">
- <h3>🚀 快速测试</h3>
- <button class="btn-test" onclick="testInit()">测试初始化</button>
- <button class="btn-test" onclick="testHealth()">测试健康检查</button>
- <button class="btn-test" onclick="testSignIn()">测试签到</button>
- <button class="btn-test" onclick="testSignOut()">测试签退</button>
- <button class="btn-test" onclick="clearLogs()">清空日志</button>
- </div>
- <div class="debug-section">
- <h3>📡 请求信息</h3>
- <div>
- <strong>请求URL:</strong> <span id="requestUrl">等待请求...</span>
- <span class="timestamp" id="requestTime"></span>
- </div>
- <div><strong>请求方法:</strong> POST</div>
- <div><strong>Content-Type:</strong> application/json</div>
- <div><strong>请求体:</strong></div>
- <textarea id="requestBody" readonly></textarea>
- </div>
- <div class="debug-section">
- <h3>📊 响应信息</h3>
- <div class="info-box" id="statusBox">
- <strong>状态:</strong> <span id="httpStatus">等待响应...</span>
- <span class="timestamp" id="responseTime"></span>
- </div>
- <div><strong>响应头:</strong></div>
- <textarea id="responseHeaders" readonly></textarea>
- <div><strong>响应体:</strong></div>
- <textarea id="responseBody" readonly></textarea>
- </div>
- <div class="debug-section">
- <h3>🔍 执行路径追踪</h3>
- <div id="executionPath"></div>
- </div>
- <div class="debug-section">
- <h3>📝 调试日志</h3>
- <div id="debugLogs"></div>
- </div>
- </div>
- <script>
- const BASE_URL = 'http://localhost:8321/api/entry/workinjury';
- function logMessage(message, type = 'info') {
- const logs = document.getElementById('debugLogs');
- const timestamp = new Date().toLocaleString();
- const logEntry = document.createElement('div');
- logEntry.className = `info-box status-${type === 'error' ? 'error' : type === 'warning' ? 'warning' : 'success'}`;
- logEntry.innerHTML = `<strong>[${timestamp}]</strong> ${message}`;
- logs.appendChild(logEntry);
- logs.scrollTop = logs.scrollHeight;
- }
- function clearLogs() {
- document.getElementById('debugLogs').innerHTML = '';
- document.getElementById('requestBody').value = '';
- document.getElementById('responseBody').value = '';
- document.getElementById('responseHeaders').value = '';
- document.getElementById('httpStatus').textContent = '等待响应...';
- document.getElementById('executionPath').innerHTML = '';
- }
- function updateRequestInfo(url, body) {
- document.getElementById('requestUrl').textContent = url;
- document.getElementById('requestTime').textContent = new Date().toLocaleString();
- document.getElementById('requestBody').value = JSON.stringify(body, null, 2);
- }
- function updateResponseInfo(status, headers, body, responseTime) {
- const statusBox = document.getElementById('statusBox');
- const statusSpan = document.getElementById('httpStatus');
-
- statusSpan.textContent = `${status}`;
- document.getElementById('responseTime').textContent = new Date(responseTime).toLocaleString();
-
- // 设置状态颜色
- statusBox.className = 'info-box ' + (status === 200 ? 'status-success' : 'status-error');
-
- // 显示响应头
- let headersText = '';
- if (headers) {
- for (let [key, value] of headers.entries()) {
- headersText += `${key}: ${value}\n`;
- }
- }
- document.getElementById('responseHeaders').value = headersText;
-
- // 显示响应体
- if (body) {
- document.getElementById('responseBody').value = JSON.stringify(body, null, 2);
-
- // 追踪执行路径
- updateExecutionPath(body);
- } else {
- document.getElementById('responseBody').value = '(无响应体或响应体为空)';
- logMessage('⚠️ 关键问题:Status 200但响应体为空!', 'error');
- }
- }
- function updateExecutionPath(responseBody) {
- const pathDiv = document.getElementById('executionPath');
- pathDiv.innerHTML = '';
-
- if (responseBody && typeof responseBody === 'object') {
- const steps = [];
-
- // 收集所有debug_step信息
- for (let key in responseBody) {
- if (key.startsWith('debug_')) {
- steps.push(`<strong>${key}:</strong> ${responseBody[key]}`);
- }
- }
-
- if (steps.length > 0) {
- pathDiv.innerHTML = '<div class="info-box status-success">' + steps.join('<br>') + '</div>';
- } else {
- pathDiv.innerHTML = '<div class="info-box status-warning">响应中无调试信息</div>';
- }
- } else {
- pathDiv.innerHTML = '<div class="info-box status-error">无法解析响应体</div>';
- }
- }
- async function makeRequest(action, additionalParams = {}) {
- const requestTime = Date.now();
- const requestBody = {
- action: action,
- timestamp: new Date().toISOString(),
- ...additionalParams
- };
- updateRequestInfo(BASE_URL, requestBody);
- logMessage(`🚀 发送请求: ${action}`, 'info');
- try {
- const response = await fetch(BASE_URL, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Accept': 'application/json'
- },
- body: JSON.stringify(requestBody)
- });
- const responseTime = Date.now();
- logMessage(`📡 收到响应: ${response.status} ${response.statusText}`, response.ok ? 'success' : 'error');
- let responseBody = null;
- const contentType = response.headers.get('content-type');
-
- if (contentType && contentType.includes('application/json')) {
- try {
- responseBody = await response.json();
- logMessage('✅ 响应体解析成功', 'success');
- } catch (jsonError) {
- logMessage(`❌ JSON解析失败: ${jsonError.message}`, 'error');
- responseBody = { error: 'JSON解析失败', details: jsonError.message };
- }
- } else {
- const text = await response.text();
- logMessage(`⚠️ 响应不是JSON格式,Content-Type: ${contentType}`, 'warning');
- responseBody = { error: '非JSON响应', contentType: contentType, text: text };
- }
- updateResponseInfo(response.status, response.headers, responseBody, responseTime);
- // 特殊处理Status 200但无响应体的情况
- if (response.status === 200 && (!responseBody || Object.keys(responseBody).length === 0)) {
- logMessage('🔥 发现关键问题:HTTP 200成功但响应体为空!', 'error');
- logMessage('这通常表示C#代码执行过程中发生了未捕获的异常或DLL访问冲突', 'error');
- }
- } catch (networkError) {
- logMessage(`🚫 网络错误: ${networkError.message}`, 'error');
- updateResponseInfo('Network Error', null, { error: networkError.message }, Date.now());
- }
- }
- // 测试函数
- function testInit() {
- makeRequest('init', {
- config: {
- fixmedinsCode: 'SQ201348',
- fixmedinsName: '沭阳铭和医院',
- interfaceVersion: 'V2.1'
- }
- });
- }
- function testHealth() {
- makeRequest('health');
- }
- function testSignIn() {
- makeRequest('transaction', {
- transactionName: 'SignIn',
- identifyMode: '1',
- operatorId: '001',
- operatorName: '系统管理员'
- });
- }
- function testSignOut() {
- makeRequest('transaction', {
- transactionName: 'SignOut',
- identifyMode: '1',
- operatorId: '001',
- operatorName: '系统管理员'
- });
- }
- // 页面加载时的初始化
- document.addEventListener('DOMContentLoaded', function() {
- logMessage('🔧 调试工具已加载,可以开始测试', 'success');
- logMessage('如果看到Status 200但无响应体,请检查ThCardReader.exe进程是否正常运行', 'warning');
- });
- </script>
- </body>
- </html>
|