private IcScriptUploadTradeResponseEntity unpack(byte[] respData) {
   byte[] respBodyData = new byte[respData.length - 7]; // respDataLength+tpduHeaderLength
   System.arraycopy(respData, 7, respBodyData, 0, respBodyData.length);
   IcScriptUploadTradeResponseEntity entity = new IcScriptUploadTradeResponseEntity();
   entity.unpack(respBodyData);
   return entity;
 }
  public PepsiColaResponseInfo process(
      CupsTrmnl cupsTrmnl, CupsKeyManage cupsKeyManage, PepsiColaRequestInfo request)
      throws TransferFailedException {
    logger.info("[PepsiCola渠道IC卡脚本上送开始...]");
    // 1.组装报文
    IcScriptUploadTradeRequestEntity requestEntity = packUp(cupsTrmnl, cupsKeyManage, request);
    // iso mac计算
    byte[] iso_8583_main = requestEntity.pack();
    byte[] input = ArrayUtils.subarray(iso_8583_main, 6, iso_8583_main.length - 8);
    byte[] macKey = CodecUtils.hex2byte(cupsKeyManage.getTrmnlMacKey());
    byte[] mac;
    try {
      mac = hsmService.calculateMAC_CUPS(macKey, input).getBytes();
      input = ArrayUtils.subarray(iso_8583_main, 0, iso_8583_main.length - 8);
      iso_8583_main = ArrayUtils.addAll(input, mac);
    } catch (HSMException e) {
      String hsmRespCode = XPOSPClientUtils.getCode(e);
      if (!AppExCode.UNKNOWN.equals(hsmRespCode)) {
        hsmRespCode = Const.TP_BEGIN_HSM + hsmRespCode;
      }
      logger.error("[IC卡脚本上送失败,calculate mac form hsm error code:" + hsmRespCode + "]");
      throw new TransferFailedException(
          hsmRespCode, "[IC卡脚本上送失败, 加密机计算MAC失败, errorCode:" + hsmRespCode + "]");
    }

    // 组装报文报文头
    byte[] iso_8583_body =
        ArrayUtils.addAll(
            XPOSPClientUtils.getTpduHeader(XpospSysProperty.getPepsiColaTPDU()).pack(),
            iso_8583_main);
    String iso_8583_body_length =
        StringUtils.leftPad(Integer.toHexString(iso_8583_body.length), 4, "0");
    byte[] iso_8583_length = ISOUtils.hex2byte(iso_8583_body_length);
    byte[] iso_8583 = ArrayUtils.addAll(iso_8583_length, iso_8583_body);

    // 新增银联CUPS流水记录 {2,3,4,11,22,25,26,35,36,41,42,49,52,53,60,64}
    String payNo = transRefNoGenerator.generate();
    PayCups payCups = new PayCups();
    payCups.setPayNo(payNo);
    payCups.setCardNo(requestEntity.getCardNo());
    payCups.setProcessCode(requestEntity.getProcessCode());
    payCups.setTrmnlFlowNo(requestEntity.getTrmnlFlowNo());
    payCups.setTrmnlBatchNo(cupsTrmnl.getTrmnlBatchNo());
    payCups.setPosEntryMode(requestEntity.getPosEntryMode());
    payCups.setCardSeqNum(request.getCardSeqNum());
    payCups.setTrmnlNo(requestEntity.getTrmnlNo());
    payCups.setTrmnlMrchNo(requestEntity.getTrmnlMrchNo());
    payCups.setCurrency(requestEntity.getCurrency());
    payCups.setIcData(request.getEmvTransInfo());
    payCups.setSelfDefined060(requestEntity.getSelfDefined60());
    payCups.setOriginalInfo(requestEntity.getOriginalMessage());
    payCups.setTransType(TransType.ICSCRIPTUPLOAD.getOrdinal());
    payCups.setSubChannel(SubChannelType.PEPSICOLATRANSFERCHANNEL.getChannelName());
    payCupsService.addPayCups(payCups);
    // 打包,新增流水记录后更新终端流水信息
    cupsTrmnlService.updateCupsTrmnlFlowNo(cupsTrmnl);

    // 2.发送报文
    byte[] respData =
        TCPUtils.getInstance().sendReciveMsg(iso_8583, XpospSysProperty.getPepsiColaIP_PORT());

    // 3.解析报文
    PepsiColaResponseInfo pepsiColaResponseInfo = new PepsiColaResponseInfo();
    try {
      IcScriptUploadTradeResponseEntity responseEntity = unpack(respData);
      String isoRespCode = responseEntity.getRespCode();
      if (!Const.ISO_RESPCODE_OK.equals(isoRespCode)) {
        payCups.setRespCode(isoRespCode);
        isoRespCode = isoRespCode.replace("A", "10");
        payCupsService.updatePayCups(payCups);
        isoRespCode =
            Const.TP_BEGIN_ISO + StringUtils.leftPad("" + Integer.parseInt(isoRespCode), 3, "0");

        logger.error("[pay via cups failed, iso error code:" + isoRespCode + "]");
        throw new TransferFailedException(
            isoRespCode, "[pay via cups failed, so error code:" + isoRespCode + "]");
      }

      // 更新交易流水
      payCups.setTransDate(responseEntity.getTransDate());
      payCups.setTransTime(responseEntity.getTransTime());
      payCups.setSettlementDate(responseEntity.getSettlementDate());
      payCups.setRespCode(responseEntity.getRespCode());
      payCupsService.updatePayCups(payCups);

      pepsiColaResponseInfo.setTransCode(
          Const.TP_BEGIN_ISO + StringUtils.leftPad("" + Integer.parseInt(isoRespCode), 3, "0"));
      // 响应
    } catch (RuntimeException e) {
      throw e;
    }
    logger.info("[PepsiCola渠道IC卡脚本上送结束...]");
    return pepsiColaResponseInfo;
  }