public void TestMessageNotExtendedUnpack() { var mtid = Encoding.ASCII.GetBytes("0200"); var bitmap = new Bitmap(); bitmap[2] = true; bitmap[3] = true; var bitmapData = bitmap.ToMsg(); var msgContent = Encoding.ASCII.GetBytes("1758889290122738116270010"); var fullMessageLength = 4 + bitmapData.Length + msgContent.Length; var raw = new byte[fullMessageLength]; Array.Copy(mtid, raw, 4); Array.Copy(bitmapData, 0, raw, 4, bitmapData.Length); Array.Copy(msgContent, 0, raw, 4 + bitmapData.Length, msgContent.Length); var msg = new Iso8583(); var offset = msg.Unpack(raw, 0); Assert.AreEqual(fullMessageLength, offset, "The offset for the message is incorrect"); Assert.AreEqual(true, msg.IsFieldSet(2), "Expected field 2"); Assert.AreEqual("58889290122738116", msg[2], "Expected field 2 value 58889290122738116"); Assert.AreEqual(true, msg.IsFieldSet(3), "Expected field 3"); Assert.AreEqual("270010", msg[3], "Expected field 3 value 270010"); }
public void TestIso8583PostTemplateAuthIdResponse() { var iso8583Post = new Iso8583Post(); iso8583Post.MessageType = Iso8583.MsgType._0200_TRAN_REQ; iso8583Post[Iso8583.Bit._003_PROC_CODE] = "000000"; iso8583Post[Iso8583.Bit._037_RETRIEVAL_REF_NUM] = "123456789012"; iso8583Post[Iso8583.Bit._038_AUTH_ID_RESPONSE] = "12 abc"; var rawBytes = iso8583Post.ToMsg(); Assert.IsNotNull(rawBytes); var iso8583 = new Iso8583(); FieldFormatException expected = null; try { iso8583.Unpack(rawBytes, 0); } catch (FieldFormatException ffe) { expected = ffe; } Assert.IsNotNull(expected); Assert.AreEqual(Iso8583.Bit._038_AUTH_ID_RESPONSE, expected.FieldNumber); }
public PayResponseModel Query(byte[] preMsg, string mac) { Iso8583 Result = new Iso8583(); //Send(preMsg,mac,out Result); return(Send(preMsg, mac, out Result)); }
public void TestIso8583PostTemplateEchoData() { var iso8583Post = new Iso8583Post(); iso8583Post.MessageType = Iso8583.MsgType._0200_TRAN_REQ; iso8583Post[Iso8583.Bit._003_PROC_CODE] = "000000"; iso8583Post[Iso8583.Bit._037_RETRIEVAL_REF_NUM] = "123456789012"; iso8583Post[Iso8583.Bit._038_AUTH_ID_RESPONSE] = "123456"; iso8583Post[Iso8583Post.Bit._059_ECHO_DATA] = "Echo Data"; var rawBytes = iso8583Post.ToMsg(); Assert.IsNotNull(rawBytes); var iso8583 = new Iso8583(); UnknownFieldException expected = null; try { iso8583.Unpack(rawBytes, 0); } catch (UnknownFieldException e) { expected = e; } Assert.IsNotNull(expected); Assert.AreEqual("59", expected.FieldNumber); }
/// <summary> /// 签到获取密钥 /// </summary> /// <returns></returns> public SignResponseModel Sign(VisualSelfServiceEquipment equipment) { Bitmap map = new Bitmap(); map[11] = map[41] = map[42] = map[60] = map[63] = true; Iso8583 iso8583 = new Iso8583(map); iso8583[11].Content = Settings.SysTraceNum; Settings.SysTraceNum = (Convert.ToInt32(Settings.SysTraceNum) + 1).ToString().PadLeft(6, '0'); iso8583[41].Content = equipment.TerminalNo;// Settings.TerminalNo; iso8583[42].Content = Settings.MerchantCode; iso8583[60].FieldLenIndicator.Content = "011"; iso8583[60].Content = "00003010003"; iso8583[63].FieldLenIndicator.Content = "003"; iso8583[63].Content = "001"; Message msg = new Message(iso8583); msg.TPDU.Content = Settings.TPDU; msg.MessageHead.Content = Settings.MsgHead; msg.MessageType.Content = "0800"; Iso8583 Res_iso8583 = new Iso8583(); Message Res_Msg = new Message(Res_iso8583); Res_Msg.Unpack(msg.Send(Settings.BankIp, Convert.ToInt32(Settings.BankPort))); SignResponseModel responseModel = new SignResponseModel() { ResponseCode = Res_iso8583[39].Content }; if (responseModel.ResponseCode == "00") { responseModel.Content = BitConverter.ToString(Res_iso8583[62].Pack()).Replace("-", ""); } return(responseModel); }
public void TestMessageExtendedPack() { var msg = new Iso8583(); msg[2] = "58889212354567816"; msg[3] = "270010"; msg[102] = "9012273811"; msg.MessageType = Iso8583.MsgType._0200_TRAN_REQ; var actual = msg.ToMsg(); var mtid = Encoding.ASCII.GetBytes("0200"); var bitmap = new Bitmap(); bitmap[2] = true; bitmap[3] = true; bitmap[102] = true; var bitmapData = bitmap.ToMsg(); var msgContent = Encoding.ASCII.GetBytes("1758889212354567816270010109012273811"); var fullMessageLength = 4 + bitmapData.Length + msgContent.Length; Assert.AreEqual(fullMessageLength, msg.PackedLength, "Incorrect packed length"); var expected = new byte[fullMessageLength]; Array.Copy(mtid, expected, 4); Array.Copy(bitmapData, 0, expected, 4, bitmapData.Length); Array.Copy(msgContent, 0, expected, 4 + bitmapData.Length, msgContent.Length); CollectionAssert.AreEqual(expected, actual); }
protected PayResponseModel Send(byte[] preMsg, string mac, out Iso8583 Res_iso8583) { Bitmap map = new Bitmap(); map[64] = true; Iso8583 iso8583 = new Iso8583(map); iso8583[64].Content = mac; iso8583[64].Pack().CopyTo(preMsg, preMsg.Length - 8); Res_iso8583 = new Iso8583(); Message Res_Msg = new Message(Res_iso8583); Res_Msg.Unpack(Utilities.Send(Settings.BankIp, Convert.ToInt32(Settings.BankPort), preMsg)); Settings.SysTraceNum = (Convert.ToInt32(Settings.SysTraceNum) >= 999999 ? 1 : Convert.ToInt32(Settings.SysTraceNum) + 1).ToString(); #region 组织返回数据 PayResponseModel resultModel = new PayResponseModel(); resultModel.ResponseCode = Res_iso8583[39].Content; resultModel.Pan = Res_iso8583[2].Content; resultModel.Money = Res_iso8583[4].Content; resultModel.TransactionSerialNum = Res_iso8583[11].Content; resultModel.TransactionTime = Res_iso8583[12].Content + Res_iso8583[13].Content; resultModel.ExtendInfo = Res_iso8583[54].Content; #endregion return(resultModel); }
public void TestNullAdditionalAmounts() { var msg = new Iso8583(); var addAmounts = msg.AdditionalAmounts; Assert.IsTrue(addAmounts == null); }
public void TestClearFieldThatIsNull() { var msg = new Iso8583(); msg.ClearField(2); Assert.IsNull(msg[2]); Assert.IsFalse(msg.IsFieldSet(2)); }
public void TestSettingNullClearsField() { var msg = new Iso8583(); msg[2] = "12345678912365"; msg[2] = null; Assert.IsNull(msg[2]); Assert.IsFalse(msg.IsFieldSet(2)); }
public void TestClearField() { var msg = new Iso8583(); msg[2] = "123456789123456"; msg.ClearField(2); Assert.AreEqual(false, msg.IsFieldSet(2)); Assert.AreEqual((object)null, msg[2]); }
public void TestAutoGenerateTransmissionDateTime() { var msg = new Iso8583(); var nowGmt = DateTime.Now.ToUniversalTime(); msg.TransmissionDateTime.SetNow(); var actual = msg[7]; var expected = nowGmt.ToString("MMddHHmmss"); Assert.AreEqual(expected, actual); }
public void TestGetAdditionalAmounts() { var msg = new Iso8583(); msg[54] = "1001840C0000000220001002840C000000022000"; var amounts = msg.AdditionalAmounts; foreach (var amount in amounts) { Assert.IsNotNull(amount); } }
public byte[] Query(string terminalNo, string pinBlock, CreditCard creditCard) { ICCard Card = creditCard as ICCard; if (Card == null) { throw new ArgumentException("无效的卡片"); } Bitmap map = new Bitmap(); map[2] = map[3] = map[11] = map[22] = map[25] = map[26] = map[35] = map[41] = map[42] = map[49] = map[52] = map[53] = map[60] = map[64] = true; Iso8583 iso8583 = new Iso8583(map); iso8583[2].FieldLenIndicator.Content = (Card.CardNo.Length / 2).ToString(); iso8583[2].Content = Card.CardNo; iso8583[3].Content = "310000"; iso8583[11].Content = Settings.SysTraceNum; iso8583[22].Content = "021"; iso8583[25].Content = "00"; iso8583[26].Content = "06"; iso8583[35].FieldLenIndicator.Content = (Card.Msg2.Length / 2).ToString(); iso8583[35].Content = Card.Msg2; iso8583[41].Content = terminalNo; iso8583[42].Content = Settings.MerchantCode; iso8583[49].Content = "156"; iso8583[52].Content = pinBlock; iso8583[53].Content = "26"; iso8583[60].FieldLenIndicator.Content = "011"; iso8583[60].Content = "00003010003"; iso8583[64].Content = "1111111111111111"; Message msg = new Message(iso8583); msg.TPDU.Content = Settings.TPDU; msg.MessageHead.Content = Settings.MsgHead; msg.MessageType.Content = "0200"; StringBuilder mac = new StringBuilder(); byte[] subMsg = msg.Pack(); return(subMsg); }
/// <summary> /// 冲正预处理 /// </summary> /// <param name="preMsg">原始交易</param> /// <param name="creditCard">银行卡信息></param> /// <returns></returns> public byte[] Correct(byte[] preMsg, CreditCard creditCard) { Iso8583 Pre_iso8583 = new Iso8583(); Message Pre_Msg = new Message(Pre_iso8583); Pre_Msg.Unpack(preMsg); Bitmap map = new Bitmap(); map[2] = map[3] = map[4] = map[11] = map[22] = map[25] = map[35] = map[39] = map[41] = map[42] = map[49] =// map[52] = map[53] = map[60] = map[61] = map[64] = true; Iso8583 iso8583 = new Iso8583(map); iso8583[2].FieldLenIndicator.Content = (Pre_iso8583[2].Content.Length / 2).ToString(); iso8583[2].Content = Pre_iso8583[2].Content; iso8583[3].Content = Pre_iso8583[3].Content; iso8583[4].Content = Pre_iso8583[4].Content; iso8583[11].Content = Pre_iso8583[11].Content; iso8583[22].Content = Pre_iso8583[22].Content; iso8583[25].Content = Pre_iso8583[25].Content; iso8583[35].FieldLenIndicator.Content = (Pre_iso8583[35].Content.Length / 2).ToString(); iso8583[35].Content = Pre_iso8583[35].Content; iso8583[39].Content = "06"; iso8583[41].Content = Pre_iso8583[41].Content; iso8583[42].Content = Pre_iso8583[42].Content; iso8583[49].Content = Pre_iso8583[49].Content; iso8583[60].FieldLenIndicator.Content = "019"; iso8583[60].Content = "2200301000020000000";////Pre_iso8583[60].Content; iso8583[61].FieldLenIndicator.Content = "016"; iso8583[61].Content = string.Format("{0}{1}{2}", Pre_iso8583[11].Content, "003010", DateTime.Now.ToString("MMDD")); iso8583[64].Content = "1111111111111111"; Message msg = new Message(iso8583); msg.TPDU.Content = Settings.TPDU; msg.MessageHead.Content = Settings.MsgHead; msg.MessageType.Content = "0400"; byte[] subMsg = msg.Pack(); return(subMsg); }
protected PayResponseModel Send(byte[] preMsg, string mac) { Bitmap map = new Bitmap(); map[64] = true; Iso8583 iso8583 = new Iso8583(map); iso8583[64].Content = mac; iso8583[64].Pack().CopyTo(preMsg, preMsg.Length - 8); Iso8583 Res_iso8583 = new Iso8583(); Message Res_Msg = new Message(Res_iso8583); Res_Msg.Unpack(Utilities.Send(Settings.BankIp, Convert.ToInt32(Settings.BankPort), preMsg)); Settings.SysTraceNum = (Convert.ToInt32(Settings.SysTraceNum) >= 999999 ? 1 : Convert.ToInt32(Settings.SysTraceNum) + 1).ToString(); #region 组织返回数据 PayResponseModel resultModel = new PayResponseModel(); resultModel.ResponseCode = Res_iso8583[39].Content; resultModel.Pan = Res_iso8583[2].Content; resultModel.Money = Res_iso8583[4].Content; resultModel.TransactionSerialNum = Res_iso8583[11].Content; string transactionTimeStr = Res_iso8583[13].Content + Res_iso8583[12].Content; resultModel.TransactionTime = string.Format("{0}-{1}-{2} {3}:{4}:{5}", DateTime.Now.Date.Year.ToString(), transactionTimeStr.Substring(0, 2), transactionTimeStr.Substring(2, 2), transactionTimeStr.Substring(4, 2), transactionTimeStr.Substring(6, 2), transactionTimeStr.Substring(8, 2)); if (Res_iso8583.Keys.Contains(38)) { //附加数据 //假如38域授权码存在时返回 resultModel.ExtendInfo = string.Format("{0},{1}", Res_iso8583[37].Content, Res_iso8583[38].Content); } else { //假如38域不存在则只返回37域交易参考号用于撤销交易 resultModel.ExtendInfo = string.Format("{0}", Res_iso8583[37].Content); } #endregion return(resultModel); }
public void Setup() { _origMsg = new Iso8583 { MessageType = Iso8583.MsgType._0200_TRAN_REQ }; _origMsg[3] = "090000"; var header = new TwoByteHeader(); _packedData = header.Pack(_origMsg); var headerData = new byte[header.HeaderLength]; Array.Copy(_packedData, 0, headerData, 0, header.HeaderLength); int newOffset; var msgLength = header.GetMessageLength(headerData, 0, out newOffset); _unpackedMsg = new Iso8583(); // Doing this will test that get message length works correctly _unpackedMsg.Unpack(_packedData, _packedData.Length - msgLength); }
public void TestMessageNotExtendedPack() { var msg = new Iso8583(); msg[2] = "58889290122738116"; msg[3] = "270010"; msg.MessageType = Iso8583.MsgType._0200_TRAN_REQ; var actual = msg.ToMsg(); var mtid = Encoding.ASCII.GetBytes("0200"); var bitmap = new Bitmap(); bitmap[2] = true; bitmap[3] = true; var bitmapData = bitmap.ToMsg(); var msgContent = Encoding.ASCII.GetBytes("1758889290122738116270010"); var fullMessageLength = 4 + bitmapData.Length + msgContent.Length; var expected = new byte[fullMessageLength]; Array.Copy(mtid, expected, 4); Array.Copy(bitmapData, 0, expected, 4, bitmapData.Length); Array.Copy(msgContent, 0, expected, 4 + bitmapData.Length, msgContent.Length); Assert.AreEqual(fullMessageLength, msg.PackedLength, "Incorrect packed length"); var equal = true; for (var i = 0; i < fullMessageLength; i++) { equal &= expected[i] == actual[i]; } Assert.AreEqual(true, equal, "Messages not equal"); }
/// <summary> /// 撤销 /// </summary> /// <param name="preMsg">原始交易</param> /// <param name="creditCard">银行卡信息></param> /// <returns></returns> public byte[] CancelPay(byte[] preMsg, CreditCard creditCard, string posSerialNo) { Iso8583 Pre_iso8583 = new Iso8583(); Message Pre_Msg = new Message(Pre_iso8583); Pre_Msg.Unpack(preMsg); string[] extendData = posSerialNo.Split(','); string posserialNo = extendData[0]; string AuthorizationCode = extendData.Length > 1 ? extendData[1] : null; Bitmap map = new Bitmap(); map[2] = map[3] = map[4] = map[11] = map[22] = map[25] = map[26] = map[35] = map[37] = map[41] = map[42] = map[49] = map[52] = map[53] = map[60] = map[61] = map[64] = true; if (!string.IsNullOrEmpty(AuthorizationCode)) { map[38] = true; } Iso8583 iso8583 = new Iso8583(map); iso8583[2].FieldLenIndicator.Content = (Pre_iso8583[2].Content.Length / 2).ToString(); iso8583[2].Content = Pre_iso8583[2].Content; iso8583[3].Content = "200000";//Pre_iso8583[3].Content; iso8583[4].Content = Pre_iso8583[4].Content; iso8583[11].Content = Settings.SysTraceNum; iso8583[22].Content = Pre_iso8583[22].Content; iso8583[25].Content = Pre_iso8583[25].Content; iso8583[26].Content = Pre_iso8583[26].Content; iso8583[35].FieldLenIndicator.Content = (Pre_iso8583[35].Content.Length / 2).ToString(); iso8583[35].Content = Pre_iso8583[35].Content; iso8583[37].Content = posserialNo; if (!string.IsNullOrEmpty(AuthorizationCode)) { iso8583[38].Content = AuthorizationCode; } iso8583[41].Content = Pre_iso8583[41].Content; iso8583[42].Content = Pre_iso8583[42].Content; iso8583[49].Content = Pre_iso8583[49].Content; iso8583[52].Content = Pre_iso8583[52].Content; iso8583[53].Content = Pre_iso8583[53].Content; iso8583[60].FieldLenIndicator.Content = "019"; iso8583[60].Content = "2200301000020000000";////Pre_iso8583[60].Content; iso8583[61].FieldLenIndicator.Content = "016"; iso8583[61].Content = string.Format("{0}{1}{2}", "003010", Pre_iso8583[11].Content, DateTime.Now.ToString("MMdd")); iso8583[64].Content = "1111111111111111"; Message msg = new Message(iso8583); msg.TPDU.Content = Settings.TPDU; msg.MessageHead.Content = Settings.MsgHead; msg.MessageType.Content = "0200"; byte[] subMsg = msg.Pack(); return(subMsg); }
public byte[] Correct(byte[] preMsg, CreditCard creditCard) { ICCard Card = creditCard as ICCard; if (Card == null) { throw new ArgumentException("无效的卡片"); } Iso8583 pre_iso8583 = new Iso8583(); Message pre_Msg = new Message(pre_iso8583); pre_Msg.Unpack(preMsg); Bitmap map = new Bitmap(); map[2] = map[3] = map[4] = map[11] = map[22] = map[23] = map[25] = map[39] = map[41] = map[42] = map[49] = map[55] = map[60] = map[61] = map[64] = true; Iso8583 iso8583 = new Iso8583(map); iso8583[2].FieldLenIndicator.Content = (pre_iso8583[2].Content.Length / 2).ToString(); iso8583[2].Content = pre_iso8583[2].Content; iso8583[3].Content = pre_iso8583[3].Content; iso8583[4].Content = pre_iso8583[4].Content; iso8583[11].Content = pre_iso8583[11].Content; iso8583[22].Content = pre_iso8583[22].Content; iso8583[23].Content = pre_iso8583[23].Content; iso8583[25].Content = pre_iso8583[25].Content; iso8583[39].Content = "06"; iso8583[41].Content = pre_iso8583[41].Content; iso8583[42].Content = pre_iso8583[42].Content; iso8583[49].Content = pre_iso8583[49].Content; //iso8583[52].Content = pre_iso8583[52].Content; //iso8583[53].Content = pre_iso8583[53].Content; iso8583[55].Content = string.Format("9F3602{0}", Card.ATC); iso8583[55].FieldLenIndicator.Content = string.Format("{0:000}", (iso8583[55].Content.Length / 2)); iso8583[60].FieldLenIndicator.Content = "019"; iso8583[60].Content = "2200002900050000000"; iso8583[61].FieldLenIndicator.Content = "016"; iso8583[61].Content = string.Format("{0}{1}{2}", pre_iso8583[11].Content, "000029", DateTime.Now.ToString("MMDD")); iso8583[64].Content = "1111111111111111"; Message msg = new Message(iso8583); msg.TPDU.Content = Settings.TPDU; msg.MessageHead.Content = Settings.MsgHead; msg.MessageType.Content = "0400"; StringBuilder mac = new StringBuilder(); byte[] subMsg = msg.Pack(); return(subMsg); }
/// <summary> /// 撤销预处理 /// </summary> /// <param name="preMsg">原始交易</param> /// <param name="creditCard">银行卡信息></param> /// <returns></returns> public byte[] CancelPay(byte[] preMsg, CreditCard creditCard, string posSerialNo) { Iso8583 Pre_iso8583 = new Iso8583(); Message Pre_Msg = new Message(Pre_iso8583); Pre_Msg.Unpack(preMsg); string[] extendData = posSerialNo.Split(','); string posserialNo = extendData[0]; string AuthorizationCode = extendData.Length > 1 ? extendData[1] : null; string preSysTraceNum = Pre_iso8583[11].Content; Bitmap map = new Bitmap(); map[3] = map[4] = map[11] = map[22] = map[25] = map[26] = map[35] = map[37] = map[41] = map[42] = map[49] = map[52] = map[53] = map[60] = map[61] = map[64] = true; if (!string.IsNullOrEmpty(AuthorizationCode)) { map[38] = true; } Iso8583 iso8583 = new Iso8583(map); if (Settings.SysTraceNum.Equals(preSysTraceNum)) { Settings.SysTraceNum = (Convert.ToInt32(Settings.SysTraceNum) + 1).ToString(); } iso8583[3].Content = "200000"; iso8583[4].Content = Pre_iso8583[4].Content; iso8583[11].Content = Settings.SysTraceNum; iso8583[22].Content = "022"; iso8583[25].Content = "00"; iso8583[26].Content = Pre_iso8583[26].Content; iso8583[35].FieldLenIndicator.Content = creditCard.Msg2.Length.ToString(); iso8583[35].Content = creditCard.Msg2; iso8583[37].Content = posserialNo; if (!string.IsNullOrEmpty(AuthorizationCode)) { iso8583[38].Content = AuthorizationCode; } iso8583[41].Content = Pre_iso8583[41].Content; iso8583[42].Content = Settings.MerchantCode; iso8583[49].Content = "156"; iso8583[52].Content = Pre_iso8583[52].Content; iso8583[53].Content = "2610000000000000"; iso8583[60].FieldLenIndicator.Content = "013"; iso8583[60].Content = string.Format("23{0}00050", Settings.BatchNo); iso8583[61].FieldLenIndicator.Content = "012"; iso8583[61].Content = string.Format("{0}{1}", Settings.BatchNo, preSysTraceNum); iso8583[64].Content = "1111111111111111"; Message msg = new Message(iso8583); msg.TPDU.Content = Settings.TPDU; msg.MessageHead.Content = Settings.MsgHead; msg.MessageType.Content = "0200"; byte[] subMsg = msg.Pack(); return(subMsg); }
/// <summary> /// 撤销预处理 /// </summary> /// <param name="preMsg">原始交易</param> /// <param name="creditCard">银行卡信息></param> /// <returns></returns> public byte[] CancelPay(byte[] preMsg, CreditCard creditCard, string posSerialNo) { Iso8583 pre_iso8583 = new Iso8583(); Message Pre_Msg = new Message(pre_iso8583); Pre_Msg.Unpack(preMsg); string[] extendData = posSerialNo.Split(','); string posserialNo = extendData[0]; string AuthorizationCode = extendData.Length > 1 ? extendData[1] : null; string preSysTraceNum = pre_iso8583[11].Content; Bitmap map = new Bitmap(); map[2] = map[3] = map[4] = map[11] = map[22] = map[25] = map[35] = map[37] = map[39] = map[41] = map[42] = map[49] = map[52] = map[53] = map[60] = map[64] = true; if (!string.IsNullOrEmpty(AuthorizationCode)) { map[38] = true; } Iso8583 iso8583 = new Iso8583(map); iso8583[2].FieldLenIndicator.Content = creditCard.CardNo.Length.ToString(); iso8583[2].Content = creditCard.CardNo; iso8583[3].Content = pre_iso8583[3].Content; iso8583[4].Content = pre_iso8583[4].Content; iso8583[11].Content = pre_iso8583[11].Content; iso8583[22].Content = pre_iso8583[22].Content; iso8583[25].Content = pre_iso8583[25].Content; iso8583[35].FieldLenIndicator.Content = creditCard.Msg2.Length.ToString(); iso8583[35].Content = creditCard.Msg2; iso8583[37].Content = posserialNo; iso8583[39].Content = "06"; if (!string.IsNullOrEmpty(AuthorizationCode)) { iso8583[38].Content = AuthorizationCode; } iso8583[41].Content = pre_iso8583[41].Content; iso8583[42].Content = pre_iso8583[42].Content; iso8583[49].Content = pre_iso8583[49].Content; iso8583[52].Content = pre_iso8583[52].Content; iso8583[53].Content = pre_iso8583[53].Content; iso8583[60].FieldLenIndicator.Content = "019"; iso8583[60].Content = pre_iso8583[60].Content; iso8583[64].Content = "1111111111111111"; Message msg = new Message(iso8583); msg.TPDU.Content = Settings.TPDU; msg.MessageHead.Content = Settings.MsgHead; msg.MessageType.Content = "0400"; byte[] subMsg = msg.Pack(); return(subMsg); }
public byte[] Pay(string terminalNo, string PayMoney, string pinBlock, CreditCard creditCard) { ICCard Card = creditCard as ICCard; if (Card == null) { throw new ArgumentException("无效的卡片"); } Bitmap map = new Bitmap(); map[2] = map[3] = map[4] = map[11] = map[14] = map[22] = map[23] = map[25] = map[26] = map[35] = map[41] = map[42] = map[49] = map[52] = map[53] = map[55] = map[60] = map[64] = true; Iso8583 iso8583 = new Iso8583(map); iso8583[2].FieldLenIndicator.Content = Card.CardNo.Length.ToString(); iso8583[2].Content = Card.CardNo; iso8583[3].Content = "000000"; iso8583[4].Content = PayMoney; iso8583[11].Content = Settings.SysTraceNum; iso8583[14].Content = Card.EffectiveDate.ToString("yyMM"); //有效日期 iso8583[22].Content = "051"; //IC卡支付 iso8583[23].Content = Card.PANSerialNum.PadLeft(4, '0'); iso8583[25].Content = "00"; iso8583[26].Content = "06"; iso8583[35].FieldLenIndicator.Content = Card.Msg2.Length.ToString(); iso8583[35].Content = Card.Msg2; iso8583[41].Content = terminalNo; iso8583[42].Content = Settings.MerchantCode; iso8583[49].Content = "156"; iso8583[52].Content = pinBlock; iso8583[53].Content = "26"; iso8583[55].Content = Card.BuildPart55Data(terminalNo, TransactionType.Pay, PayMoney, Settings.SysTraceNum); iso8583[55].FieldLenIndicator.Content = string.Format("{0:000}", (iso8583[55].Content.Length / 2)); iso8583[60].FieldLenIndicator.Content = "019"; iso8583[60].Content = string.Format("22{0}00050000000", Settings.BatchNo); iso8583[64].Content = "1111111111111111"; Message msg = new Message(iso8583); msg.TPDU.Content = Settings.TPDU; msg.MessageHead.Content = Settings.MsgHead; msg.MessageType.Content = "0200"; StringBuilder mac = new StringBuilder(); byte[] subMsg = msg.Pack(); return(subMsg); }
public byte[] CancelPay(byte[] preMsg, CreditCard creditCard, string posSerialNo) { ICCard Card = creditCard as ICCard; if (Card == null) { throw new ArgumentException("无效的卡片"); } Iso8583 pre_iso8583 = new Iso8583(); Message pre_Msg = new Message(pre_iso8583); pre_Msg.Unpack(preMsg); string[] extendData = posSerialNo.Split(','); string posserialNo = extendData[0]; string AuthorizationCode = extendData.Length > 1 ? extendData[1] : null; string preSysTraceNum = pre_iso8583[11].Content; if (Settings.SysTraceNum.Equals(preSysTraceNum)) { Settings.SysTraceNum = (Convert.ToInt32(Settings.SysTraceNum) + 1).ToString(); } Bitmap map = new Bitmap(); map[3] = map[4] = map[11] = map[14] = map[22] = map[23] = map[25] = map[26] = map[35] = map[37] = map[41] = map[42] = map[49] = map[52] = map[53] = map[55] = map[60] = map[61] = map[64] = true; if (!string.IsNullOrEmpty(AuthorizationCode)) { map[38] = true; } Iso8583 iso8583 = new Iso8583(map); iso8583[3].Content = "200000"; iso8583[4].Content = pre_iso8583[4].Content; iso8583[11].Content = Settings.SysTraceNum; iso8583[14].Content = Card.EffectiveDate.ToString("yyMM");//有效日期 iso8583[22].Content = pre_iso8583[22].Content; iso8583[23].Content = pre_iso8583[23].Content; iso8583[25].Content = pre_iso8583[25].Content; iso8583[26].Content = pre_iso8583[26].Content; iso8583[35].FieldLenIndicator.Content = Card.Msg2.Length.ToString(); iso8583[35].Content = Card.Msg2; iso8583[37].Content = posserialNo; if (!string.IsNullOrEmpty(AuthorizationCode)) { iso8583[38].Content = AuthorizationCode; } iso8583[41].Content = pre_iso8583[41].Content; iso8583[42].Content = pre_iso8583[42].Content; iso8583[49].Content = pre_iso8583[49].Content; iso8583[52].Content = pre_iso8583[52].Content; iso8583[53].Content = pre_iso8583[53].Content; iso8583[55].Content = string.Format("9F3602{0}", Card.ATC); iso8583[55].FieldLenIndicator.Content = string.Format("{0:000}", (iso8583[55].Content.Length / 2)); iso8583[60].FieldLenIndicator.Content = "013"; iso8583[60].Content = string.Format("23{0}00050", Settings.BatchNo); iso8583[61].FieldLenIndicator.Content = "012"; iso8583[61].Content = string.Format("{0}{1}", Settings.BatchNo, preSysTraceNum); iso8583[64].Content = "1111111111111111"; Message msg = new Message(iso8583); msg.TPDU.Content = Settings.TPDU; msg.MessageHead.Content = Settings.MsgHead; msg.MessageType.Content = "0200"; StringBuilder mac = new StringBuilder(); byte[] subMsg = msg.Pack(); return(subMsg); }
static void Main(string[] args) { ISO8583 isolocal = new ISO8583(); string[] DE = new string[130]; string MTI = "0110"; DE[3] = "010000"; DE[4] = "000000010000"; DE[39] = "010000"; DE[62] = "5656565656"; //TOKEN DE[63] = @"D|BN|BENI\D|CB|COCHABAMBA\D|CH|CHUQUISACA\D|LP|LA PAZ\D|OR|ORURO\D|PN|PANDO\D|PT|POTOSI\D|SC|SANTA CRUZ\D|TJ|TARIJA\U|1|PARTICULAR\U|2|PUBLICO\U|3|EJERCITO\U|4|POLICIA\U|5|OFICIAL\V|1|MOTOCICLETA\V|2|AUTOMOVIL\V|3|JEEP\V|4|CAMIONETA\V|5|VAGONETA\V|6|MICROBUS\V|7|COLECTIVO\V|8|OMNIBUS/FLOTA(MAS DE 39 oc)\V|9|TRACTO CAMION\V|10|MINIBUS(8 OCUPANTES)\V|11|MINIBUS(11 OCUPANTES)\V|12|MINIBUS(15 OCUPANTES)\V|13|CAMION(3 OCUPANTES)\V|14|CAMION(18 OCUPANTES)\V|15|CAMION(25 OCUPANTES)\"; string nonASCII = ""; string headerHex = "00d06000000233"; string resMensaje = isolocal.BuildCustomISO(DE, MTI, out nonASCII); string finalMensaje = headerHex + resMensaje; byte[] message = new byte[] { 0x02, 0x00, 0x80, 0x38, 0x00, 0x01, 0x02, 0xC1, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x43, 0x21, 0x13, 0x58, 0x40, 0x04, 0x19, 0x31, 0x31, 0x00, 0x08, 0x76, 0x54, 0x32, 0x1F, 0x30, 0x30, 0x38, 0x34, 0x30, 0x37, 0x31, 0x32, 0x33, 0x34, 0x37, 0x37, 0x37, 0x30, 0x30, 0x30, 0x31, 0x32, 0x33, 0x32, 0x31, 0x32, 0x33, 0x32, 0x31, 0x30, 0x30, 0x38, 0x8C, 0xA0, 0xA6, 0x42, 0x0C, 0x5C, 0xA6, 0x28, 0x01, 0x23 }; // Parse the bytes into an instance of the message class //string messageHex = "003460023303CB01002000000000000006010000001731323334353637382F313233343536373800133139322E3136382E31312E393400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; string messageHex = "01002000000000000006010000001731323334353637382F313233343536373800133139322E3136382E31312E393400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; // Translate the passed message into ASCII and store it as a byte array. Byte[] data = new Byte[1024]; data = System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary.Parse(messageHex).Value; OpenIso8583Net.Iso8583 iso = new Iso8583(); iso.Unpack(data, 0); Console.Write(iso[62]); Console.Write(iso[63]); Console.WriteLine("Press a key"); /* * byte[] MTI100 = new byte[] { 0, 1 }; * byte[] MTI200 = new byte[] { 0, 2 }; * Console.WriteLine(BitConverter.ToString(MTI100).Replace("-", string.Empty)); * Console.WriteLine(BitConverter.ToString(MTI200).Replace("-", string.Empty)); * * Console.WriteLine(Encoding.ASCII.GetString(MTI100)); * Console.WriteLine(Encoding.ASCII.GetString(MTI200)); * * //ISO8583 isolocal=new ISO8583(); * //string[] test=isolocal.Parse("?4`3? ?????????01002000000000000006010000016USUARIO/PASSWORD015255.254.253.251"); * //string[] test = isolocal.Parse("01002000000000000006010000016USUARIO/PASSWORD015255.254.253.251"); */ Console.ReadLine(); }