ISO 8583 using summary (attachment portion Java source code) (ii)

The first implementation

The first implementation is divided into three steps:

  • Step 1: Create domain object
  • Step 2: Create a variety of data conversion tools
  • The third step: a package request

    Step 1: Create domain object

    This step is relatively simple, relatively easy to understand, less suitable domain, or is it so each time you fill a dozen domain.
    Open your interface documentation, look at the document in the interface message has the number of domains, here I have 64 domains, there are some sub-domains under the domain.
public class Message8583Body {
    private String msgType;// 消息类型
    private String bitMap;// 位元表
    private String domain2;
    private String domain3;
    private String domain4;
    ··· 
    private String domain48;
    private String domain49; 
    private String domain58;  
    private String domain58_1;  
    private String domain58_2;  
    private String domain58_3;
}

Here I would simply say something, a total of 64 fields, create a class based on each domain and its subdomain. Subdomain to my domain here 58 For example, suppose there are 55 fields following three sub-domains, sub-domains where set methods require special handling.

  
  public String getDomain58() {
    return domain58;
  }
  public void setDomain58(String domain58) {
    this.domain58 = domain58;
  }
  public String getDomain58_1() {
    return domain58_1;
  }
  public void setDomain58_1(String domain58_1) {
    this.domain58_1 = domain58_1;
    this.domain58 += domain58_1;
  }
  public String getDomain58_2() {
    return domain58_2;
  }  
  public void setDomain58_2(String domain58_2) {
    this.domain58_2 = domain58_2;
    this.domain58 += domain58_2;
  }
  public String getDomain58_3() {
    return domain58_3;
  }
  public void setDomain58_3(String domain58_3) {
    this.domain58_3 = domain58_3;
    this.domain58 += domain58_3;
  }

In other words, this subdomain message is followed by stitching back behind the 58 domains. If 58_1 includes sub-domains, like the wording here is not elaborated. So far, the first step is complete.
(WARNING: I mean here is a brief expression, according to the actual situation please consider using highly concurrent.)

Step 2: Create a variety of data conversion tools

Because in 8583, the message is transmitted numbers and letters, some converted into ASCII, and some just left / right by BCD fill 0, and so on. Here are the commonly used character conversion, if I need the full version here, please move on github.

    /**
     * 获取位元表
     *
     * @param list
     * @return
     */
    public static String getBitMap(List<Integer> list) {
        StringBuffer result = new StringBuffer("");
        byte[] bytes = new byte[64];
        for (int i = 0; i < 64; i++) {
            if (list.contains(i + 1)) {
                bytes[i] = 1;
            } else {
                bytes[i] = 0;
            }
        }
        StringBuffer sb = new StringBuffer("");
        for (int i = 0; i <= 64; i++) {
            if (i % 4 == 0 && i != 0) {
                result.append(
                        String.format("%x", Integer.valueOf(sb.toString(), 2))
                                .toUpperCase());
                sb.delete(0, sb.length());
                if (i < 64) {
                    sb.append(bytes[i]);
                }
            } else {
                sb.append(bytes[i]);
            }
        }
        log.info("bitMap=" + result.toString());
        return result.toString();
    }
    
    /**
         * 普通字符串转为ascii字符串
         *
         * @param asciiString 字节数组
         * @return
         */
        public static String asciiToHex(String asciiString) {
            if (asciiString == null) {
                return "";
            }
            StringBuffer buff = new StringBuffer();
            byte[] bytes = asciiString.getBytes();
            int len = bytes.length;
            for (int j = 0; j < len; j++) {
                if ((bytes[j] & 0xff) < 16) {
                    buff.append('0');
                }
                buff.append(Integer.toHexString(bytes[j] & 0xff).toUpperCase());
            }
            return buff.toString();
        }

Due to space limitations, I am here for the time being two examples listed first method, created a variety of tools, the second step is complete.

The third step: a package request

Package request is relatively simple, and the first bit tables were created, and then assign domain on it.

        //位元表填写
    Integer[] array = {2,3,4,11,25,41,42,58,60,63,64};
    List<Integer> list=  Arrays.asList(array);
    

Value represents the bit table inside here which has a value domain, create a list through the data, and then assign the time domain, and then list into a bit table.
For performing the following assignment, or to the sample code

Message8583Body body = new Message8583Body();
body.setMsgType("1111");
body.setBitMap(getBitMap(list));
body.setDomain2("2222");
body.setDomain3("3333");
body.setDomain4("4444");
···
body.setDomain58_1("581581581");
body.setDomain58_2("582582582");
body.setDomain58_3("583583583");
String domain58 = (这里调用实际报文转换的方式,一般58域是获取整体报文长度,拼装在58域的前面)(body.getDomain58(), 3);
body.setDomain58(domain58);

When your messages are set finished, call the service side and agreed manner, to calculate all the message length, to fight in front of the message. So far, the third step is complete.
After the three steps are done, then you can send a socket to the service side, and the rest is commissioning work.

Guess you like

Origin www.cnblogs.com/ragnaros/p/11304797.html