当前位置: 首页 > news >正文

HTTP协议网络读卡器通讯报文

本说明使用的读卡器:https://item.taobao.com/item.htm?spm=a21dvs.23580594.0.0.52de2c1bGBhMtE&ft=t&id=22173428704

一、读卡器设置为GET方式提交刷卡数据

GET /IC-14h.asp?info=37&jihao=0&cardtype=5&card=0000000A&dn=169850547BD05F21 HTTP/1.1
Host: 192.168.1.211:5000
Connection: close
User-Agent: Mozilla/4.0
Accept-Language: en

二、读卡器设置为POST方式提交刷卡数据

POST /IC-14h.asp HTTP/1.1
Host: 192.168.1.211:5000
Connection: close
User-Agent: Mozilla/4.0
Accept-Language: en
Content-Type: application/x-www-form-urlencoded
Content-Length: 60

info=37&jihao=0&cardtype=5&card=0000000A&dn=169850547BD05F21

三、读卡器设置为JSON方式提交刷卡数据

POST /IC-14h.asp HTTP/1.1
Host: 192.168.1.211:5000
Connection: close
User-Agent: Mozilla/4.0
Accept-Language: en
Content-Type: application/json
Content-Length: 82

{"info":"24","jihao":"0","cardtype":"5","card":"0000000A","dn":"169850547BD05F21"}

四、服务器端以JSON方式回应驱动读卡器显示文字、播报语音

{"Response":"json","infotype":"1","info":"28","disp":"{卡号:}1234567890AB25-04-30 11:30:50","dispdelay":"20","beeptype":"1","voicetype":"读取卡号[n1]1234567890ABCDEF","k1delay":"20","k2delay":"20"}

五、服务器端以字符串方式回应驱动读卡器显示文字、播报语音

Response=1,32,{卡号:}1234567890AB25-04-30 11:30:50,20,2,读取卡号[n1]1234567890ABCDEF,20,30

六、服务端ASHX网页获取刷卡数据及回应示例

