使用 jpos api 打包子字段
Packing SUBFIELDS using jpos api
我正在尝试使用 jpos 框架.
编写一个打包和解包 ISOMessage 的主程序
问题是我的消息包含一些 sub_fields,例如 字段 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 之外的所有字段,它是 returns null 值。不知道为什么,是封装层面有问题,还是别的什么。
字段 48 的外包装程序必须是二进制 class,即 IFA_LLLBINARY 或 IFB_LLLBINARY,具体取决于您的规范。如果没有字段 0,您可能必须添加 firstField
属性并将其设置为 1。作为替代方案,您可以将字段 0 定义为 IF_NOP
(无操作)。
我正在尝试使用 jpos 框架.
编写一个打包和解包 ISOMessage 的主程序问题是我的消息包含一些 sub_fields,例如 字段 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 之外的所有字段,它是 returns null 值。不知道为什么,是封装层面有问题,还是别的什么。
字段 48 的外包装程序必须是二进制 class,即 IFA_LLLBINARY 或 IFB_LLLBINARY,具体取决于您的规范。如果没有字段 0,您可能必须添加 firstField
属性并将其设置为 1。作为替代方案,您可以将字段 0 定义为 IF_NOP
(无操作)。