test_page.html 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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>ThCardReader 读卡测试页面</title>
  7. <style>
  8. body {
  9. font-family: 'Microsoft YaHei', Arial, sans-serif;
  10. margin: 20px;
  11. background-color: #f5f5f5;
  12. }
  13. .container {
  14. max-width: 1200px;
  15. margin: 0 auto;
  16. background: white;
  17. padding: 20px;
  18. border-radius: 8px;
  19. box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  20. }
  21. .header {
  22. text-align: center;
  23. color: #333;
  24. border-bottom: 2px solid #007bff;
  25. padding-bottom: 20px;
  26. margin-bottom: 30px;
  27. }
  28. .section {
  29. margin-bottom: 30px;
  30. padding: 20px;
  31. border: 1px solid #ddd;
  32. border-radius: 5px;
  33. }
  34. .section h3 {
  35. color: #007bff;
  36. margin-top: 0;
  37. }
  38. .btn-group {
  39. margin: 10px 0;
  40. }
  41. .btn {
  42. background-color: #007bff;
  43. color: white;
  44. border: none;
  45. padding: 10px 20px;
  46. margin: 5px;
  47. border-radius: 4px;
  48. cursor: pointer;
  49. font-size: 14px;
  50. }
  51. .btn:hover {
  52. background-color: #0056b3;
  53. }
  54. .btn-success {
  55. background-color: #28a745;
  56. }
  57. .btn-success:hover {
  58. background-color: #218838;
  59. }
  60. .btn-warning {
  61. background-color: #ffc107;
  62. color: #333;
  63. }
  64. .btn-warning:hover {
  65. background-color: #e0a800;
  66. }
  67. .result {
  68. background-color: #f8f9fa;
  69. border: 1px solid #dee2e6;
  70. border-radius: 4px;
  71. padding: 15px;
  72. margin-top: 15px;
  73. min-height: 200px;
  74. font-family: 'Courier New', monospace;
  75. font-size: 12px;
  76. white-space: pre-wrap;
  77. overflow-x: auto;
  78. }
  79. .status {
  80. padding: 10px;
  81. margin: 10px 0;
  82. border-radius: 4px;
  83. font-weight: bold;
  84. }
  85. .status-success {
  86. background-color: #d4edda;
  87. color: #155724;
  88. border: 1px solid #c3e6cb;
  89. }
  90. .status-error {
  91. background-color: #f8d7da;
  92. color: #721c24;
  93. border: 1px solid #f5c6cb;
  94. }
  95. .status-info {
  96. background-color: #d1ecf1;
  97. color: #0c5460;
  98. border: 1px solid #bee5eb;
  99. }
  100. .api-info {
  101. background-color: #e9ecef;
  102. padding: 10px;
  103. border-radius: 4px;
  104. margin-bottom: 10px;
  105. font-family: 'Courier New', monospace;
  106. font-size: 13px;
  107. }
  108. </style>
  109. </head>
  110. <body>
  111. <div class="container">
  112. <div class="header">
  113. <h1>🆔 ThCardReader 读卡测试页面</h1>
  114. <p>支持华视读身份证和江苏医保读社保卡功能</p>
  115. <div id="serviceStatus" class="status status-info">
  116. 正在检查服务状态...
  117. </div>
  118. </div>
  119. <!-- 华视读身份证功能 -->
  120. <div class="section">
  121. <h3>🆔 华视读身份证功能</h3>
  122. <div class="api-info">服务地址:http://localhost:8321</div>
  123. <div class="btn-group">
  124. <button class="btn" onclick="huashiInit()">初始化读卡器</button>
  125. <button class="btn btn-success" onclick="huashiReadCard()">读取身份证</button>
  126. <button class="btn" onclick="huashiStatus()">设备状态</button>
  127. <button class="btn btn-warning" onclick="huashiClose()">关闭连接</button>
  128. </div>
  129. <div class="result" id="huashiResult">等待操作...</div>
  130. </div>
  131. <!-- 江苏医保读社保卡功能 -->
  132. <div class="section">
  133. <h3>🏥 江苏医保读社保卡功能</h3>
  134. <div class="api-info">服务地址:http://localhost:8321/readcard/jiangsu</div>
  135. <div class="btn-group">
  136. <button class="btn btn-success" onclick="jiangsuReadCardAuto()">自动初始化读卡</button>
  137. <button class="btn" onclick="jiangsuInit()">手动初始化</button>
  138. <button class="btn" onclick="jiangsuReadCard()">读取社保卡</button>
  139. <button class="btn" onclick="jiangsuStatus()">设备状态</button>
  140. </div>
  141. <div class="btn-group">
  142. <button class="btn btn-warning" onclick="jiangsuVerifyPin()">验证PIN码</button>
  143. <button class="btn btn-warning" onclick="jiangsuDiagnose()">系统诊断</button>
  144. </div>
  145. <div class="result" id="jiangsuResult">等待操作...</div>
  146. </div>
  147. </div>
  148. <script>
  149. // 基础配置
  150. const BASE_URL = 'http://localhost:8321';
  151. // 页面加载时检查服务状态
  152. window.onload = function() {
  153. checkServiceStatus();
  154. };
  155. // 检查服务状态
  156. async function checkServiceStatus() {
  157. try {
  158. const response = await fetch(`${BASE_URL}/readcard/huashi/health`);
  159. const data = await response.json();
  160. if (data.status === 'healthy') {
  161. showStatus('服务运行正常 ✅', 'success');
  162. } else {
  163. showStatus('服务状态异常 ⚠️', 'error');
  164. }
  165. } catch (error) {
  166. showStatus('服务未启动或无法访问 ❌', 'error');
  167. }
  168. }
  169. // 显示状态
  170. function showStatus(message, type) {
  171. const statusDiv = document.getElementById('serviceStatus');
  172. statusDiv.textContent = message;
  173. statusDiv.className = `status status-${type}`;
  174. }
  175. // 通用请求函数
  176. async function makeRequest(url, resultElementId) {
  177. const resultElement = document.getElementById(resultElementId);
  178. resultElement.textContent = '请求中...';
  179. try {
  180. const response = await fetch(url);
  181. const data = await response.json();
  182. resultElement.textContent = JSON.stringify(data, null, 2);
  183. // 根据结果更新状态
  184. if (data.code === 200 || data.success) {
  185. console.log('操作成功:', data);
  186. } else {
  187. console.error('操作失败:', data);
  188. }
  189. } catch (error) {
  190. resultElement.textContent = `请求失败: ${error.message}`;
  191. console.error('请求异常:', error);
  192. }
  193. }
  194. // 华视读卡器功能
  195. function huashiInit() {
  196. makeRequest(`${BASE_URL}/readcard/entry?param=huashi_init_1001`, 'huashiResult');
  197. }
  198. function huashiReadCard() {
  199. makeRequest(`${BASE_URL}/readcard/entry?param=huashi_readcard`, 'huashiResult');
  200. }
  201. function huashiStatus() {
  202. makeRequest(`${BASE_URL}/readcard/entry?param=huashi_status`, 'huashiResult');
  203. }
  204. function huashiClose() {
  205. makeRequest(`${BASE_URL}/readcard/entry?param=huashi_close`, 'huashiResult');
  206. }
  207. // 江苏医保功能
  208. function jiangsuReadCardAuto() {
  209. makeRequest(`${BASE_URL}/readcard/jiangsu/readcard_auto`, 'jiangsuResult');
  210. }
  211. function jiangsuInit() {
  212. makeRequest(`${BASE_URL}/readcard/jiangsu/init`, 'jiangsuResult');
  213. }
  214. function jiangsuReadCard() {
  215. makeRequest(`${BASE_URL}/readcard/jiangsu/readcard`, 'jiangsuResult');
  216. }
  217. function jiangsuStatus() {
  218. makeRequest(`${BASE_URL}/readcard/jiangsu/status`, 'jiangsuResult');
  219. }
  220. function jiangsuVerifyPin() {
  221. makeRequest(`${BASE_URL}/readcard/jiangsu/verifypin`, 'jiangsuResult');
  222. }
  223. function jiangsuDiagnose() {
  224. makeRequest(`${BASE_URL}/readcard/jiangsu/diagnose`, 'jiangsuResult');
  225. }
  226. // POST请求示例(高级功能)
  227. async function jiangsuPostRequest() {
  228. const resultElement = document.getElementById('jiangsuResult');
  229. resultElement.textContent = 'POST请求中...';
  230. try {
  231. const response = await fetch(`${BASE_URL}/readcard/jiangsu`, {
  232. method: 'POST',
  233. headers: {
  234. 'Content-Type': 'application/json'
  235. },
  236. body: JSON.stringify({
  237. action: 'readcard',
  238. autoVerifyPIN: false,
  239. autoInit: true
  240. })
  241. });
  242. const data = await response.json();
  243. resultElement.textContent = JSON.stringify(data, null, 2);
  244. } catch (error) {
  245. resultElement.textContent = `POST请求失败: ${error.message}`;
  246. }
  247. }
  248. </script>
  249. </body>
  250. </html>