示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private ICCardData DirectReadCard()
        {
            InitIC();
            ICCardData result = ReadIc();

            Beep();
            ExitIC();
            return(result);
        }
示例#2
0
        /// <summary>
        /// 读卡
        /// </summary>
        /// <returns></returns>
        public ICCardData ReadIc()
        {
            ulong icCardNo = 0;
            char  str      = (char)0;

            dc_reset(_icdev, 0);
            dc_card((Int16)_icdev, str, ref icCardNo);

            ICCardData result = new ICCardData
            {
                cardId = icCardNo.ToString()
            };

            return(result);
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="result"></param>
        private void RequestCallback(IAsyncResult result)
        {
            Encoding            encoding = new UTF8Encoding(false); // Whenever I have UTF8 problems it's BOM's fault
            HttpListenerContext context  = null;

            try
            {
                context = HttpListener.EndGetContext(result);
                context.Response.AppendHeader("Access-Control-Allow-Origin", "*");
                context.Response.ContentEncoding = Encoding.UTF8;

                ICCardData obj         = DirectReadCard();
                string     json        = GetJsonByObject(obj);
                byte[]     outputBytes = encoding.GetBytes(json);

                context.Response.ContentType     = "application/json";
                context.Response.ContentLength64 = outputBytes.Length;
                context.Response.OutputStream.Write(outputBytes, 0, outputBytes.Length);
                //logger.WriteEntry("完成HTTP请求,已应答。");
            }
            catch (Exception ex)
            {
                byte[] outputBytes = encoding.GetBytes(ex.Message);
                context.Response.StatusCode      = 500;
                context.Response.ContentType     = "text/plain";
                context.Response.ContentLength64 = outputBytes.Length;
                context.Response.OutputStream.Write(outputBytes, 0, outputBytes.Length);

                logger.WriteEntry("读取身份证出错:" + ex.Message);
            }
            finally
            {
                if (context != null && context.Response != null)
                {
                    context.Response.Close();
                }

                HttpListener.BeginGetContext(new AsyncCallback(RequestCallback), null);
            }
        }