巧解银联8583数据域

仔细分析了下8583报文,发现理解之后,解析还是很方便的。

两个函数搞定。

 

/*
**************************************************************************************************************
*Iso8583 报文初始化
Information8583SetRcv[0]  -----> 1域
Information8583SetRcv[1]  -----> 2域
		.				  	   .
		.				  	   .
		.				  	   .
Information8583SetRcv[63] ----->64域
**************************************************************************************************************
*/
void APP_8583_Init( __8583Information  *Information8583Set)
{
	Information8583Set[0].Seat = 0;
	Information8583Set[0].LenLen = 0;
	Information8583Set[0].DataLen = 0;
	Information8583Set[1].Seat = 0;
	Information8583Set[1].LenLen = 1;
	Information8583Set[1].DataLen = 0;
	Information8583Set[2].Seat = 0;
	Information8583Set[2].LenLen = 0;
	Information8583Set[2].DataLen = 3;
	Information8583Set[3].Seat = 0;
	Information8583Set[3].LenLen = 0;
	Information8583Set[3].DataLen = 6;
	Information8583Set[10].Seat = 0;
	Information8583Set[10].LenLen = 0;
	Information8583Set[10].DataLen = 3;
	Information8583Set[11].Seat = 0;
	Information8583Set[11].LenLen = 0;
	Information8583Set[11].DataLen = 3;
	Information8583Set[12].Seat = 0;
	Information8583Set[12].LenLen = 0;
	Information8583Set[12].DataLen = 2;
	Information8583Set[13].Seat = 0;
	Information8583Set[13].LenLen = 0;
	Information8583Set[13].DataLen = 2;
	Information8583Set[14].Seat = 0;
	Information8583Set[14].LenLen = 0;
	Information8583Set[14].DataLen = 2;
	Information8583Set[15].Seat = 0;
	Information8583Set[15].LenLen = 0;
	Information8583Set[15].DataLen = 2;
	Information8583Set[21].Seat = 0;
	Information8583Set[21].LenLen = 0;
	Information8583Set[21].DataLen = 2;
	Information8583Set[22].Seat = 0;
	Information8583Set[22].LenLen = 0;
	Information8583Set[22].DataLen = 2;
	Information8583Set[24].Seat = 0;
	Information8583Set[24].LenLen = 0;
	Information8583Set[24].DataLen = 1;
	Information8583Set[25].Seat = 0;
	Information8583Set[25].LenLen = 0;
	Information8583Set[25].DataLen = 1;
	Information8583Set[31].Seat = 0;
	Information8583Set[31].LenLen = 1;
	Information8583Set[31].DataLen = 0;
	Information8583Set[36].Seat = 0;
	Information8583Set[36].LenLen = 0;
	Information8583Set[36].DataLen = 12;
	Information8583Set[37].Seat = 0;
	Information8583Set[37].LenLen = 0;
	Information8583Set[37].DataLen = 6;
	Information8583Set[38].Seat = 0;
	Information8583Set[38].LenLen = 0;
	Information8583Set[38].DataLen = 2;
	Information8583Set[40].Seat = 0;
	Information8583Set[40].LenLen = 0;
	Information8583Set[40].DataLen = 8;
	Information8583Set[41].Seat = 0;
	Information8583Set[41].LenLen = 0;
	Information8583Set[41].DataLen = 15;
	Information8583Set[43].Seat = 0;
	Information8583Set[43].LenLen = 1;
	Information8583Set[43].DataLen = 0;
	Information8583Set[47].Seat = 0;
	Information8583Set[47].LenLen = 2;
	Information8583Set[47].DataLen = 0;
	Information8583Set[48].Seat = 0;
	Information8583Set[48].LenLen = 0;
	Information8583Set[48].DataLen = 3;
	Information8583Set[51].Seat = 0;
	Information8583Set[51].LenLen = 0;
	Information8583Set[51].DataLen = 8;
	Information8583Set[52].Seat = 0;
	Information8583Set[52].LenLen = 0;
	Information8583Set[52].DataLen = 8;

	Information8583Set[54].Seat = 0;
	Information8583Set[54].LenLen = 2;
	Information8583Set[54].DataLen = 0;
	Information8583Set[59].Seat = 0;
	Information8583Set[59].LenLen = 2;
	Information8583Set[59].DataLen = 0;
	Information8583Set[60].Seat = 0;
	Information8583Set[60].LenLen = 2;
	Information8583Set[60].DataLen = 0;
	Information8583Set[61].Seat = 0;
	Information8583Set[61].LenLen = 2;
	Information8583Set[61].DataLen = 0;
	Information8583Set[62].Seat = 0;
	Information8583Set[62].LenLen = 2;
	Information8583Set[62].DataLen = 0;
	Information8583Set[63].Seat = 0;
	Information8583Set[63].LenLen = 0;
	Information8583Set[63].DataLen = 8;
}
/*
**************************************************************************************************************
*Iso8583 报文解析
**************************************************************************************************************
*/
U32 APP_8583_Analysis( __8583Information  *Information8583SetRcv, U08 *SeatBuf, U08 *DataBuf, U32 BufferLen)
{
	U16 len = 0;
	U08 i,rbuf[5];
	U64 buf = 0,seat=1;
	APP_8583_Init(Information8583SetRcv);
	for(i=0;i<8;i++)
	{
		buf = ((buf<<8) | SeatBuf[i]);
	}
	len += 23;
	for(i=0;i<64;i++)
	{
		if(buf&(seat<<(63-i)))
		{
			memset(rbuf, 0, 5);
			if(Information8583SetRcv[i].DataLen)
			{
				Information8583SetRcv[i].Seat = len;
				len += Information8583SetRcv[i].DataLen;
			}
			else
			{	
				if(Information8583SetRcv[i].LenLen == 1)
				{
					sprintf((char*)rbuf,"%02X",DataBuf[len]);
					Information8583SetRcv[i].DataLen = (U16)atoi((const char*)rbuf);
					len += 1;
					Information8583SetRcv[i].Seat = len;
					if((i==1)||(i==31)||(i==47)||(i==59)||(i==60))
					{
						Information8583SetRcv[i].DataLen =	Information8583SetRcv[i].DataLen/2 + Information8583SetRcv[i].DataLen%2;
					}
				}
				else if(Information8583SetRcv[i].LenLen == 2)
				{
					sprintf((char*)rbuf,"%02X%02X", DataBuf[len], DataBuf[len+1]);
					Information8583SetRcv[i].DataLen = (U16)atoi((const char*)rbuf);
					len += 2;
					Information8583SetRcv[i].Seat = len;
					if((i==1)||(i==31)||(i==59)||(i==60)||(i==61))
					{
						Information8583SetRcv[i].DataLen =	Information8583SetRcv[i].DataLen/2 + Information8583SetRcv[i].DataLen%2;
					}
				}
				else
				{
					DEF_UPCash_Debug;
					return 1;
				}
				len += Information8583SetRcv[i].DataLen;
			}	
		}
	}
	if(len>BufferLen)
	{
		DEF_UPCash_Debug;
		return 1;
	}
	return 0;
}


typedef struct                       
{
unsigned  short DataLen;
unsigned  char LenLen;
unsigned  short Seat;
}__8583Information;

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

特立独行的猫a

您的鼓励是我的创作动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值