好吧,阅读 jpos 库文档,它的草稿版本可以在网上找到,你可以在这里找到它
具体到您关于 JPOS Server 的问题更好地实现您自己的服务器。JPos 提供类,例如以下 bean 在文件ISOServer
中启动 ISO 服务器applicationContext.xml
<bean id="paymentServer" class="org.jpos.iso.ISOServer">
<constructor-arg>
<value>13000</value>
</constructor-arg>
<constructor-arg ref="paymentChannel" />
<constructor-arg ref="paymentServerThreadPool" />
</bean>
<bean id="paymentChannel" class="org.jpos.iso.channel.ASCIIChannel">
<constructor-arg ref="paymentPackager" />
</bean>
<bean id="paymentPackager" class="com.sample.payment.packager.PaymentPackager"/>
<bean id="paymentServerThreadPool" class="org.jpos.util.ThreadPool">
<constructor-arg>
<value>1</value>
</constructor-arg>
<constructor-arg>
<value>100</value>
</constructor-arg>
<constructor-arg>
<value>PaymentServer</value>
</constructor-arg>
</bean>
<bean id="paymentProcessor" class="com.sample.processors.PaymentProcessor" init-method="init"/>
跟随类来实现打包器
public class PaymentPackager extends ISOBasePackager {
protected ISOFieldPackager fld[] = {
/* 0000 */ new IFB_NUMERIC ( 4, "Message Type Indicator", false),
/* 0001 */ new IFB_BITMAP ( 16, "Bitmap"),
/* 0002 */ new IFB_LLLCHAR (999, "Primary Account number"),
/* 0003 */ new IFB_NUMERIC ( 6, "Processing Code", true),
/* 0004 */ new IFB_NUMERIC ( 12, "Amount, Transaction", true),
//.....
/* 0063 */ new IFB_LLLCHAR (999, "Reserved for national use"),
/* 0064 */ new IFB_BINARY ( 20, "Message authentication code field"),
//.....
/* 0125 */ new IF_UNUSED (),
/* 0126 */ new IF_UNUSED (),
/* 0127 */ new IF_UNUSED (),
/* 0128 */ new IFB_BINARY ( 20, "Message authentication code field"),
};
public PaymentPackager() {
super();
setFieldPackager(fld);
}
}
在应用程序入口点类中,您可以获取 bean 并使用如下方式附加通道侦听器
paymentServer.addISORequestListener(paymentProcessor);
以下是示例监听器
public class PaymentProcessor implements ISORequestListener {
private static Logger log = LoggerFactory.getLogger(PaymentProcessor.class);
public void init() {
//do init
}
public boolean process (ISOSource source, ISOMsg m){
log.debug(">PaymentProcessor.process");
ISOMsg request = (ISOMsg) m.clone();
ISOMsg response = new ISOMsg();
//...
//build your response
//...
source.send(response);
return true;
}
}
注意:我还没有实现它,但是 jpos 提供了使用 Q2 实现服务器和客户端的新方法,您可以查看 QServer 类实现服务器的文档,我会尽快分享示例。
快乐编码:)