/// <summary> /// 获取应用标识符 /// </summary> /// <returns></returns> public void GetAID(ICCard card) { string result = CardReader.SendAPDU(APDUCommand.GETDATA); List <TLVEntity> tlvList = TLVHelper.ToTLVEntityList(result); var entity = TLVHelper.GetValueByTag(tlvList, EMVTag.AID); if (entity == null) { throw new CardReadException("获取不到卡片的应用标识符!"); } card.AID = CodeConvert.ToHexString(entity.Value); }
/// <summary> /// 获取处理选项数据对象列表(PDOL) /// </summary> /// <returns></returns> public void GetPDOL(ICCard card) { string aid = card.AID; APDUEntity apdu = new APDUEntity("00", APDU_INS.SELECT, "04", "00", string.Format("{0}{1}", (aid.Length / 2).ToString("x2"), aid)); string result = CardReader.SendAPDU(apdu.ToString()); List <TLVEntity> tlvList = TLVHelper.ToTLVEntityList(result); var entity = TLVHelper.GetValueByTag(tlvList, EMVTag.PDOL); if (entity == null) { throw new CardReadException("获取不到卡片的处理选项数据对象列表!"); } card.GPOL = CodeConvert.ToTLStringList(entity.Value); }
/// <summary> /// 发卡行外部认证 /// </summary> /// <param name="data"></param> /// <returns></returns> public bool IssueBankAuthenticate(string data) { //支付成功获取发卡行返回的55域数据 byte[] part55Data = CodeConvert.HexStringToByteArray(data); List <TLVEntity> tlvList = TLVPackage.Construct(part55Data); TLVEntity entity = TLVHelper.GetValueByTag(tlvList, "91");//获取发卡行认证数据 if (entity != null) { APDUEntity apdu = new APDUEntity("00", "82", "00", "00", CodeConvert.ToHexString(entity.Length) + CodeConvert.ToHexString(entity.Value)); string result = CardReader.SendAPDU(apdu.ToString()); return(true);// result.Equals(StatusCode.Success) == result.Equals(StatusCode.Authenticated); } else { return(true); } }
/// <summary> /// 获取所有应用文件的数据 /// </summary> /// <param name="card">卡片</param> /// <returns></returns> public List <TLVEntity> GetData(ICCard card) { List <TLVEntity> tlvList = new List <TLVEntity>(); List <string> dataList = new List <string>(); card.AFL.ToList().ForEach(af => GetDataBySF(dataList, af)); foreach (string data in dataList) { tlvList.AddRange(TLVHelper.ToTLVEntityList(data)); } //card.AppFileDataList = tlvList; //卡号 card.CardNo = CodeConvert.ToHexString(TLVHelper.GetValueByTag(tlvList, EMVTag.PAN).Value).Replace("F", ""); //序列号 858323域使用 card.PANSerialNum = CodeConvert.ToHexString(TLVHelper.GetValueByTag(tlvList, EMVTag.PANSerialNum).Value); card.AppVersionNo = CodeConvert.ToHexString(TLVHelper.GetValueByTag(tlvList, EMVTag.AppVersionNo).Value); //应用版本号 string msg2 = CodeConvert.ToHexString(TLVHelper.GetValueByTag(tlvList, EMVTag.Msg2).Value); //等价2磁道数据 msg2 = msg2.ToUpper().Replace("D", "="); //有些银行为对为D的情况做处理 if (msg2.EndsWith("F")) { msg2 = msg2.Substring(0, msg2.Length - 1); } if (msg2.StartsWith(card.CardNo + "=")) { string dateString = msg2.Split('=')[1].Substring(0, 4); dateString = string.Format("{0}-{1}-{2}", "20" + dateString.Substring(0, 2), dateString.Substring(2, 2), "01"); card.EffectiveDate = Convert.ToDateTime(dateString); } card.Msg2 = msg2;//等价2磁道数据 //卡风险管理数据对象列表1 用于获取应用密文 card.CDOL1 = CodeConvert.ToTLStringList(TLVHelper.GetValueByTag(tlvList, EMVTag.CDOL1).Value); card.CDOL2 = CodeConvert.ToTLStringList(TLVHelper.GetValueByTag(tlvList, EMVTag.CDOL2).Value); var proid = TLVHelper.GetValueByTag(tlvList, EMVTag.ProductId); if (proid != null) { card.ProductId = CodeConvert.ToHexString(proid.Value); } return(tlvList); }