前言
1. SWIFT说明
国际资金清算系统(SWIFT)由[环球同业银行金融电讯协会](https://baike.baidu.com/item/%E7%8E%AF%E7%90%83%E5%90%8C%E4%B8%9A%E9%93%B6%E8%A1%8C%E9%87%91%E8%9E%8D%E7%94%B5%E8%AE%AF%E5%8D%8F%E4%BC%9A/5423562)管理,SWIFT的使用,使银行的结算提供了安全、可靠、快捷、标准化、自动化的通讯业务,从而大大提高了银行的结算速度。由于SWIFT的格式具有标准化,信用证的格式主要都是用SWIFT电文。
2. Prowide说明
Prowide Core 是一个用于管理 FIN MT 消息的开源 Java 库
3. 使用版本
-
使用Prowide
1. 添加依赖
添加解析SWIFT报文依赖
<dependency>
<groupId>com.prowidesoftware</groupId>
<artifactId>pw-swift-core</artifactId>
<version>SRU2021-9.2.12</version>
</dependency>
2. 解析MT940
MT940示例数据
{1:F01AAAABB99BSMK3513951576}{2:O9400934081223BBBBAA33XXXX03592332770812230834N}{4:
:20:0112230000000890
:25:SAKG800030155USD
:28C:255/1
:60F:C011223USD175768,92
:61:0112201223CD110,92NDIVNONREF//08 IL053309
/GB/2542049/SHS/312,
:62F:C011021USD175879,84
:20:NONREF
:25:4001400010
:28C:58/1
:60F:C140327EUR6308,75
:61:1403270327C3519,76NTRF50RS201403240008//2014032100037666
ABC DO BRASIL LTDA
:86:INVOICE NR. 6000012801
ORDPRTY : ABC DO BRASIL LTDA RUA LIBERO BADARO,293-SAO
PAULO BRAZIL }
使用SwiftParser解析报文
SwiftParser parser = new SwiftParser(mt940);
SwiftMessage swiftMessage = parser.message();
System.out.println("getSender:" + swiftMessage.getSender());
System.out.println("getReceiver:" + swiftMessage.getReceiver());
System.out.println("getType:" + swiftMessage.getType());
System.out.println("getMtId:" + swiftMessage.getMtId());
System.out.println("getSignature:" + swiftMessage.getSignature());
System.out.println("---------------------------------------------");
SwiftBlock1 swiftBlock1 = swiftMessage.getBlock1();
System.out.println("getApplicationId:" + swiftBlock1.getApplicationId());
System.out.println("getServiceId:" + swiftBlock1.getServiceId());
System.out.println("getLogicalTerminal:" + swiftBlock1.getLogicalTerminal());
System.out.println("getSequenceNumber:" + swiftBlock1.getSequenceNumber());
System.out.println("---------------------------------------------");
SwiftBlock2 swiftBlock2 = swiftMessage.getBlock2();
System.out.println("getBlockValue:" + swiftBlock2.getBlockValue());
System.out.println("---------------------------------------------");
SwiftBlock4 swiftBlock4 = swiftMessage.getBlock4();
Field[] fields = swiftBlock4.getFieldsByName("61");
for (Field field : fields) {
System.out.println("getTagValue:" + field.getValue());
System.out.println("AMOUNT:" + field.getComponent(5));
}
使用MT940解析报文
MT940 mt = MT940.parse(mt940);
for (Field61 tx : mt.getField61()) {
System.out.println("Amount: " + tx.getComponent(Field61.AMOUNT));
System.out.println("Transaction Type: " + tx.getComponent(Field61.TRANSACTION_TYPE));
System.out.println("Reference Acc Owner: " + tx.getComponent(Field61.REFERENCE_FOR_THE_ACCOUNT_OWNER));
}
相关资料
Prowide官方文档
Prowide示例代码
MT报文格式说明