Trx库中的ISO8583消息头

时间:2013-07-25 11:30:45

标签: c# iso8583 trx

我使用了Trx ISO 8583库。该库以HEX格式发送消息长度。但我需要发送4个字节的Ascii字符作为消息头。怎么做?

1 个答案:

答案 0 :(得分:1)

要更改邮件标题,您应该更改NboFrameLengthSink class在Trx => Communication => Sinks => NboFrameLengthSink.cs

在代码

下更改public void Send(PipelineContext context)函数
buffer.Write(true, _bytesInHeader == 2
                ? new[] {(byte) (length >> 8), (byte) length}
                : new[] {(byte) (length >> 24), (byte) (length >> 16), (byte) (length >> 8), (byte) (length)});

string ls_length;

ls_length = length.ToString("####").PadLeft(4,'0');

byte[] ascii = System.Text.Encoding.ASCII.GetBytes(ls_length);

buffer.Write(true, _bytesInHeader == 2
 ? new[] { (byte)(length >> 8), (byte)length }
 : ascii);

在函数public bool Receive(PipelineContext context)

代码

context.ExpectedBytes = ( header[0] << 24 ) | ( header[1] << 16 ) | ( header[2] << 8 ) | header[3];

chage to

context.ExpectedBytes = header[0] | header[1] | header[2] | header[3];

如果您需要在Ascii中发送消息,但需要将位图发送为HEX 请执行以下操作:

在 Iso8583Ascii1987.xml congif文件更改

<!-- Add first bitmap -->
<Invoke Name="Add">
  <Parameter Type="BitMapFieldFormatterFactory">
    <Property Name="FieldNumber" Value="0" />
    <Property Name="Description" Value="Primary bitmap" />
    <Property Name="Encoder" Reference="DataEncoderFactory" />
    <Property Name="LowerFieldNumber" Value="1" />
    <Property Name="UpperFieldNumber" Value="64" />
  </Parameter>
</Invoke>

<!-- Add secondary bitmap (field number 1) -->
<Invoke Name="Add">
  <Parameter Type="BitMapFieldFormatterFactory">
    <Property Name="FieldNumber" Value="1" />
    <Property Name="Description" Value="Secondary bitmap" />
    <Property Name="Encoder" Reference="DataEncoderFactory" />
    <Property Name="LowerFieldNumber" Value="65" />
    <Property Name="UpperFieldNumber" Value="128" />
  </Parameter>
</Invoke>