巧解银联8583数据域

简介: 巧解银联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;
相关文章
|
11月前
用试题这把“剑“帮你破除指针与数组之间的那些猫腻
用试题这把“剑“帮你破除指针与数组之间的那些猫腻
45 0
|
缓存 算法 安全
Hash哈希竞猜游戏系统开发技术分析及功能
 Hash,一般翻译做散列,也有直接音译为哈希,就是把任意长度的输入(又叫做预映射,pre-image),通过散列算法,变换成固定长度的输出,该输出就是散列值。
Hash哈希竞猜游戏系统开发技术分析及功能
|
存储 算法 Java
【算法攻坚】回溯电话号码
【算法攻坚】回溯电话号码
203 0
【算法攻坚】回溯电话号码
|
机器学习/深度学习 安全 区块链
隐私计算顶级赛事iDASH2021揭榜 蚂蚁链摩斯获同态加密、联邦学习两项第一
内部钉钉交流群:摩斯产品应用交流(群号:35544266)摩斯产品官网:https://antchain.antgroup.com/products/morse1月28日,2021年iDASH国际隐私计算竞赛正式公布比赛结果,来自蚂蚁集团的蚂蚁链摩斯团队斩获同态加密、联邦学习两项第一。这是自2014年iDASH举办以来,首次来自中国的参赛队夺得上述赛道第一,蚂蚁链摩斯也成为首支同时拿下两项第一的中
隐私计算顶级赛事iDASH2021揭榜 蚂蚁链摩斯获同态加密、联邦学习两项第一
|
Java Python
997.找到小镇的法官 哈希表模拟、数组投票选举 双解!
997.找到小镇的法官 哈希表模拟、数组投票选举 双解!
106 0
|
Java PHP 开发工具
记录一次和工行对接对方提供的aeskey是24位字符串
记录一次和工行对接对方提供的aeskey是24位字符串
246 0
记录一次和工行对接对方提供的aeskey是24位字符串
|
前端开发 Java
|
人工智能 边缘计算 数据挖掘
您有一份数智化商业机密待查收!
关于实体商业数字化和流量运营的秘密,建议偷偷打开......
您有一份数智化商业机密待查收!
|
JSON 前端开发 API
剥开比原看代码16:比原是如何通过/list-transactions显示交易信息的
作者:freewind 比原项目仓库: Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom 在前一篇文章中,我们试图理解比原是如何交易的,但是由于内容太多,我们把它分成了几个小问题,并在前一篇解决了“在dashboard中如何提交交易信息”,以及“比原后台是如何操作的”。
1187 0