您的位置:首页 > 编程语言 > C语言/C++

8583报文结构分析及C语言实现

2012-10-19 17:26 127 查看
 

 

 

8583报文结构分析及C语言实现
------报文结构分析
 
曹玉坤
 
 
 
 
 
 
 
 
 
 
 
2011-7-11
 
 
 
目  录
1    
概述...
3

2    
8583报文结构...
3

3    
各字段意义说明...
4

4    
报文结构样例...
4

5    
报文内容样例...
8

 
 

 

1      
概述

8583报文是开放的自由度比较高的报文格式之一,多用于银行报文的传输。由于其较高的自由度,每家银行都可以规定自己的8583报文格式,从一定程度上为银行报文提供了加密。即如果想要解开8583报文的内容,就必须知道此8583报文遵循的是何种结构。而这个结构则是由银行内部自己制定。

2       8583报文结构

大家都对结构体比较熟悉,我们先来看看8583的结构体。

Typedef  struct ISO8583

{

       int length; /*数据域长度*/ 

       int variable_flag; /*是否变长标志0:否 2:2位变长, 

3:3位变长*/

       char *data; /*存放具体值*/ 

} ISO8583

我们并没有列出所有的字段,只列出些比较常用的。首先我们看第一个数据的长度,指的是数据的最大长度(如果是变长的话)。

第二个是是否变长标志,这个稍微有点麻烦,我们举个例子说明。先看看如果是0,标识定长,也就是说数据的长度就是前面定义的数据长度位;如果是2或3,那就说明数据的前两位或前三位是标识数据的实际长度的。如,我们数据 
3,100:标识数据总长度为100,实际长度通过前三位标识。00812345678,前面三位008,标识实际长度,后面12345678
8位才是真实的数据。

再来后面就是存放的具体数值。

3      
各字段意义说明

前面我们大概介绍了各个字段的意义,这里我们着重讲下一个特殊的字段,就是8583的灵魂,bitmap。Bitmap顾名思义就是位图,他表示什么呢?他表示哪些位有值,哪些没有。他长度一共16个字节,一共128位,每位标识相应的位有没有数据,如果有则为1,没有标识为0。这样就能大大提高我们的读取效率。还有我们有可能需要标识出报文长度时128位还是64位,因为很多报文没有那么多的要素,不需要那么多的数据位。这个是通过bitmap第一位标识的,如果是1就认为报文长度为128,如果为0就说明报文长度为64。

