# 华视读卡器URL调用说明 ## 📋 概述 华视读卡器现在支持与现有系统相同的URL调用方式,您可以通过简单的GET请求来调用华视读卡器功能。 --- ## 🔗 调用方式对比 ### 现有系统调用方式 ``` http://localhost:8321/readcard/entry?param=idcard_01101 ``` ### 华视读卡器调用方式 #### 方式一:通过现有EntryController调用(推荐) ``` http://localhost:8321/readcard/entry?param=huashi_readcard ``` #### 方式二:通过专用HuaShiController调用 ``` http://localhost:8321/api/huashi/simple?action=readcard ``` --- ## 📡 EntryController调用方式(推荐) ### 基本格式 ``` http://localhost:8321/readcard/entry?param=huashi_{操作}_{参数} ``` ### 🔧 支持的操作 | 操作 | URL示例 | 说明 | |------|---------|------| | **初始化** | `http://localhost:8321/readcard/entry?param=huashi_init_1001` | 初始化读卡器,端口1001 | | **读身份证** | `http://localhost:8321/readcard/entry?param=huashi_readcard` | 读取身份证(最常用) | | **连续读卡** | `http://localhost:8321/readcard/entry?param=huashi_continuous` | 连续读卡模式 | | **设备状态** | `http://localhost:8321/readcard/entry?param=huashi_status` | 获取设备状态 | | **关闭连接** | `http://localhost:8321/readcard/entry?param=huashi_close` | 关闭读卡器连接 | ### 🚀 快速使用示例 ```javascript // 1. 初始化华视读卡器(使用USB端口1001) fetch('http://localhost:8321/readcard/entry?param=huashi_init_1001') .then(response => response.json()) .then(data => console.log('初始化结果:', data)); // 2. 读取身份证 fetch('http://localhost:8321/readcard/entry?param=huashi_readcard') .then(response => response.json()) .then(data => console.log('读卡结果:', data)); // 3. 获取设备状态 fetch('http://localhost:8321/readcard/entry?param=huashi_status') .then(response => response.json()) .then(data => console.log('设备状态:', data)); ``` --- ## 📡 HuaShiController调用方式 ### 基本格式 ``` http://localhost:8321/api/huashi/simple?action={操作}&port={端口} ``` ### 🔧 支持的操作 | 操作 | URL示例 | 说明 | |------|---------|------| | **初始化** | `http://localhost:8321/api/huashi/simple?action=init&port=1001` | 初始化读卡器 | | **读身份证** | `http://localhost:8321/api/huashi/simple?action=readcard` | 读取身份证 | | **连续读卡** | `http://localhost:8321/api/huashi/simple?action=continuous` | 连续读卡模式 | | **设备状态** | `http://localhost:8321/api/huashi/simple?action=status` | 获取设备状态 | | **关闭连接** | `http://localhost:8321/api/huashi/simple?action=close` | 关闭连接 | --- ## 🎯 完整的使用流程 ### HTML页面调用示例 ```html 华视读卡器测试

华视读卡器测试页面

``` ### C# WinForm调用示例 ```csharp using System; using System.Net.Http; using System.Threading.Tasks; using System.Windows.Forms; using Newtonsoft.Json.Linq; public partial class Form1 : Form { private static readonly HttpClient httpClient = new HttpClient(); // 初始化华视读卡器 private async void btnInit_Click(object sender, EventArgs e) { try { string url = "http://localhost:8321/readcard/entry?param=huashi_init_1001"; string response = await httpClient.GetStringAsync(url); JObject result = JObject.Parse(response); MessageBox.Show($"初始化结果:{result["message"]}", "华视读卡器"); } catch (Exception ex) { MessageBox.Show($"初始化异常:{ex.Message}", "错误"); } } // 读取身份证 private async void btnReadCard_Click(object sender, EventArgs e) { try { string url = "http://localhost:8321/readcard/entry?param=huashi_readcard"; string response = await httpClient.GetStringAsync(url); JObject result = JObject.Parse(response); if ((int)result["code"] == 200) { var data = result["data"]; string info = $"姓名:{data["name"]}\n" + $"性别:{data["sex"]}\n" + $"民族:{data["nation"]}\n" + $"出生日期:{data["birthday"]}\n" + $"身份证号:{data["idCode"]}\n" + $"地址:{data["address"]}"; MessageBox.Show(info, "身份证信息"); } else { MessageBox.Show($"读卡失败:{result["message"]}", "错误"); } } catch (Exception ex) { MessageBox.Show($"读卡异常:{ex.Message}", "错误"); } } } ``` --- ## 📊 返回数据格式 ### 成功响应示例 ```json { "code": 200, "type": "huashi_idcard", "message": "华视读卡器读取身份证成功", "device": "华视电子身份证读卡器", "data": { "name": "张三", "sex": "男", "nation": "汉", "birthday": "19900101", "idCode": "110101199001011234", "address": "北京市东城区某某街道123号", "department": "北京市公安局东城分局", "startDate": "20200101", "endDate": "20300101", "sexCode": "1", "nationCode": "01", "certType": "" } } ``` ### 错误响应示例 ```json { "code": 1001, "message": "端口打开失败,请检查读卡器连接", "errorCode": 2, "device": "华视电子身份证读卡器" } ``` --- ## ⚠️ 注意事项 1. **📌 硬件要求**: - 华视电子身份证读卡器硬件设备 - 正确安装设备驱动程序 - 四个DLL文件(termb.dll等)部署到bin目录 2. **🔧 使用顺序**: - 首次使用需要先调用`huashi_init`初始化 - 然后可以多次调用`huashi_readcard`读取身份证 - 使用完毕建议调用`huashi_close`关闭连接 3. **⏱️ 性能建议**: - 读卡间隔建议大于300ms - 可使用`huashi_continuous`连续读卡模式提高效率 4. **🛡️ 错误处理**: - 检查返回的`code`字段,200表示成功 - 失败时查看`message`字段了解具体错误 --- ## 🔄 与现有系统的兼容性 | 现有调用 | 华视读卡器调用 | 说明 | |----------|----------------|------| | `param=idcard_01101` | `param=huashi_readcard` | 读取身份证 | | `param=sicard` | `param=huashi_readcard` | 功能类似,读取证件信息 | 华视读卡器完全独立运行,不会影响现有的医保业务调用: - ✅ 现有的`idcard_01101`、`sicard`等调用保持不变 - ✅ 新增`huashi_*`系列调用支持华视读卡器 - ✅ 两套系统可以并行使用 --- **现在您可以像调用现有读卡功能一样,通过简单的URL调用华视读卡器了!** 🎉