• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

swiftMT报文解析处理

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
swift 官方资料:https://www2.swift.com/knowledgecentre/publications/us5mc_20180720/2.0?topic=alec.htm#genalec
 
swift 百科:https://baike.baidu.com/item/SWIFT/1108075

 

prowide - swift 报文处理 开源框架:https://www.prowidesoftware.com/resources/quickstarts

  pom.xml引用包:

<dependency>
    <groupId>com.prowidesoftware</groupId>
    <artifactId>pw-swift-core</artifactId>
    <version>SRU2018-7.10.4</version>
</dependency>

  如下解析MT940类型报文:

import com.prowidesoftware.swift.io.parser.SwiftParser;
import com.prowidesoftware.swift.model.*;
import com.prowidesoftware.swift.model.field.Field;
import com.prowidesoftware.swift.model.field.Field61;
import com.prowidesoftware.swift.model.mt.mt9xx.MT940;

import java.io.IOException;

public class MT940Test {

    public static void main(String[] args) throws IOException {
        String mt940 = "{1:F01AAAABB99BSMK3513951576}"+
                "{2:O9400934081223BBBBAA33XXXX03592332770812230834N}" +
                "{4:\n"+
                ":20:0112230000000890\n"+
                ":25:SAKG800030155USD\n"+
                ":28C:255/1\n"+
                ":60F:C011223USD175768,92\n"+
                ":61:0112201223CD110,92NDIVNONREF//08 IL053309\n"+
                "/GB/2542049/SHS/312,\n"+
                ":62F:C011021USD175879,84\n"+
                ":20:NONREF\n" +
                ":25:4001400010\n" +
                ":28C:58/1\n" +
                ":60F:C140327EUR6308,75\n" +
                ":61:1403270327C3519,76NTRF50RS201403240008//2014032100037666\n" +
                "ABC DO BRASIL LTDA\n" +
                ":86:INVOICE NR. 6000012801 \n" +
                "ORDPRTY : ABC DO BRASIL LTDA RUA LIBERO BADARO,293-SAO \n" +
                "PAULO BRAZIL }";
        // 方法一
        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));
        }
        System.out.println("*******************************************");
        // 方法二
        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));
        }

    }
}

  运行结果:

getSender:BBBBAA33XXXX
getReceiver:AAAABB99BSMK
getType:940
getMtId:fin.940
getSignature:null
*******************************************
getApplicationId:F
getServiceId:01
getLogicalTerminal:AAAABB99BSMK
getSequenceNumber:951576
*******************************************
getBlockValue:O9400934081223BBBBAA33XXXX03592332770812230834N
*******************************************
getTagValue:0112201223CD110,92NDIVNONREF//08 IL053309
/GB/2542049/SHS/312,
AMOUNT:110,92
getTagValue:1403270327C3519,76NTRF50RS201403240008//2014032100037666
ABC DO BRASIL LTDA
AMOUNT:3519,76
*******************************************
Amount: 110,92
Transaction Type: N
Reference Acc Owner: NONREF
Amount: 3519,76
Transaction Type: N
Reference Acc Owner: 50RS201403240008

  参考资料:https://blog.csdn.net/Little_Stars/article/details/100558234

       https://github.com/prowide/prowide-core-examples/blob/master/src/main/java/com/prowidesoftware/swift/samples/core/ParseMT940FromStringExample.java


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Swift学习(一):自定义运算符operator发布时间:2022-07-13
下一篇:
总结swift1.2适配swift2.0遇到的改变发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap