123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <!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: Arial, sans-serif; margin: 20px; line-height: 1.6; }
- .container { max-width: 1200px; margin: 0 auto; }
- button { background: #007cba; color: white; border: none; padding: 10px 20px; margin: 5px; cursor: pointer; border-radius: 4px; }
- button:hover { background: #005a87; }
- .result { background: #f5f5f5; border: 1px solid #ccc; padding: 15px; margin: 10px 0; border-radius: 4px; }
- .error { color: red; }
- .success { color: green; }
- .info { color: blue; }
- .warning { color: orange; }
- .debug-info { background: #fff3cd; border: 1px solid #ffeaa7; padding: 10px; margin: 10px 0; border-radius: 4px; }
- </style>
- </head>
- <body>
- <div class="container">
- <h1>华视读卡器照片功能调试</h1>
-
- <div class="test-section">
- <h2>调试测试</h2>
- <button onclick="testReadCard()">读取身份证(调试模式)</button>
- <button onclick="clearResults()">清除结果</button>
- </div>
- <div class="debug-info">
- <h3>调试说明</h3>
- <p>本页面专门用于调试华视读卡器的照片BASE64功能。会显示详细的调试信息。</p>
- <p><strong>预期行为:</strong></p>
- <ul>
- <li>如果华视SDK支持BASE64函数,应该能看到详细的调用过程</li>
- <li>如果不支持,会显示函数调用失败的信息</li>
- <li>备用方法会尝试获取二进制数据并手动转换</li>
- </ul>
- </div>
- <div id="results"></div>
- </div>
- <script>
- function addResult(title, data, type = 'info') {
- const results = document.getElementById('results');
- const div = document.createElement('div');
- div.className = `result ${type}`;
-
- let content = `<h3>${title}</h3>`;
- if (typeof data === 'object') {
- content += `<pre>${JSON.stringify(data, null, 2)}</pre>`;
- } else {
- content += `<p>${data}</p>`;
- }
-
- div.innerHTML = content;
- results.appendChild(div);
- results.scrollTop = results.scrollHeight;
- }
- function testReadCard() {
- addResult('开始调试测试', '正在读取身份证,请确保卡片已放置...', 'info');
-
- fetch('http://localhost:8321/readcard/huashi/readcard', {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ autoClose: true })
- })
- .then(response => response.json())
- .then(data => {
- const type = data.code === 200 ? 'success' : 'error';
- addResult('读卡结果', data, type);
-
- // 分析调试信息
- if (data.data) {
- analyzePhotoData(data.data);
- }
- })
- .catch(error => {
- addResult('请求错误', error.message, 'error');
- });
- }
- function analyzePhotoData(data) {
- let analysis = [];
-
- // 检查照片相关字段
- analysis.push(`photoBase64字段存在: ${data.hasOwnProperty('photoBase64')}`);
- analysis.push(`photoBase64长度: ${data.photoBase64 ? data.photoBase64.length : 0}`);
- analysis.push(`hasPhoto: ${data.hasPhoto}`);
- analysis.push(`photoFormat: ${data.photoFormat || '未设置'}`);
- analysis.push(`photoSize: ${data.photoSize || 0}`);
-
- // 如果有照片数据,分析前几个字符
- if (data.photoBase64 && data.photoBase64.length > 0) {
- const preview = data.photoBase64.substring(0, 50);
- analysis.push(`BASE64前50字符: "${preview}"`);
-
- // 检查是否是有效的BASE64
- try {
- atob(data.photoBase64.substring(0, Math.min(100, data.photoBase64.length)));
- analysis.push('BASE64格式: 有效');
- } catch (e) {
- analysis.push('BASE64格式: 无效 - ' + e.message);
- }
- }
-
- addResult('照片数据分析', analysis.join('\n'), 'warning');
- }
- function clearResults() {
- document.getElementById('results').innerHTML = '';
- }
- // 页面加载完成后的说明
- window.onload = function() {
- addResult('调试模式启动',
- `华视读卡器照片功能调试模式已启动。
-
- 本次修复内容:
- 1. 修正函数名:Getbase64JpgDataU 和 Getbase64BMPDataU (添加U后缀)
- 2. 修正缓冲区大小:JPG=38862*2字节,BMP=38862*4字节
- 3. 改进判断逻辑:只有长度>50才认为是有效照片
- 4. 添加详细调试信息
- 如果仍然获取不到照片,可能的原因:
- 1. 华视SDK版本不支持这些BASE64函数
- 2. 需要特殊的初始化或权限
- 3. 函数签名不正确
- 请先测试读卡,然后查看调试信息。`, 'info');
- };
- </script>
- </body>
- </html>
|