江苏宿迁沭阳铭和医院的华视读卡器URL调用说明.md 9.5 KB

华视读卡器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 关闭读卡器连接

🚀 快速使用示例

// 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页面调用示例

<!DOCTYPE html>
<html>
<head>
    <title>华视读卡器测试</title>
    <meta charset="utf-8">
</head>
<body>
    <h1>华视读卡器测试页面</h1>
    
    <button onclick="initReader()">1. 初始化读卡器</button>
    <button onclick="readCard()">2. 读取身份证</button>
    <button onclick="getStatus()">3. 获取设备状态</button>
    <button onclick="closeReader()">4. 关闭连接</button>
    
    <div id="result" style="margin-top: 20px; padding: 10px; border: 1px solid #ccc; min-height: 200px; font-family: monospace;"></div>

    <script>
        function showResult(title, data) {
            const resultDiv = document.getElementById('result');
            resultDiv.innerHTML = `<h3>${title}</h3><pre>${JSON.stringify(data, null, 2)}</pre>`;
        }

        // 1. 初始化读卡器
        async function initReader() {
            try {
                const response = await fetch('http://localhost:8321/readcard/entry?param=huashi_init_1001');
                const data = await response.json();
                showResult('初始化结果', data);
            } catch (error) {
                showResult('初始化错误', { error: error.message });
            }
        }

        // 2. 读取身份证
        async function readCard() {
            try {
                const response = await fetch('http://localhost:8321/readcard/entry?param=huashi_readcard');
                const data = await response.json();
                showResult('读卡结果', data);
                
                if (data.code === 200 && data.data) {
                    alert(`读取成功!\n姓名:${data.data.name}\n身份证号:${data.data.idCode}`);
                }
            } catch (error) {
                showResult('读卡错误', { error: error.message });
            }
        }

        // 3. 获取设备状态
        async function getStatus() {
            try {
                const response = await fetch('http://localhost:8321/readcard/entry?param=huashi_status');
                const data = await response.json();
                showResult('设备状态', data);
            } catch (error) {
                showResult('状态获取错误', { error: error.message });
            }
        }

        // 4. 关闭连接
        async function closeReader() {
            try {
                const response = await fetch('http://localhost:8321/readcard/entry?param=huashi_close');
                const data = await response.json();
                showResult('关闭结果', data);
            } catch (error) {
                showResult('关闭错误', { error: error.message });
            }
        }
    </script>
</body>
</html>

C# WinForm调用示例

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}", "错误");
        }
    }
}

📊 返回数据格式

成功响应示例

{
    "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": ""
    }
}

错误响应示例

{
    "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_01101sicard等调用保持不变
  • ✅ 新增huashi_*系列调用支持华视读卡器
  • ✅ 两套系统可以并行使用

现在您可以像调用现有读卡功能一样,通过简单的URL调用华视读卡器了! 🎉