Beispiel #1
0
        public int QPBOCReadRFCard(double dInAmount, Landi.FrameWorks.EMVTransProcess.PbocTransType pbocType)
        {
            int state = 0;

            byte[] answer         = new byte[128];
            int    pnLen          = 0;
            int    pnChipProtocol = 0;

            EMVInfo = new EMVData();
            long hand = 0;

            try
            {
                //pboc.App_EMVSetAidAndCAFileName("yl");
                hand = R80.GetHandle();
                pboc.App_EMV_ucSetAPDUInterface("CardReader.dll", "Card_ChipIO", "R80.dll", "EA_mifare_sICAppCMDTransfer");
                //pboc.App_EMVSetParam(, BankCardConfig.gBatchNo, "", BankCardConfig.gTerminalNo, BankCardConfig.gBranchNo);

                //pboc.App_EMV_ucSetAPDUInterface("CardReader.dll", "Card_ChipIO", "R80.dll", "Card_ChipIO");
                state = pboc.App_EMVLInit(PayType, hand);
                if (state != 0)
                {
                    Log.Warn("卡片初始化失败");
                    return(-1);
                }

                #region 获取卡片应用

                byte[] appList  = new byte[256];
                int    nListNum = 0;
                pboc.App_EMVL2SelectApp(pnChipProtocol, appList, ref nListNum);
                string[] strEmvList = System.Text.Encoding.Default.GetString(appList).Trim().Replace("\0", "").Split('|');
                if (nListNum < 1)
                {
                    Log.Warn("卡片无可用的应用");
                    return(-1);
                }

                byte[] inTrace       = Encoding.Default.GetBytes("000000");
                byte[] inDay         = Encoding.Default.GetBytes(DateTime.Now.ToString("yyMMdd"));
                byte[] inTime        = Encoding.Default.GetBytes(DateTime.Now.ToString("HHmmss"));
                byte[] inAmount      = Encoding.Default.GetBytes(Utility.AmountToString(dInAmount.ToString()));;
                byte[] inOtherAmount = Encoding.Default.GetBytes("000000000000");
                int    iAppId        = 1;
                bool   bEmvOk        = false;
                foreach (string tempEmv in strEmvList)
                {
                    //A000000333010101|银联
                    //if (!String.IsNullOrEmpty(tempEmv) && tempEmv.StartsWith("A000000333"))
                    //{
                    //    state = pboc.App_EMVStartEmvApp(iAppId, pnChipProtocol, (int)PbocTransType.PURCHASE, inTrace, inDay, inTime, inAmount, inOtherAmount);
                    //    if (state == 0)
                    //    {
                    //        bEmvOk = true;
                    //        break;
                    //    }
                    //}
                    state = pboc.App_EMVStartEmvApp(iAppId, pnChipProtocol, (int)pbocType, inTrace, inDay, inTime, inAmount, inOtherAmount);
                    if (state == 0 || state == 8)
                    {
                        bEmvOk = true;
                        gICAid = tempEmv;
                        break;
                    }
                    iAppId++;
                }
                if (!bEmvOk)
                {
                    Log.Warn("没有支持的应用");
                    return(-1);
                }

                #endregion

                #region 获取卡片卡号信息

                byte[] cardNo     = new byte[21];
                int    cardNoLen  = 0;
                byte[] track2     = new byte[38];
                int    track2Len  = 0;
                byte[] expData    = new byte[5];
                int    expLen     = 0;
                byte[] cardSeqNum = new byte[2];

                pboc.App_EMVGetCardNo(cardNo, ref cardNoLen, track2, ref track2Len, expData, ref expLen, cardSeqNum);
                EMVInfo.CardNum     = Encoding.Default.GetString(cardNo).Trim('\0');
                EMVInfo.Track2      = Encoding.Default.GetString(track2).Trim('\0');
                EMVInfo.CardSeqNum  = Convert.ToString(cardSeqNum[0]).Trim('\0');
                EMVInfo.CardExpDate = Encoding.Default.GetString(expData).Trim('\0');
                if (String.IsNullOrEmpty(EMVInfo.CardNum))
                {
                    Log.Warn("IC:读卡号失败");
                    return(-1);
                }
                else
                {
                    EMVInfo.CardNum = EMVInfo.CardNum.Replace('\0', ' ').Trim();
                }
                #endregion

                #region 获取55域

                //byte[] field55 = new byte[512];
                //int field55Len = 0;
                ////6 App_EMVGetField55
                //pboc.App_EMVGetField55(field55, ref field55Len);
                //EMVInfo.SendField55 = new byte[field55Len];
                //Array.Copy(field55, EMVInfo.SendField55, field55Len);
                EMVInfo.SendField55 = GetField55(pboc, 0);
                #endregion
            }
            catch (Exception ex)
            {
                Log.Error("IC:初始化异常", ex);
                return(-1);
            }
            return(0);
        }