4      
报文结构样例

        /*000*/ {TYP_BCD, 0, 4, "Message Type Indicator"},

    /*001*/ {TYP_BIT, 0, 16, "Bitmap"},

    /*002*/ {TYP_ASC, 0, 35, "报文标识号"},

    /*003*/ {TYP_ASC, 0, 19, "报文发送时间"},

    /*004*/ {TYP_BCD, 0, 14, "发起直接参与机构"},

    /*005*/ {TYP_BCD, 0, 14, "发起间接参与机构"},

    /*006*/ {TYP_BCD, 0, 14, "接收直接参与机构"},

    /*007*/ {TYP_BCD, 0, 14, "接收间接参与机构"},

    /*008*/ {TYP_ASC, 0, 4, "系统编号"},

    /*009*/ {TYP_BCD, 2, 16, "支付交易序号"},

    /*010*/ {TYP_ASC, 2, 60, "付款人名称"},

    /*011*/ {TYP_BCD, 2, 32, "付款人账号"},

    /*012*/ {TYP_BCD, 0, 14, "付款人开户行号"},

    /*013*/ {TYP_BCD, 0, 14, "付款行行号"},

    /*014*/ {TYP_BCD, 0, 14, "收款行行号"},

    /*015*/ {TYP_ASC, 2, 60, "收款人名称"},

    /*016*/ {TYP_BCD, 2, 32, "收款人帐号"},

    /*017*/ {TYP_BCD, 0, 14, "收款人开户行号"},

    /*018*/ {TYP_ASC, 0, 3, "币种代码"},

    /*019*/ {TYP_BCD, 0, 18, "金额"},

    /*020*/ {TYP_BCD, 0, 4, "业务类型编码"},

    /*021*/ {TYP_BCD, 0, 5, "业务种类编码"},

    /*022*/ {TYP_ASC, 0, 12, "附言"},

    /*023*/ {TYP_BCD, 0, 3, "Card sequence number"},

    /*024*/ {TYP_BCD, 0, 3, "Function code"},

    /*025*/ {TYP_BCD, 0, 4, "Message reason code"},

    /*026*/ {TYP_BCD, 0, 4, "Card acceptor business code"},

    /*027*/ {TYP_BCD, 0, 1, "Approval code length"},

    /*028*/ {TYP_BCD, 0, 6, "Date, Reconciliation"},

    /*029*/ {TYP_BCD, 0, 3, "Reconciliation indicator"},

    /*030*/ {TYP_BCD, 0, 24, "Amounts, original"},

    /*031*/ {TYP_ASC, 2, 99, "Acquirer reference data"},

    /*032*/ {TYP_BCD, 2, 11, "Acquirer institution identification code"},

    /*033*/ {TYP_BCD, 2, 11, "Forwarding institution identification code"},

    /*034*/ {TYP_ASC, 2, 28, "Primary account number, extended"},

    /*035*/ {TYP_ASC, 2, 37, "Track 2 data"},

    /*036*/ {TYP_ASC, 3, 104, "Track 3 data"},

    /*037*/ {TYP_ASC, 0, 12, "Retrieval reference number"},

    /*038*/ {TYP_ASC, 0, 6, "Approval code"},

    /*039*/ {TYP_BCD, 0, 3, "Action code"},

    /*040*/ {TYP_BCD, 0, 3, "Service code"},

    /*041*/ {TYP_ASC, 0, 8, "Card acceptor terminal identification"},

    /*042*/ {TYP_ASC, 0, 15, "Card acceptor identification code"},

    /*043*/ {TYP_ASC, 2, 99, "Card acceptor name/location"},

    /*044*/ {TYP_ASC, 2, 99, "Additional response data"},

    /*045*/ {TYP_ASC, 2, 76, "Track 1 data"},

    /*046*/ {TYP_ASC, 3, 204, "Amounts, Fees"},

    /*047*/ {TYP_ASC, 3, 999, "Additional data - national"},

    /*048*/ {TYP_ASC, 3, 999, "Additional data - private"},

    /*049*/ {TYP_ASC, 0, 3, "Currency code, Transaction"},

    /*050*/ {TYP_ASC, 0, 3, "Currency code, Reconciliation"},

    /*051*/ {TYP_ASC, 0, 3, "Currency code, Cardholder billing"},

    /*052*/ {TYP_BIN, 0, 8, "Personal identification number, PIN) data"},

    /*053*/ {TYP_BIN, 2, 48, "Security related control information"},

    /*054*/ {TYP_ASC, 3, 120, "Amounts, additional"},

    /*055*/ {TYP_BIN, 3, 255, "IC card system related data"},

    /*056*/ {TYP_BIN, 3, 255, "Original data elements"},

    /*057*/ {TYP_BCD, 0, 3, "Authorization life cycle code"},

    /*058*/ {TYP_BCD, 2, 11, "Authorizing agent institution Id Code"},

    /*059*/ {TYP_ASC, 3, 999, "Transport data"},

    /*060*/ {TYP_ASC, 3, 999, "Reserved for national use"},

    /*061*/ {TYP_ASC, 3, 999, "Reserved for national use"},

    /*062*/ {TYP_ASC, 3, 999, "Reserved for private use"},

    /*063*/ {TYP_ASC, 3, 999, "Reserved for private use"},

    /*064*/ {TYP_BIN, 0, 8, "Message authentication code field"}

 

