使用jpos api包装SUBFIELDS

时间:2017-03-27 16:06:48

标签: java iso8583 jpos

我正在尝试使用 jpos框架编写一个打包并解包 ISOMessage 的主程序。

问题是我的邮件包含一些子字段,例如字段48 ,并且我一直将其作为空值。

低于我的配置+主程序

打包程序

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE isopackager PUBLIC
        "-//jPOS/jPOS Generic Packager DTD 1.0//EN"
        "http://jpos.org/dtd/generic-packager-1.0.dtd">
<!-- ISO 8583:1993 (ASCII) field descriptions for GenericPackager -->

<isopackager>

    <isofield id="0" length="4" name="Message Type Indicator"
        class="org.jpos.iso.IFA_NUMERIC" />

    <isofield id="1" length="64" name="Bitmap" class="org.jpos.iso.IFA_BITMAP" />

    <isofield id="2" length="19" name="PRIMARY ACCOUNT NUMBER"
        class="org.jpos.iso.IFA_LLNUM" />

    <isofield id="3" length="6" name="PROCESSING CODE" class="org.jpos.iso.IFA_NUMERIC" />

    <isofield id="4" length="12" name="AMOUNT, TRANSACTION" class="org.jpos.iso.IFA_NUMERIC" />

    <isofield id="7" length="10" name="DATE AND TIME, TRANSMISSION"
        class="org.jpos.iso.IFA_NUMERIC" />

    <isofield id="11" length="6" name="Systems trace audit number"
        class="org.jpos.iso.IFA_NUMERIC" />

    <isofield id="12" length="6" name="Time, Local transaction"
        class="org.jpos.iso.IFA_NUMERIC" />

    <isofield id="13" length="4" name="Date, Local transaction"
        class="org.jpos.iso.IFA_NUMERIC" />

    <isofield id="14" length="4" name="Date, Expiration" class="org.jpos.iso.IFA_NUMERIC" />

    <isofield id="18" length="4" name="Merchant type" class="org.jpos.iso.IFA_NUMERIC" />

    <isofield id="22" length="4" name="Point of service entry mode code"
        class="org.jpos.iso.IFA_NUMERIC" />

    <isofield id="25" length="2" name="POS Condition code" class="org.jpos.iso.IFA_NUMERIC" ></isofield>

    <isofield id="41" length="8"
        name="Card acceptor terminal identification" class="org.jpos.iso.IF_CHAR" ></isofield>

    <isofield id="42" length="15" name="Card acceptor identification code"
        class="org.jpos.iso.IF_CHAR" />

    <isofieldpackager id="48"
        length="255"
        name="Additional private data"
        class="org.jpos.iso.IFA_LLLNUM"
        emitBitmap="false"
        packager="org.jpos.iso.packager.GenericSubFieldPackager">
      <isofield   
          id="1"
          length="8"
          name="PSP Identifier"
          class="org.jpos.iso.IFA_NUMERIC"/>
      <isofield
          id="2"
          length="8"
          name="Ecommerce Acquirer Identifier"
          class="org.jpos.iso.IFA_NUMERIC"/>
    </isofieldpackager>

    <isofield id="49" length="3" name="Currency Code, Transaction"
        class="org.jpos.iso.IFA_NUMERIC" />

</isopackager>

main.java

      public static void main(String[] args) throws ISOException {
                IServicesUtils service = new ServiceUtilsImpl();
                String filePackager = (String) service
                        .getValuesFromPropertiesFile(new String[] { IConstants.DEMO_PACKAGER_LOCATION },
                                "parameters.properties")
                        .get(IConstants.DEMO_PACKAGER_LOCATION);
                GenericPackager packager = new GenericPackager(filePackager);

                ISOMsg isoMsg = new ISOMsg();
                isoMsg.setPackager(packager);
                isoMsg.setMTI("1100");
                isoMsg.set("2", "1111110000000010");
                isoMsg.set("3", "000000");
                isoMsg.set("4", StringUtils.leftPad("116.0", 12, "0"));
                isoMsg.set("7", DateUtils.getTransmissionDate(new Date()));
                isoMsg.set("11", service.generateSTAN());
                isoMsg.set("12", DateUtils.getField12Iso("1207"));
                isoMsg.set("13", DateUtils.getField13Iso("1105"));
                isoMsg.set("14", "0808");
                isoMsg.set("18", "3306");
                isoMsg.set("22", "....");
                isoMsg.set("25", "59");
                isoMsg.set("41", "59002300");
                isoMsg.set("42", "111110000012345");
                isoMsg.set("48", "111110000077658");
                isoMsg.set("48.1", "00221166");
                isoMsg.set("49", "804");

                logISOMsg(isoMsg);

                byte[] data = isoMsg.pack();

                logger.info("RESULT : " + new String(data));
            }


      private static void logISOMsg(ISOMsg msg) {
            System.out.println("----ISO MESSAGE-----");
            try {
                System.out.println("  MTI : " + msg.getMTI());
                for (int i = 1; i <= msg.getMaxField(); i++) {
                    if (msg.hasField(i)) {
                        logger.info("    Field-" + i + " : " + msg.getString(i));
                    }
                }
            } catch (ISOException e) {
                e.printStackTrace();
            } finally {
                System.out.println("--------------------");
            }
        }

此主打印除了字段48之外的所有字段,它返回 null 值。不知道为什么,包装层面有问题,还是别的什么。

1 个答案:

答案 0 :(得分:3)

字段48的外包装程序必须是二进制类,即IFA_LLLBINARY或IFB_LLLBINARY,具体取决于您的规范。如果没有字段0,您可能必须添加firstField属性并将其设置为1.作为替代方法,您可以将字段0定义为IF_NOP(无操作)。