【问题标题】:JPOS unpacking running exampleJPOS解包运行示例
【发布时间】:2016-10-17 09:21:04
【问题描述】:

我正在尝试使用 JPOS 库来打包/解包 ISO8583-1987 消息。

我的格式有问题,我在互联网上找不到任何运行示例。

谁能给我一个解包十六进制消息的运行示例,因为有很多关于 ASCII 消息的示例,但这不是我需要的。

感谢大家的时间和关注

朱利安

【问题讨论】:

  • 我不知道 jpos 是否有从十六进制字符串消息中解包的方法,但是您可以轻松编写一些方法 hexaStringToAscci 如果每个字节由两个十六进制表示,我可以帮助您字符。
  • 你好!!!我认为的问题是所有字段的格式不同,有些是 char,有些是数字,其他是位图值,我认为您不能将所有字段转换为 ASCII 值
  • 是的,你是对的。您可以将“hexa string”转换为 byte[] 十进制数组,然后您可以使用此值“解包”。如果你愿意,我可以用这个转换的例子来回答。

标签: iso8583 jpos


【解决方案1】:

我假设您有一个十六进制字符串表示字符串中的消息,在这种情况下您必须将其转换为字节数组。

例如,假设您将字符串作为 main 的参数。无论如何,您必须知道该十六进制表示中包含的 iso 消息的格式。例如,如果消息是二进制的,则必须选择 ISO87BPackager,如果是 ascii,则必须选择 ISO87APackager。

import org.jpos.iso.packager.ISO87BPackager;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOUtil;

public class ParseISOMsg {
    public static void main(String[] args) throws ISOException {
        String hexmsg = args[0];
        // convert hex string to byte array
        byte[] bmsg =ISOUtil.hex2byte(hexmsg);
        ISOMsg m = new ISOMsg();
        // set packager, change ISO87BPackager for the matching one.
        m.setPackager(new ISO87BPackager());
        //unpack the message using the packager
        m.unpack(bmsg);
        //dump the message to standar output
        m.dump(System.out, "");
    }
}

例如,如果您调用java -cp .:jpos.jar ParseISOMsg 080000200000008000001234563132333435363738,它应该会打印:

<isomsg>
    <!-- org.jpos.iso.packager.ISO87BPackager -->
    <field id="0" value="0800"/>
    <field id="11" value="123456"/>
    <field id="41" value="12345678"/>
</isomsg>

【讨论】:

    猜你喜欢
    • 2019-06-08
    • 2018-11-19
    • 1970-01-01
    • 2019-05-16
    • 2017-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-05
    相关资源
    最近更新 更多