test_simple_huashi.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>华视读卡器简单测试</title>
  7. <style>
  8. body { font-family: Arial, sans-serif; margin: 20px; line-height: 1.6; }
  9. .container { max-width: 1000px; margin: 0 auto; }
  10. button { background: #007cba; color: white; border: none; padding: 10px 20px; margin: 5px; cursor: pointer; border-radius: 4px; }
  11. button:hover { background: #005a87; }
  12. .result { background: #f5f5f5; border: 1px solid #ccc; padding: 15px; margin: 10px 0; border-radius: 4px; }
  13. .error { color: red; }
  14. .success { color: green; }
  15. .info { color: blue; }
  16. pre { white-space: pre-wrap; word-wrap: break-word; }
  17. </style>
  18. </head>
  19. <body>
  20. <div class="container">
  21. <h1>华视读卡器简单测试</h1>
  22. <div class="test-section">
  23. <h2>测试功能</h2>
  24. <button onclick="testSimpleCall()">简单读卡测试</button>
  25. <button onclick="testHealthCheck()">健康检查</button>
  26. <button onclick="testDeviceStatus()">设备状态</button>
  27. <button onclick="clearResults()">清除结果</button>
  28. </div>
  29. <div id="results"></div>
  30. </div>
  31. <script>
  32. function addResult(title, data, type = 'info') {
  33. const results = document.getElementById('results');
  34. const div = document.createElement('div');
  35. div.className = `result ${type}`;
  36. let content = `<h3>${title}</h3>`;
  37. if (typeof data === 'object') {
  38. content += `<pre>${JSON.stringify(data, null, 2)}</pre>`;
  39. } else {
  40. content += `<p>${data}</p>`;
  41. }
  42. div.innerHTML = content;
  43. results.appendChild(div);
  44. results.scrollTop = results.scrollHeight;
  45. }
  46. function testSimpleCall() {
  47. addResult('开始简单读卡测试', '使用简单API端点...', 'info');
  48. // 使用简单的GET请求避免路由冲突
  49. fetch('http://localhost:8321/readcard/huashi/simple?action=readcard&port=1001', {
  50. method: 'GET',
  51. headers: { 'Content-Type': 'application/json' }
  52. })
  53. .then(response => response.json())
  54. .then(data => {
  55. const type = data.code === 200 ? 'success' : 'error';
  56. addResult('简单读卡结果', data, type);
  57. // 检查照片数据
  58. if (data.data) {
  59. analyzePhotoData(data.data);
  60. }
  61. })
  62. .catch(error => {
  63. addResult('请求错误', error.message, 'error');
  64. });
  65. }
  66. function testHealthCheck() {
  67. fetch('http://localhost:8321/readcard/huashi/health', {
  68. method: 'GET'
  69. })
  70. .then(response => response.json())
  71. .then(data => {
  72. addResult('健康检查', data, 'info');
  73. })
  74. .catch(error => {
  75. addResult('健康检查错误', error.message, 'error');
  76. });
  77. }
  78. function testDeviceStatus() {
  79. fetch('http://localhost:8321/readcard/huashi/status', {
  80. method: 'GET'
  81. })
  82. .then(response => response.json())
  83. .then(data => {
  84. const type = data.connected ? 'success' : 'warning';
  85. addResult('设备状态', data, type);
  86. })
  87. .catch(error => {
  88. addResult('设备状态错误', error.message, 'error');
  89. });
  90. }
  91. function analyzePhotoData(data) {
  92. let analysis = [];
  93. analysis.push(`photoBase64字段: ${data.hasOwnProperty('photoBase64') ? '存在' : '不存在'}`);
  94. analysis.push(`photoBase64长度: ${data.photoBase64 ? data.photoBase64.length : 0}`);
  95. analysis.push(`hasPhoto: ${data.hasPhoto}`);
  96. analysis.push(`photoFormat: ${data.photoFormat || '未设置'}`);
  97. analysis.push(`photoSize: ${data.photoSize || 0}`);
  98. if (data.photoBase64 && data.photoBase64.length > 0) {
  99. const preview = data.photoBase64.substring(0, 20);
  100. analysis.push(`BASE64前20字符: "${preview}"`);
  101. }
  102. addResult('📸 照片数据分析', analysis.join('\n'), 'info');
  103. }
  104. function clearResults() {
  105. document.getElementById('results').innerHTML = '';
  106. }
  107. // 页面加载完成后的说明
  108. window.onload = function() {
  109. addResult('测试说明',
  110. `华视读卡器简单测试页面
  111. 使用GET方法避免路由冲突问题。
  112. 测试步骤:
  113. 1. 先点击"健康检查"确认服务正常
  114. 2. 点击"设备状态"检查读卡器状态
  115. 3. 将身份证放在读卡器上
  116. 4. 点击"简单读卡测试"
  117. 5. 查看照片数据分析结果
  118. 注意:这个页面使用简化的API端点,避免复杂的POST请求路由冲突。`, 'info');
  119. };
  120. </script>
  121. </body>
  122. </html>