⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cb8583packetheader.java

📁 8583 pack and unpack 8583 pro
💻 JAVA
字号:
package com.szzt.trade.zsbank;

import com.szzt.common.SysFunction;
import com.szzt.common.datapacket.PacketException;

public class CB8583PacketHeader {
  //包头数据,80个byte,不包括包体长度
  private byte[] packetType = null; //报文种类 0为8583,1为非8583
  private byte[] msgType = null;
  private byte[] prcCode = null;
  private byte[] acqInstID = null; //收单机构号
  private byte[] termID = null; //收单机构终端号
  private byte[] traceNo = null; //流水号
  private byte[] cusType = null; //卡种类
  private byte[] cusNo = null; //卡号
  private byte[] appType = null; //应用类型
  private byte[] svrCode = null; //对帐服务器代码
  private byte[] retCode = null; //返回码
  private byte[] packetNo = null; //报文序号
  private byte[] filler = null; //附加域

  public CB8583PacketHeader() {
  }

  public CB8583PacketHeader(String packetType,
                      String msgType,
                      String prcCode,
                      String acqInstID,
                      String termID,
                      String traceNo,
                      String cusType,
                      String cusNo,
                      String appType,
                      String svrCode,
                      String retCode,
                      String packetNo,
                      String filler)
  {
       this.packetType = SysFunction.getFixedLenStr(packetType,1,' ',false).getBytes();
       this.msgType = SysFunction.getFixedLenStr(msgType,4,' ',false).getBytes();
       //modiy by tangmw 1210
       if(prcCode.trim().equals("936011")){
         this.prcCode = SysFunction.getFixedLenStr("936000",6,' ',false).getBytes();
       }else{
         this.prcCode = SysFunction.getFixedLenStr(prcCode,6,' ',false).getBytes();
       }
       this.acqInstID = SysFunction.getFixedLenStr(acqInstID,8,' ',false).getBytes();
       this.termID = SysFunction.getFixedLenStr(termID,8,' ',false).getBytes();
       this.traceNo = SysFunction.getFixedLenStr(traceNo,6,' ',false).getBytes();
       this.cusType = SysFunction.getFixedLenStr(cusType,2,' ',false).getBytes();
       this.cusNo = SysFunction.getFixedLenStr(cusNo,25,' ',false).getBytes();
       this.appType = SysFunction.getFixedLenStr(appType,2,' ',false).getBytes();
       this.svrCode = SysFunction.getFixedLenStr(svrCode,8,' ',false).getBytes();
       this.retCode = SysFunction.getFixedLenStr(retCode,2,' ',false).getBytes();
       this.packetNo = SysFunction.getFixedLenStr(packetNo,2,' ',false).getBytes();
       this.filler = SysFunction.getFixedLenStr(filler,6,' ',false).getBytes();
  }

  public byte[] getPacketHeader(){
       byte[] tmpHeader = new byte[80];
       int iPos = 0;
       System.arraycopy(this.packetType,0,tmpHeader,iPos,this.packetType.length);
       iPos += this.packetType.length;
       System.arraycopy(this.msgType,0,tmpHeader,iPos,this.msgType.length);
       iPos += this.msgType.length;
       System.arraycopy(this.prcCode,0,tmpHeader,iPos,this.prcCode.length);
       iPos += this.prcCode.length;
       System.arraycopy(this.acqInstID,0,tmpHeader,iPos,this.acqInstID.length);
       iPos += this.acqInstID.length;
       System.arraycopy(this.termID,0,tmpHeader,iPos,this.termID.length);
       iPos += this.termID.length;
       System.arraycopy(this.traceNo,0,tmpHeader,iPos,this.traceNo.length);
       iPos += this.traceNo.length;
       System.arraycopy(this.cusType,0,tmpHeader,iPos,this.cusType.length);
       iPos += this.cusType.length;
       System.arraycopy(this.cusNo,0,tmpHeader,iPos,this.cusNo.length);
       iPos += this.cusNo.length;
       System.arraycopy(this.appType,0,tmpHeader,iPos,this.appType.length);
       iPos += this.appType.length;
       System.arraycopy(this.svrCode,0,tmpHeader,iPos,this.svrCode.length);
       iPos += this.svrCode.length;
       System.arraycopy(this.retCode,0,tmpHeader,iPos,this.retCode.length);
       iPos += this.retCode.length;
       System.arraycopy(this.packetNo,0,tmpHeader,iPos,this.packetNo.length);
       iPos += this.packetNo.length;
       System.arraycopy(this.filler,0,tmpHeader,iPos,this.filler.length);
       return tmpHeader;
  }

