Example #1
0
        //public override Card getCardInfo(string cardNo)
        //{
        //    //TODO 调用万通卡查询余额的方法,返回卡片信息

        //    return null;
        //}

        //public override bool Recharge(string cardNo, int gasValue)
        //{
        //    throw new NotImplementedException();
        //}

        //public override bool Recharge(string cardNo, double moneyCount)
        //{
        //    //TODO 调用拉卡拉消费的方法
        //    //TODO 调用拉卡拉消费的方法,如果失败,提示错误,跳出方法

        //    //TODO 调用拉卡拉消费的方法,如果成功,调用万通卡的充值方法
        //    return false;

        //}

        /// <summary>
        /// 调用读卡器,拿到万通卡卡号
        /// </summary>
        /// <returns></returns>
        public string GetCardNo()
        {
            string        port   = SysConfigHelper.readerNode("CRT310Port");
            StringBuilder info   = new StringBuilder(260);
            int           handle = CRT310.CommOpen("COM" + port);

            try
            {
                //进卡控制
                CRT310.CRT310_CardSetting(handle, 0x3, 0x1);
                //停卡位置
                CRT310.CRT310_CardPosition(handle, 0x4);

                Byte atPosition   = new byte();
                Byte frontSetting = new byte();
                Byte rearSetting  = new byte();

                //读取状态
                int hasCard = CRT310.CRT310_GetStatus(handle, ref atPosition, ref frontSetting, ref rearSetting);//卡没插好,怎么办

                Byte   cpuType   = new byte();
                Byte[] exdata    = new byte[1024];
                int    exdataLen = 0;
                //CPU卡复位
                CRT310.CPU_ColdReset(handle, 0x0, ref cpuType, exdata, ref exdataLen);

                executeAPDU(handle, "00A40000023F00");

                executeAPDU(handle, "00A40000023F20");

                string cardNoSource = executeAPDU(handle, "00B0950000");
                //进卡控制
                CRT310.CRT310_CardSetting(handle, 0x1, 0x1);

                string result = DecryptCardNo(cardNoSource);
                return(result);
            }
            catch (Exception e)
            {
                throw new WtException(WtExceptionCode.Card.WT_READ_CARD, e.Message);
            }
            finally
            {
                //关闭端口
                CRT310.CommClose(handle);
            }
        }