巧解银联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;

 

 

 

 

 

本软件可以模拟不同类型的交易文,可以对交易测试案例进行统一管理,并可以进行简单时间统计和成功率统计。 使用本软件可以减轻传统测试过程中的修改-编译-测试-的循环等待时间,在测试过程中可以根据需要随时更改文内容。 本软件支持任意格式的文,可以模拟不同格式的文,如定长,变长,XML,8583文。每个的内容可以是常量,也可以支持约定的表达式。 本软件可以根据需要设置对应答相关进行合法性检查,可以校验应答文和请求文的匹配关系,可以校验的长度,校验的内容等。 本软件支持MAC的生成、校验以及PIN加密处理,同时可以根据需要调整是否需要进行MAC和PIN加密。 支持服务端功能,根据不同的文设置不同的应答文。 本软件运行程序无需安装,只需将相关程序和测试案例文件拷贝到相应的文件夹下即可执行。 Version 1.7.0 521 修正一些BUG,增加服务端的设置。 Version 1.6.4.405 增加了应答服务的交易码析,根据析后的交易码匹配应答案例。 增加了再次接收长度,对于特殊文,可先读取一定长度的内容,再根据此配置读取指定长度。 Version 1.6.4.317 增加了应答文的处理,配置案例文件如:_resp.txt(以_开头),按该文本内容格式发出文。 增加了服务配置的接收长度属性,指明长度(如96:按96长度位固定接收),或者(a4-按4位长度位接收,b2-按2位BCD码长度位接收)。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

特立独行的猫a

您的鼓励是我的创作动力

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

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

打赏作者

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

抵扣说明:

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

余额充值