  public void setPacketHeader(byte[] packetHeader)
            throws PacketException{
       if(packetHeader == null || packetHeader.length != 80)
           throw new PacketException("解包头出错") ;
       byte[] tmpHeader = new byte[80];
       int iPos = 0;
       this.packetType = new byte[1];
       System.arraycopy(packetHeader,iPos,this.packetType,0,1);
       iPos += 1;
       this.msgType = new byte[4];
       System.arraycopy(packetHeader,iPos,this.msgType,0,4);
       iPos += 4;
       this.prcCode = new byte[6];
       System.arraycopy(packetHeader,iPos,this.prcCode,0,6);
       iPos += 6;
       this.acqInstID = new byte[8];
       System.arraycopy(packetHeader,iPos,this.acqInstID,0,8);
       iPos += 8;
       this.termID = new byte[8];
       System.arraycopy(packetHeader,iPos,this.termID,0,8);
       iPos += 8;
       this.traceNo = new byte[6];
       System.arraycopy(packetHeader,iPos,this.traceNo,0,6);
       iPos += 6;
       this.cusType = new byte[2];
       System.arraycopy(packetHeader,iPos,this.cusType,0,2);
       iPos += 2;
       this.cusNo = new byte[25];
       System.arraycopy(packetHeader,iPos,this.cusNo,0,25);
       iPos += 25;
       this.appType = new byte[2];
       System.arraycopy(packetHeader,iPos,this.appType,0,2);
       iPos += 2;
       this.svrCode = new byte[8];
       System.arraycopy(packetHeader,iPos,this.svrCode,0,8);
       iPos += 8;
       this.retCode = new byte[2];
       System.arraycopy(packetHeader,iPos,this.retCode,0,2);
       iPos += 2;
       this.packetNo = new byte[2];
       System.arraycopy(packetHeader,iPos,this.packetNo,0,2);
       iPos += 2;
       this.filler = new byte[6];
       System.arraycopy(packetHeader,iPos,this.filler,0,6);
       iPos += 6;
  }

  public byte[] getPacketType(){
       return this.packetType;
  }

  public byte[] getMsgType(){
       return this.msgType;
  }

  public byte[] getPrcCode(){
       return this.prcCode;
  }

  public byte[] getAcqInstID(){
       return this.acqInstID;
  }

  public byte[] getTermID(){
       return this.termID;
  }

  public byte[] getTraceNo(){
       return this.traceNo;
  }

  public byte[] getCusType(){
       return this.cusType;
  }

  public byte[] getCusNo(){
       return this.cusNo;
  }

  public byte[] getAppType(){
       return this.appType;
  }

  public byte[] getSvrCode(){
       return this.svrCode;
  }

  public byte[] getRetCode(){
       return this.retCode;
  }

  public byte[] getPacketNo(){
       return this.packetNo;
  }

  public byte[] getFiller(){
       return this.filler;
  }


  public void clear(){
    this.packetType = null;
    this.msgType = null;
    this.prcCode = null;
    this.acqInstID = null;
    this.termID = null;
    this.traceNo = null;
    this.cusType = null;
    this.cusNo = null;
    this.appType = null;
    this.svrCode = null;
    this.retCode = null;
    this.packetNo = null;
    this.filler = null;
  }




}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -