华视读卡器现在支持与现有系统相同的URL调用方式,您可以通过简单的GET请求来调用华视读卡器功能。
http://localhost:8321/readcard/entry?param=idcard_01101
http://localhost:8321/readcard/entry?param=huashi_readcard
http://localhost:8321/api/huashi/simple?action=readcard
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));
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 |
关闭连接 |
<!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>
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": "华视电子身份证读卡器"
}
📌 硬件要求:
🔧 使用顺序:
huashi_init
初始化huashi_readcard
读取身份证huashi_close
关闭连接⏱️ 性能建议:
huashi_continuous
连续读卡模式提高效率🛡️ 错误处理:
code
字段,200表示成功message
字段了解具体错误现有调用 | 华视读卡器调用 | 说明 |
---|---|---|
param=idcard_01101 |
param=huashi_readcard |
读取身份证 |
param=sicard |
param=huashi_readcard |
功能类似,读取证件信息 |
华视读卡器完全独立运行,不会影响现有的医保业务调用:
idcard_01101
、sicard
等调用保持不变huashi_*
系列调用支持华视读卡器现在您可以像调用现有读卡功能一样,通过简单的URL调用华视读卡器了! 🎉