#if ISO_FLDS==128

 ,

 /*065*/ {TYP_BIN, 0, 8, "Reserved for ISO use"},

    /*066*/ {TYP_ASC, 3, 204, "Amounts, original fees"},

    /*067*/ {TYP_BCD, 0, 2, "Extended payment data"},

    /*068*/ {TYP_BCD, 0, 3, "Country code, receiving institution"},

    /*069*/ {TYP_BCD, 0, 3, "Country code, settlement institution"},

    /*070*/ {TYP_BCD, 0, 3, "Country code, authorizing agent Inst."},

    /*071*/ {TYP_BCD, 0, 8, "Message number"},

    /*072*/ {TYP_ASC, 3, 999, "Data record"},

    /*073*/ {TYP_BCD, 0, 6, "Date, action"},

    /*074*/ {TYP_BCD, 0, 10, "Credits, number"},

    /*075*/ {TYP_BCD, 0, 10, "Credits, reversal number"},

    /*076*/ {TYP_BCD, 0, 10, "Debits, number"},

    /*077*/ {TYP_BCD, 0, 10, "Debits, reversal number"},

    /*078*/ {TYP_BCD, 0, 10, "Transfer, number"},

    /*079*/ {TYP_BCD, 0, 10, "Transfer, reversal number"},

    /*080*/ {TYP_BCD, 0, 10, "Inquiries, number"},

    /*081*/ {TYP_BCD, 0, 10, "Authorizations, number"},

    /*082*/ {TYP_BCD, 0, 10, "Inquiries, reversal number"},

    /*083*/ {TYP_BCD, 0, 10, "Payments, number"},

    /*084*/ {TYP_BCD, 0, 10, "Payments, reversal number"},

    /*085*/ {TYP_BCD, 0, 10, "Fee collections, number"},

    /*086*/ {TYP_BCD, 0, 16, "Credits, amount"},

    /*087*/ {TYP_BCD, 0, 16, "Credits, reversal amount"},

    /*088*/ {TYP_BCD, 0, 16, "Debits, amount"},

    /*089*/ {TYP_BCD, 0, 16, "Debits, reversal amount"},

    /*090*/ {TYP_BCD, 0, 10, "Authorizations, reversal number"},

    /*091*/ {TYP_BCD, 0, 3, "Country code, transaction Dest. Inst."},

    /*092*/ {TYP_BCD, 0, 3, "Country code, transaction Orig. Inst."},

    /*093*/ {TYP_BCD, 2, 11, "Transaction Dest. Inst. Id code"},

    /*094*/ {TYP_BCD, 2, 11, "Transaction Orig. Inst. Id code"},

    /*095*/ {TYP_ASC, 2, 99, "Card issuer reference data"},

    /*096*/ {TYP_BIN, 3, 999, "Key management data"},

    /*097*/ {TYP_BCD, 0, 1+16, "Amount, Net reconciliation"}, /* was ISO_AMOUNT */

    /*098*/ {TYP_ASC, 0, 25, "Payee"},

    /*099*/ {TYP_ASC, 2, 11, "Settlement institution Id code"},

    /*100*/ {TYP_BCD, 2, 11, "Receiving institution Id code"},

    /*101*/ {TYP_ASC, 2, 17, "File name"},

    /*102*/ {TYP_ASC, 2, 28, "Account identification 1"},

    /*103*/ {TYP_ASC, 2, 28, "Account identification 2"},

    /*104*/ {TYP_ASC, 3, 100, "Transaction description"},

    /*105*/ {TYP_BCD, 0, 16, "Credits, Chargeback amount"},

    /*106*/ {TYP_BCD, 0, 16, "Debits, Chargeback amount"},

    /*107*/ {TYP_BCD, 0, 10, "Credits, Chargeback number"},

    /*108*/ {TYP_BCD, 0, 10, "Debits, Chargeback number"},

    /*109*/ {TYP_ASC, 2, 84, "Credits, Fee amounts"},

    /*110*/ {TYP_ASC, 2, 84, "Debits, Fee amounts"},

    /*111*/ {TYP_ASC, 3, 999, "Reserved for ISO use"},

    /*112*/ {TYP_ASC, 3, 999, "Reserved for ISO use"},

    /*113*/ {TYP_ASC, 3, 999, "Reserved for ISO use"},

    /*114*/ {TYP_ASC, 3, 999, "Reserved for ISO use"},

    /*115*/ {TYP_ASC, 3, 999, "Reserved for ISO use"},

    /*116*/ {TYP_ASC, 3, 999, "Reserved for national use"},

    /*117*/ {TYP_ASC, 3, 999, "Reserved for national use"},

    /*118*/ {TYP_ASC, 3, 999, "Reserved for national use"},

    /*119*/ {TYP_ASC, 3, 999, "Reserved for national use"},

    /*120*/ {TYP_ASC, 3, 999, "Reserved for national use"},

    /*121*/ {TYP_ASC, 3, 999, "Reserved for national use"},

    /*122*/ {TYP_ASC, 3, 999, "Reserved for national use"},

    /*123*/ {TYP_ASC, 3, 999, "Reserved for private use"},

    /*124*/ {TYP_ASC, 3, 999, "Reserved for private use"},

    /*125*/ {TYP_ASC, 3, 999, "Reserved for private use"},

    /*126*/ {TYP_ASC, 3, 999, "Reserved for private use"},

    /*127*/ {TYP_ASC, 3, 999, "Reserved for private use"},

    /*128*/ {TYP_BIN, 0, 8, "Message authentication code field"}

#endif /*ISO_FLDS==128*/

 

5      
报文内容样例

     内容就是按照8583规定的样式,将对应位的内容对应在相应的位置上。

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息