Пример #1
0
  @Override
  public void pack(Map<String, Object> fieldValues, ControlMessage cm, BusinessMessage bm)
      throws PacketOperationException {

    // 备付金密码
    FIXSTRINGPacketUtils.addFieldValue(fieldValues, "D_PREPAY_PWD", bm.getPrePayPwd());

    // 交易金额
    FIXSTRINGPacketUtils.addFieldValue(fieldValues, "D_AMOUNT", Double.toString(bm.getAmount()));

    // 用户号
    FIXSTRINGPacketUtils.addFieldValue(fieldValues, "D_USER_CODE", bm.getUserCode());

    // 附加响应数据
    FIXSTRINGPacketUtils.addFieldValue(fieldValues, "D_ADDITIONAL_TIP", bm.getAdditionalTip());

    // 货币代码
    FIXSTRINGPacketUtils.addFieldValue(fieldValues, "D_CURRENCY_CODE", bm.getCurrencyCode());

    // 自定义域
    FIXSTRINGPacketUtils.addFieldValue(fieldValues, "D_CUSTOM_FIELD", bm.getCustomField());

    // 原系统水流号
    FIXSTRINGPacketUtils.addFieldValue(fieldValues, "D_SYS_ORIGSEQNO", bm.getOrigSysJournalSeqno());
  }
Пример #2
0
  @Override
  public Map<DATA_TYPE, Object> packBuffer(Map<DATA_TYPE, Object> message)
      throws PacketOperationException {
    logger.info("开始进行FIXSTRING打包....");
    offset = 0;
    String packet = null;
    cm = PacketUtils.getControlMessage(message);
    bm = PacketUtils.getBusinessMessage(message);
    String tranCode = cm.getTranCode();

    // response code convert
    String resultCode = cm.getResultCode();
    if (GlobalConst.RESULTCODE_SUCCESS.equals(resultCode) && !"000010".equals(bm.getTranCode())) {
      bm.setResponseCode(GlobalConst.RESPONSECODE_SUCCESS);
    } else if (resultCode.equals("999999")) {
      // timeout or unknown result
      bm.setResponseCode("99");
      //					else
      //						bm.setResponseCode("01");
    }

    fieldValues.clear();
    headerHelper.pack(fieldValues, cm, bm);
    String header = packFIXSTRING();
    logger.info("交易{}打包包头完成,报文头[{}],用户号[{}]", new Object[] {tranCode, header, bm.getUserCode()});

    // pack body
    IPacketWEBSTRING packetHelper;
    String body = null;
    try {
      fieldValues.clear();

      packetHelper =
          (IPacketWEBSTRING) SpringContextHolder.getBean(getPacketBeanName(cm.getTranCode()));

      packetHelper.pack(fieldValues, cm, bm);
      body = packFIXSTRING();
      packet = header + body;

      // 减去报文头前10位+报文体作为MAB
      byte[] responseMac =
          getMac(packet.substring(10 + 6, packet.length()).getBytes("gb2312"), bm.getShopCode());
      logger.info("响应报文MAC值[{}]", responseMac);
      packet += ConvertUtils.bytes2HexStr(responseMac);

      // 报文长度处理
      packet =
          FieldUtils.leftAddZero4FixedLengthString(
                  String.valueOf(packet.getBytes("gb2312").length - 6), 6)
              + packet.substring(6);
      PacketUtils.setOrigAnsPacket(message, packet);
    } catch (InstantiationException e) {
      logger.error("get packet helper class error!", e);
      throw new PacketOperationException();
    } catch (IllegalAccessException e) {
      logger.error("get packet helper class error!", e);
      throw new PacketOperationException();
    } catch (ClassNotFoundException e) {
      logger.error("get packet helper class error!", e);
      throw new PacketOperationException();
    } catch (Exception e) {
      logger.error("get packet helper class error!", e);
      throw new PacketOperationException();
    }

    logger.info("交易{}报文打包完成,报文:[{}]", tranCode, packet);

    return message;
  }