<%@ WebHandler Language="C#" Class="HttpReader" %>using System;
using System.Web;
using System.IO;
//using Newtonsoft.Json;public class HttpReader : IHttpHandler
{    public void ProcessRequest (HttpContext context) {        string info = "";string jihao = "";string cardtype = "";string scantype = "";string heartbeattype = "";string card = "";string data = "";string input = "";string output = "";string rand = "";string dn = "";string status = "";        Int16 cardtype16 = 0;int cardtypecode = 0;int pushortake = 0;string dispstr = "";string ChineseVoice = "[v8]";    //[v8]表示本次播报语音音量,取值范围v1 到 v16context.Response.ContentType = "text/plain";if (context.Request["info"] != null) { info = context.Request["info"].ToString(); }                                 //接收到的数据包号,需回应该包号if (context.Request["jihao"] != null) { jihao = context.Request["jihao"].ToString(); }                              //设备机号(可自编)                        if (context.Request["cardtype"] != null) { cardtype = context.Request["cardtype"].ToString(); }                     //刷卡标识位if (context.Request["scantype"] != null) { scantype = context.Request["scantype"].ToString(); }                     //扫码标识位if (context.Request["heartbeattype"] != null) { heartbeattype = context.Request["heartbeattype"].ToString(); }      //心跳包标识   if (context.Request["card"] != null) { card = context.Request["card"].ToString(); }                                 //接收到的原始16进制卡号,可根据需要自行转换成其他卡号if (context.Request["data"] != null) { data = context.Request["data"].ToString(); }                                 //扇区内容 或 扫码信息if (context.Request["input"] != null) { input = context.Request["input"].ToString(); }                              //输入标志if (context.Request["output"] != null) { output = context.Request["output"].ToString(); }                           //输出标志if (context.Request["rand"] != null) { rand = context.Request["rand"].ToString(); }                                 //设备的随机数if (context.Request["dn"] != null) { dn = context.Request["dn"].ToString(); }                                       //设备硬件序列号,出厂时已固化,全球唯一if (context.Request["status"] != null) { status = context.Request["status"].ToString(); }                           //读卡状态,如12表示卡密码认证失败      if (info == "" && jihao == "" && dn == "")    //如果未接收到有效的Request信息,再尝试用Json解析是否有Request信息{StreamReader sr = new StreamReader(context.Request.GetBufferlessInputStream());string response = sr.ReadToEnd();info = getjsonval(response, "info");                    //接收到的数据包号,需回应该包号jihao = getjsonval(response, "jihao");                  //设备机号(可自编)cardtype = getjsonval(response, "cardtype");            //刷卡标志,卡类型scantype = getjsonval(response, "scantype");            //扫码标志heartbeattype = getjsonval(response, "heartbeattype");  //心跳包标志   card = getjsonval(response, "card");                    //接收到的原始16进制卡号,可根据需要自行转换成其他卡号data = getjsonval(response, "data");                    //扇区内容 或 扫码信息              input = getjsonval(response, "input");                  //输入标识output = getjsonval(response, "output");                //输出标识         rand = getjsonval(response, "rand");                    //设备随机数dn = getjsonval(response, "dn");                        //设备硬件序列号,出厂时已固化,全球唯一status = getjsonval(response, "status");                //读卡状态,如12表示卡密码认证失败                                                    }if (heartbeattype == "1" && dn != "" && info != "") //接收到的Request信息是 心跳包{string RepStr = "Response=1";             //Response=1 固定前缀,我们的设备以此来检索返回信息,RepStr = RepStr + "," + info;             //提交的信息序号,一定要对应RepStr = RepStr + "," + dn + getChinesecode("接收到心跳信息! ");          //读卡器上显示文字,显示中文要转换编码RepStr = RepStr + ",20";                  //显示时长20秒RepStr = RepStr + ",1";                   //蜂鸣器发声种类,取值范围0-12RepStr = RepStr + ",";                    //播报的TTS语音//string RepStr = "Response=1," + info + ",,0,0,"; //正式项目可以用不显示文字、不响声、不播报语音的指令来回应心跳,也可以不回应,此处加入显示、响声只是用来检测读卡器功能context.Response.Write(RepStr);          }else{if (info != "" && card != "" && cardtype != "")    //接收到有效的刷卡Request信息,回应驱动读卡器显示文字、蜂鸣响声或播报语音{cardtype16 = Convert.ToInt16(cardtype, 16);pushortake = cardtype16 / 128;       //pushortake=0 表示读卡,>0表示卡离开感应区cardtypecode = cardtype16 % 16;      //cardtypecode=1 ID卡,2 HID卡,3 T5557卡,4 EM4305卡,5 IC卡,6 二代身份证,7 是15693卡,IClass"  dispstr = "{" + getChinesecode("卡号") + ":}" + (card + "      ").Substring(0, 12) + DateTime.Now.ToString("yy-MM-dd HH:mm:ss"); //显示信息,注意中文汉字一定要转换为设备能显示的编码,其它字母数字符号不需要转换,{}内的信息反白显示if (pushortake > 0){ChineseVoice = ChineseVoice + getChinesecode("卡号") + "[n1]" + card + getChinesecode("离开感应区!");     //TTS语音,注意中文汉字一定要转换为设备能识别的编码,[n1]表示数字播报方式,其它字母数字符号不需要转换              }else{ChineseVoice = ChineseVoice + getChinesecode("读取卡号") + "[n1]" + card;}//第一种回应方式string RepStr = "Response=1";             //Response=1 固定前缀,我们的设备以此来检索返回信息,表示 驱动设备显示和响声RepStr = RepStr + "," + info;             //提交的信息序号,一定要对应RepStr = RepStr + "," + dispstr;          //读卡器上显示文字,显示中文要转换编码RepStr = RepStr + ",20";                  //显示时长20秒RepStr = RepStr + ",2";                   //蜂鸣器发声种类,取值范围0-12RepStr = RepStr + "," + ChineseVoice;     //播报的TTS语音RepStr = RepStr + ",20";                 //第1继电器开启延时单位,每1个单位延时25mm,20*25表示500mm,取值为0表示关闭继电器RepStr = RepStr + ",30";                  //第2继电器开启延时单位,以,分隔,总计可以控制8个继电器context.Response.Write(RepStr);           //将回应信息传送到读卡器驱动读卡器显示文字、蜂鸣响声、播报语音//第二种以JSON的方式回应//string jsonText = "{\"Response\":\"json\",\"infotype\":\"1\"";      //固定前缀,我们的设备以此来检索返回信息,表示 驱动设备显示和响声//jsonText = jsonText + ",\"info\":\"" + info + "\"";                 //提交的信息序号,一定要对应//jsonText = jsonText + ",\"disp\":\"" + dispstr + "\"";              //显示文字,注意中文汉字一定要转换为设备能显示的编码,其它字母数字符号不需要转换,{}内的信息反白显示//jsonText = jsonText + ",\"dispdelay\":\"20\"";                      //显示时长20秒//jsonText = jsonText + ",\"beeptype\":\"1\"";                        //蜂鸣器发声种类,取值范围0-12//jsonText = jsonText + ",\"voicetype\":\""+ChineseVoice+"\"";        //播报的TTS语音//jsonText = jsonText + ",\"k1delay\":\"20\"";                        //第1继电器开启延时单位,每1个单位延时25mm,20*25表示500mm,取值为0表示关闭继电器//jsonText = jsonText + ",\"k2delay\":\"20\"}";                       //第2继电器开启延时单位,以,分隔,总计可以控制8个继电器//context.Response.ContentType = "application/json";//context.Response.Write(jsonText);       }else{if (info != "" && scantype != "") //接收到有效的扫码信息{dispstr = "{" + getChinesecode("扫码") + ":}" + data; //显示信息,注意中文汉字一定要转换为设备能显示的编码,其它字母数字符号不需要转换,{}内的信息反白显示       ChineseVoice = getChinesecode("扫码")  + data;//第一种回应方式                          string RepStr = "Response=1";             //Response=1 固定前缀,我们的设备以此来检索返回信息,表示 驱动设备显示和响声RepStr = RepStr + "," + info;             //提交的信息序号,一定要对应RepStr = RepStr + "," + dispstr;          //读卡器上显示文字,显示中文要转换编码RepStr = RepStr + ",20";                  //显示时长20秒RepStr = RepStr + ",2";                   //蜂鸣器发声种类,取值范围0-12RepStr = RepStr + "," + ChineseVoice;     //播报的TTS语音RepStr = RepStr + ",20";                  //第1继电器开启延时单位,每1个单位延时25mm,20*25表示500mm,取值为0表示关闭继电器RepStr = RepStr + ",30";                  //第2继电器开启延时单位,以,分隔,总计可以控制8个继电器context.Response.Write(RepStr);           //将回应信息传送到读卡器驱动读卡器显示文字、蜂鸣响声、播报语音            //第二种以JSON的方式回应//string jsonText = "{\"Response\":\"json\",\"infotype\":\"1\"";      //固定前缀,我们的设备以此来检索返回信息,表示 驱动设备显示和响声//jsonText = jsonText + ",\"info\":\"" + info + "\"";                 //提交的信息序号,一定要对应//jsonText = jsonText + ",\"disp\":\"" + dispstr + "\\n\\n\"";        //显示文字,注意中文汉字一定要转换为设备能显示的编码,其它字母数字符号不需要转换,{}内的信息反白显示//jsonText = jsonText + ",\"dispdelay\":\"20\"";                      //显示时长20秒//jsonText = jsonText + ",\"beeptype\":\"1\"";                        //蜂鸣器发声种类,取值范围0-12//jsonText = jsonText + ",\"voicetype\":\"" + ChineseVoice + "\"";    //播报的TTS语音//jsonText = jsonText + ",\"k1delay\":\"20\"";                        //第1继电器开启延时单位,每1个单位延时25mm,20*25表示500mm,取值为0表示关闭继电器//jsonText = jsonText + ",\"k2delay\":\"20\"}";                       //第2继电器开启延时单位,以,分隔,总计可以控制8个继电器//context.Response.ContentType = "application/json";//context.Response.Write(jsonText);                           }}}  }public static string getChinesecode(string inputstr)   //获取中文编码,显示汉字、TTS中文语音都要转换编码{int strlen = inputstr.Length;string hexcode = "";for (int i = 0; i < strlen; i++){string str = inputstr.Substring(i, 1);byte[] Chinesecodearry = System.Text.Encoding.GetEncoding(936).GetBytes(str);int codelen = (byte)Chinesecodearry.Length;if (codelen == 1){hexcode = hexcode + str;}else{hexcode = hexcode + "\\x" + Chinesecodearry[0].ToString("X2") + Chinesecodearry[1].ToString("X2");}}return hexcode;}public static string getjsonval(string totalstr, string namestr)    //解析JSON数据{string valustr = "";totalstr = totalstr.Replace("{", "");totalstr = totalstr.Replace("}", "");totalstr = totalstr.Replace("\"", "");string[] dataArray = totalstr.Split(new char[2] { ',', ',' });if (dataArray.GetUpperBound(0) > 0){for (int i = 0; i < dataArray.Length; i++){string[] dataArray2 = dataArray[i].Split(new char[2] { ':', ':' });if (dataArray2[0] == namestr){valustr = dataArray2[1];break;}                      }}return valustr;}    public bool IsReusable {get {return false;}}}

http://www.xdnf.cn/news/309367.html

相关文章:

  • 无法解析导入“pybulletgym”
  • C# System.Text.Json实现高效JSON序列化与反序列化
  • 基于Java多线程实现简单图片下载
  • SLAM算法工程师面经大全:2025年面试真题解析与实战指南
  • 美信监控易:全栈式自主可控的底层架构优势
  • 使用 Poco C++ 库构建轻量级 HTTP 服务器
  • LeetCode 1128. 等价多米诺骨牌对的数量 题解
  • 【了解】通感算一体化网络
  • 深入理解 Web 架构:从基础到实践
  • 【大模型面试每日一题】Day 10:混合精度训练如何加速大模型训练?可能出现什么问题?如何解决?
  • 数据库复习
  • 面试常问系列(一)-神经网络参数初始化-之自注意力机制为什么除以根号d而不是2*根号d或者3*根号d
  • 最新版Google浏览器加载ActiveX控件之VLC五一节特别版
  • Marin说PCB之1000-BASE-T1的PCB设计总结--04
  • DeepSeek:突破AI搜索的无限可能
  • ProteinTools辅助探索蛋白稳定性、动态调控以及结构关系
  • 优化04-选择率和直方图
  • 意识场方程与道函数赋能的三智双融体系建构
  • Xcode16提交App Store审核时提示bitcode报错
  • vue3 computed方法传参数
  • Java泛型深度解析与电商场景应用
  • 手写Promise.all
  • USB接口的PCB设计
  • vue3在使用@import “./index.scss“报错
  • 互联网法院在NFT、元宇宙等新兴领域的规则创新
  • 江苏正力新能Verify认知能力测评笔试已通知 | SHL测评题库预测题 | 华东同舟求职讲求职
  • 园区网的发展
  • Hologres x 函数计算 x Qwen3,对接MCP构建企业级数据分析 Agent
  • 深度可分离卷积(0)
  • Linux 网络编程 day5 多路IO转接之改进select and poll