PageRenderTime 107ms CodeModel.GetById 18ms app.highlight 79ms RepoModel.GetById 1ms app.codeStats 0ms

/webccr/src/com/emis/caesar/senao/util/UU2Util.java

https://bitbucket.org/sanliou/synccr
Java | 1519 lines | 1213 code | 66 blank | 240 comment | 207 complexity | ecf8f1c8e6c93c970a8812b3405861b1 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1package com.emis.caesar.senao.util;
   2
   3import com.emis.caesar.emisString;
   4import com.emis.caesar.senao.UU2.ICERAPIReq;
   5import com.emis.caesar.senao.UU2.ICERAPIResp;
   6import com.emis.caesar.senao.UU2.ICERAPIRespItem;
   7import com.emis.caesar.senao.event.TButtonEventContext;
   8import com.emis.caesar.senao.event.logic.TLoEndSale;
   9import com.emis.caesar.senao.unit.TCcr;
  10import com.emis.caesar.senao.unit.TCcrConst;
  11import com.emis.caesar.senao.unit.sale.TPayment;
  12import com.emis.caesarui.webccr.object.UU2_ERRMSG;
  13import com.emis.caesarui.webccr.object.UU2_PARAMS;
  14import com.emis.caesarui.webccr.ui.window.WinUuCard;
  15import com.emis.caesarui.webccr.ui.window.WinUuCardDongle;
  16import com.emis.caesarui.webccr.webccr;
  17import com.emis.caesarui.webccr.webccrlog;
  18import com.emis.util.emisUtil;
  19import com.emis.util.emisXmlUtil;
  20import com.vaadin.ui.JavaScript;
  21import com.vaadin.ui.JavaScriptFunction;
  22import com.vaadin.ui.UI;
  23import de.steinwedel.messagebox.ButtonOption;
  24import de.steinwedel.messagebox.MessageBox;
  25import elemental.json.JsonArray;
  26import org.apache.commons.lang.StringEscapeUtils;
  27import org.w3c.dom.Document;
  28import org.w3c.dom.Element;
  29import org.w3c.dom.Node;
  30import org.w3c.dom.NodeList;
  31
  32import java.io.BufferedReader;
  33import java.io.ByteArrayInputStream;
  34import java.lang.reflect.Method;
  35import java.util.ArrayList;
  36import java.util.Hashtable;
  37import java.util.List;
  38
  39/**
  40 *  悠遊卡二代 API
  41 *  悠遊卡付款:
  42  加值:
  43  餘額查詢:
  44  dongle交易明細查詢
  45    加值 扣款 取消 退貨(加值 扣款) 重傳 需紀錄在EASYCARD
  46 */
  47public class UU2Util {
  48  private static final String CHARSET = "UTF-8";
  49  public final String sNewLine = "\\r\\n";
  50  //
  51  public static final String T0100_SIGNON = "0800";
  52  public static final String T0100_EACH = "0200";
  53  public static final String T0300_SIGNON = "881999";       // 登入
  54  public static final String T0300_PAY = "606100";          // 扣款
  55  public static final String T0300_PAY_VOID = "620061";    // 扣款退貨 or 取消
  56  public static final String T0300_ADD_CANCEL = "816100"; // 現金加值 作廢交易
  57  public static final String T0300_ADD_VALUE = "801061";  // 現金加值
  58  public static final String T0300_QUERY = "296000";  // 卡片資料查詢(餘額)
  59  public static final String T0300_DONGLE = "214100";  // DONGLE
  60  //
  61  private static boolean bDevelopMode = false;
  62  //
  63  TButtonEventContext parentEvent;
  64  WinUuCardDongle parentWin;
  65  webccr webccr;
  66  webccrlog webccrlog;
  67  TCcr ccr;
  68  int iUuCardAmt;// 悠遊卡 付款或加值金額
  69  TPayment oPayment = null;// 當前付款別物件
  70  boolean chkOK = false;
  71  ArrayList<String> sNOlist = new ArrayList<String>(); //起迄序號
  72  String sNO; // 調閱序號
  73  int iRetry = 0; // retry次數
  74  int TYPE = 0; // 0:登入 1 扣款 2 加值 3 取消 4 查詢 5 dongle 6 退貨(扣款作廢) 7 加值作廢
  75  WinUuCard oWindow = null;
  76  int time = 0; // 供銷退retry用
  77  /**
  78   * 作為悠遊卡成功、失敗callBack
  79   */
  80  Runnable successRunnable = null;
  81  /**
  82   * 存放付款別的資料
  83   */
  84  List<TPayment> salePList = new ArrayList<TPayment>();
  85
  86  // 悠遊卡 1 付款 or 2 加值
  87  public UU2Util(int iPayAmt, int iTYPE, TButtonEventContext eventContext) {
  88    this.iUuCardAmt = iPayAmt;
  89    this.TYPE = iTYPE;
  90    this.parentEvent = eventContext;
  91    webccr = (webccr) UI.getCurrent();
  92    ccr = webccr.getFoCCR();
  93    webccrlog = webccr.getlog();
  94  }
  95
  96  // 3 取消付款
  97  public UU2Util(TPayment payment) {
  98    this.oPayment = payment;
  99    webccr = (webccr) UI.getCurrent();
 100    ccr = webccr.getFoCCR();
 101    webccrlog = webccr.getlog();
 102    TYPE = 3;
 103  }
 104
 105  // 悠遊卡 4 查詢 or 0 登入
 106  public UU2Util() {
 107    webccr = (webccr) UI.getCurrent();
 108    ccr = webccr.getFoCCR();
 109    webccrlog = webccr.getlog();
 110  }
 111
 112  // 悠遊卡 5 dongle 重傳
 113  public UU2Util(ArrayList<String> list, WinUuCardDongle window) {
 114    this.sNOlist = list;
 115    this.parentWin = window;
 116    webccr = (webccr) UI.getCurrent();
 117    ccr = webccr.getFoCCR();
 118    webccrlog = webccr.getlog();
 119    TYPE = 5;
 120  }
 121
 122  // 6 扣款作廢
 123  public UU2Util(List<TPayment> paymentlist) {
 124    this.salePList = paymentlist;
 125    webccr = (webccr) UI.getCurrent();
 126    ccr = webccr.getFoCCR();
 127    webccrlog = webccr.getlog();
 128    TYPE = 6;
 129  }
 130
 131  // 7 加值作廢
 132  public UU2Util(int iPayAmt) {
 133    this.iUuCardAmt = iPayAmt;
 134    webccr = (webccr) UI.getCurrent();
 135    ccr = webccr.getFoCCR();
 136    webccrlog = webccr.getlog();
 137    TYPE = 7;
 138  }
 139
 140  // 0 登入
 141  public void signOnUUcard() {
 142//    webccrlog.info(webccr.getClass(),"門市機號:" + ccr.getCcrID() + " --->登入悠遊卡機");
 143    CcrUtil.setMessage("門市機號:" + ccr.getCcrID() + " --->登入悠遊卡機");
 144    TYPE = 0;
 145    ICERAPIReq _Req = new ICERAPIReq();
 146    try {
 147      // 產生物件值
 148      WriteSignOnRequest(_Req);
 149      //
 150      CallIcerApi(_Req);
 151    } catch (Exception e) {
 152//      webccrlog.error(webccr.getClass(), e);
 153      CcrUtil.setMessage(emisUtil.getStackTrace(e));
 154    }
 155  }
 156
 157  // 1 扣款
 158  public void DeductUUcard() {
 159//    webccrlog.info(webccr.getClass(),"-----悠遊卡扣款-----");
 160//    webccrlog.info(webccr.getClass(),"扣款金額 : " + iUuCardAmt);
 161    CcrUtil.setMessage("-----悠遊卡扣款-----");
 162    CcrUtil.setMessage("扣款金額 : " + iUuCardAmt);
 163    ICERAPIReq _Req = new ICERAPIReq();
 164    try {
 165      // 產生物件值
 166      WriteDeductRequest(_Req);
 167      //
 168      CallIcerApi(_Req);
 169    } catch (Exception e) {
 170//      webccrlog.error(webccr.getClass(), e);
 171      CcrUtil.setMessage(emisUtil.getStackTrace(e));
 172      callBack(false, "");
 173    }
 174  }
 175
 176  // 2 加值(DepoistUUcard)
 177  public void AddValueUUcard() {
 178//    webccrlog.info(webccr.getClass(),"-----悠遊卡加值-----");
 179//    webccrlog.info(webccr.getClass(),"加值金額 : " + iUuCardAmt);
 180    CcrUtil.setMessage("-----悠遊卡加值-----");
 181    CcrUtil.setMessage("加值金額 : " + iUuCardAmt);
 182    ICERAPIReq _Req = new ICERAPIReq();
 183    try {
 184      // 產生物件值
 185      WriteAddValueRequest(_Req);
 186      //
 187      CallIcerApi(_Req);
 188    } catch (Exception e) {
 189//      webccrlog.error(webccr.getClass(), e);
 190      CcrUtil.setMessage(emisUtil.getStackTrace(e));
 191      callBack(false, "");
 192    }
 193  }
 194
 195  // 3 取消扣款
 196  public void CancelDeductUUcard() {
 197//    webccrlog.info(webccr.getClass(),"-----悠遊卡取消扣款-----");
 198    CcrUtil.setMessage("-----悠遊卡取消扣款-----");
 199    // 正常不會是null
 200    if (oPayment == null) {
 201      ccr.UInotify.swErrMsg("查無悠遊卡付款項!");
 202      return;
 203    }
 204    // 呼叫卡機流程 
 205    ICERAPIReq _Req = new ICERAPIReq();
 206    try {
 207      // 產生物件值
 208      WriteCancelDeductRequest(_Req);
 209      //
 210      CallIcerApi(_Req);
 211    } catch (Exception e) {
 212//      webccrlog.error(webccr.getClass(), e);
 213      CcrUtil.setMessage(emisUtil.getStackTrace(e));
 214      callBack(false, "");
 215    }
 216  }
 217
 218  // 4 查詢餘額
 219  public void QueryUUcardBalance() {
 220//    webccrlog.info(webccr.getClass(),"-----悠遊卡查詢餘額-----");
 221    CcrUtil.setMessage("-----悠遊卡查詢餘額-----");
 222    TYPE = 4;
 223    ICERAPIReq _Req = new ICERAPIReq();
 224    try {
 225      // 產生物件值
 226      WriteQueryRequest(_Req);
 227      //
 228      CallIcerApi(_Req);
 229    } catch (Exception e) {
 230//      webccrlog.error(webccr.getClass(), e);
 231      CcrUtil.setMessage(emisUtil.getStackTrace(e));
 232      callBack(false, "");
 233    }
 234  }
 235
 236  // 5 dongle機交易明細查詢
 237  public void QueryUUcardRecord() {
 238//    webccrlog.info(webccr.getClass(),"-----悠遊卡dongle機交易明細查詢-----");
 239    CcrUtil.setMessage("-----悠遊卡dongle機交易明細查詢-----");
 240    if (sNOlist.size() > 0) {
 241      // 取當前的資料
 242      sNO = sNOlist.get(0);
 243//      webccrlog.info(webccr.getClass(),"目前查詢序號=" + sNO);
 244      CcrUtil.setMessage("目前查詢序號=" + sNO);
 245      ICERAPIReq _Req = new ICERAPIReq();
 246      try {
 247        // 產生物件值
 248        WriteQueryRecordRequest(_Req);
 249        //
 250        CallIcerApi(_Req);
 251      } catch (Exception e) {
 252//        webccrlog.error(webccr.getClass(), e);
 253        CcrUtil.setMessage(emisUtil.getStackTrace(e));
 254      }
 255    } else {
 256//      webccrlog.info(webccr.getClass(),"陣列已經為0");
 257      CcrUtil.setMessage("陣列已經為0");
 258      if (parentWin != null) {
 259        ccr.UInotify.swMessage("重傳完畢");
 260        parentWin.close();
 261      }
 262    }
 263  }
 264
 265  // 6 退款
 266  public void ReturnUUcard() {
 267//    webccrlog.info(webccr.getClass(),"-----悠遊卡扣款作廢-----");
 268    CcrUtil.setMessage("-----悠遊卡扣款作廢-----");
 269    if (salePList.size() != 0) {
 270      // 取當前的資料
 271      oPayment = salePList.get(0);
 272      ICERAPIReq _Req = new ICERAPIReq();
 273      try {
 274        // 產生物件值
 275        WriteReturnRequest(_Req);
 276        //
 277        CallIcerApi(_Req);
 278      } catch (Exception e) {
 279//        webccrlog.error(webccr.getClass(), e);
 280        CcrUtil.setMessage(emisUtil.getStackTrace(e));
 281      }
 282    } else {
 283      callBack(false, ""); // 正常作廢進來要有付款項
 284    }
 285  }
 286
 287  // 7 加值作廢
 288  public void CancelAddValueUUcard() {
 289//    webccrlog.info(webccr.getClass(),"-----悠遊卡加值作廢-----");
 290    CcrUtil.setMessage("-----悠遊卡加值作廢-----");
 291    ICERAPIReq _Req = new ICERAPIReq();
 292    try {
 293      // 產生物件值
 294      WriteCancelAddValueRequest(_Req);
 295      //
 296      CallIcerApi(_Req);
 297    } catch (Exception e) {
 298//      webccrlog.error(webccr.getClass(), e);
 299      CcrUtil.setMessage(emisUtil.getStackTrace(e));
 300      callBack(false, "");
 301    }
 302  }
 303
 304  private void CallIcerApi(ICERAPIReq _Req) {
 305    iRetry = 0; // retry次數
 306    // 讀檔
 307    JavaScript.getCurrent().addFunction("getOutFileContent", new JavaScriptFunction() {
 308      public void call(JsonArray arguments) {
 309        CcrUtil.setMessage("---UU_CARD getOutFileContent---");
 310        String _sRespones = arguments.getString(0);
 311        String _sXML = arguments.getString(1);
 312        CcrUtil.setMessage("ICERAPI.REQ content :" + _Req.toString());
 313        CcrUtil.setMessage("ICERAPI.RES content :" + _sRespones);
 314        if (emisUtil.isEmpty(_sRespones)) {
 315          ccr.UInotify.swErrMsg("ICERAPI無回應");
 316          callBack(false, "");
 317          return;
 318        } else {
 319          // 將回傳資料寫入 EASYCARD
 320          if (TYPE == 1 || TYPE == 2 || TYPE == 3 ||
 321              TYPE == 5 || TYPE == 6 || TYPE == 7) {
 322            String SL_KEY = ccr.getCcrID() + emisUtil.todayDateAll() + TYPE;
 323            boolean IS_RESEND = true;
 324            if (ccr.getCurrentSale() != null) {
 325              SL_KEY = ccr.getCurrentSale().getPrimarykey();
 326              if (TYPE != 5) {
 327                IS_RESEND = false;
 328              }
 329            }
 330            // 寫入table給後台傳到悠遊卡公司
 331            ccr.wrDataToDb.InsEASYCARD(SL_KEY, _sRespones, IS_RESEND, _Req, iRetry);
 332          }
 333          // 解析ICERAPI
 334          ICERAPIResp resp = ReadResponseFile(_sRespones);
 335          if (bDevelopMode) {
 336            MessageBox _oMsgBox = MessageBox.createInfo();
 337            _oMsgBox.withCaption("訊息")
 338                .withMessage("是否進行Retry?")
 339                .withYesButton(() -> {
 340                  iRetry++;
 341                  MessageBox _oErrBox = MessageBox.createError();
 342                  _oErrBox.withCaption("錯誤")
 343                      .withMessage("卡機連線Timeout, 請按下確認鍵Rerry! Retry次數:" + iRetry)
 344                      .withOkButton(() -> {
 345//                        webccrlog.info(webccr.class, "-------進行Retry動作-------");
 346                        CcrUtil.setMessage("-------進行Retry動作-------");
 347                        if (iRetry > 3) {
 348                          ccr.UInotify.swErrMsg("Retry已超過3次!");
 349                          callBack(false, "");
 350                          return;
 351                        }
 352                        if (iRetry <= 3) {
 353                          _Req.setT1200(emisUtil.todayTimeS());
 354                          _Req.setT1300(emisUtil.todayDate());
 355                          uRunIcerApi(_Req);
 356                        }
 357                      }, ButtonOption.focus()).open();
 358                }, ButtonOption.focus())
 359                .withNoButton(() -> {
 360                  if (resp != null) {
 361                    // 有回傳時, 檢查是否符合retry條件, 再進入retry程序
 362                    if ( ("-125".equals(resp.getT3901()) || "6008".equals(resp.getT3904())) ) {
 363                      iRetry++;
 364                      MessageBox _oErrBox = MessageBox.createError();
 365                      _oErrBox.withCaption("錯誤")
 366                          .withMessage("卡機連線Timeout, 請按下確認鍵Rerry! Retry次數:" + iRetry)
 367                          .withOkButton(() -> {
 368//                            webccrlog.info(webccr.class, "-------進行Retry動作-------");
 369                            CcrUtil.setMessage("-------進行Retry動作-------");
 370                            if (iRetry > 3) {
 371                              ccr.UInotify.swErrMsg("Retry已超過3次!");
 372                              callBack(false, "");
 373                              return;
 374                            }
 375                            if (iRetry <= 3) {
 376                              _Req.setT1200(emisUtil.todayTimeS());
 377                              _Req.setT1300(emisUtil.todayDate());
 378                              uRunIcerApi(_Req);
 379                            }
 380                          }, ButtonOption.focus()).open();
 381                    } else {
 382                      doAction(resp, _Req);
 383                      if (TYPE == 0) {
 384                        // 變更XML
 385                        updateINI(_sXML);
 386                      }
 387                    }
 388                  } else {
 389                    ccr.UInotify.swErrMsg("出現異常:超出解析的TAG\n" + _sRespones);
 390                    callBack(false, "");
 391                    return;
 392                  }
 393                }).open();
 394          } else {
 395            if (resp != null) {
 396              // 有回傳時, 檢查是否符合retry條件, 再進入retry程序
 397              if ( ("-125".equals(resp.getT3901()) || "6008".equals(resp.getT3904())) ) {
 398                iRetry++;
 399                MessageBox _oErrBox = MessageBox.createError();
 400                _oErrBox.withCaption("錯誤")
 401                    .withMessage("卡機連線Timeout, 請按下確認鍵Rerry! Retry次數:" + iRetry)
 402                    .withOkButton(() -> {
 403                      CcrUtil.setMessage("-------進行Retry動作-------");
 404                      if (iRetry > 3) {
 405                        ccr.UInotify.swErrMsg("Retry已超過3次!");
 406                        callBack(false, "");
 407                        return;
 408                      }
 409                      if (iRetry <= 3) {
 410                        _Req.setT1200(emisUtil.todayTimeS());
 411                        _Req.setT1300(emisUtil.todayDate());
 412                        uRunIcerApi(_Req);
 413                      }
 414                    }, ButtonOption.focus()).open();
 415              } else {
 416                doAction(resp, _Req);
 417                if (TYPE == 0) {
 418                  // 變更XML
 419                  updateINI(_sXML);
 420                }
 421              }
 422            } else {
 423              ccr.UInotify.swErrMsg("出現異常:超出解析的TAG\n" + _sRespones);
 424              callBack(false, "");
 425              return;
 426            }
 427          }
 428        }
 429      }
 430    });
 431
 432    JavaScript.getCurrent().addFunction("ErrorMessage",new JavaScriptFunction() {
 433      public void call(JsonArray arguments) {
 434        try {
 435          CcrUtil.setMessage("ErrorMessage:" + arguments.getString(0));
 436          int iErrType = emisUtil.parseInt(arguments.getString(0), 0);
 437          switch (iErrType) {
 438            case 1:
 439              ccr.UInotify.swErrMsg("REQ, RES 檔有問題. 請通知資訊人員處理!");
 440              break;
 441            case 2:
 442              ccr.UInotify.swErrMsg("ICERAPI無回應");
 443              break;
 444            default:
 445              ccr.UInotify.swErrMsg("非設定的錯誤訊息, 請通知資訊人員處理!");
 446              break;
 447          }
 448        } catch (Exception e) {
 449          CcrUtil.setMessage(emisUtil.getStackTrace(e));
 450        } finally {
 451          callBack(false, "");
 452        }
 453      }
 454    });
 455
 456    JavaScript.getCurrent().addFunction("CheckFile", new JavaScriptFunction() {
 457      public void call(JsonArray arguments) {
 458        CcrUtil.setMessage("---UU_CARD CheckFile---");
 459        String _sReq = arguments.getString(0);
 460        CcrUtil.setMessage("File => " + _sReq);
 461        if (_sReq.indexOf("<T0300>") > -1) {
 462          String T0300 = _sReq.substring(_sReq.indexOf("<T0300>") + "<T0300>".length(),
 463              _sReq.indexOf("</T0300>"));
 464          if (T0300 != null && !T0300.equals(_Req.T0300)) {
 465            ccr.UInotify.swErrMsg("RES 檔有問題. 請通知資訊人員處理!");
 466            callBack(false, "");
 467            return;
 468          }
 469        }
 470        if (_sReq.indexOf("<T1200>") > -1) {
 471          String T1200 = _sReq.substring(_sReq.indexOf("<T1200>") + "<T1200>".length(),
 472              _sReq.indexOf("</T1200>"));
 473          if (T1200 != null && !T1200.equals(_Req.T1200)) {
 474            ccr.UInotify.swErrMsg("RES 檔有問題. 請通知資訊人員處理!");
 475            callBack(false, "");
 476            return;
 477          }
 478        }
 479        if (_sReq.indexOf("<T1300>") > -1) {
 480          String T1300 = _sReq.substring(_sReq.indexOf("<T1300>") + "<T1300>".length(),
 481              _sReq.indexOf("</T1300>"));
 482          if (T1300 != null && !T1300.equals(_Req.T1300)) {
 483            ccr.UInotify.swErrMsg("RES 檔有問題. 請通知資訊人員處理!");
 484            callBack(false, "");
 485            return;
 486          }
 487        }
 488        uRunIcerApi2();
 489      }
 490    });
 491
 492    uRunIcerApi(_Req);
 493  }
 494
 495  private void uRunIcerApi(ICERAPIReq _Req) {
 496    String PATH = ccr.getPLUG_DISK() + "emis/senao/ICERAPI/"; // 悠遊卡
 497    String DATA_PATH = PATH + "ICERData/"; // DATA路徑
 498    String INI_XML = PATH + "ICERINI.xml"; // XML路徑
 499    String IN_FILE = DATA_PATH + "ICERAPI.REQ"; // REQ檔
 500    String IN_FILE_OK = DATA_PATH + "ICERAPI.REQ.OK"; // REQ檔
 501    String OUT_FILE = DATA_PATH + "ICERAPI.RES"; // RES檔
 502    String OUT_FILE_OK = DATA_PATH + "ICERAPI.RES.OK"; // RES檔
 503    String BAT_FILE1 = PATH + "ICERAPI1.bat"; // 刪檔bat
 504    String BAT_FILE2 = PATH + "ICERAPI2.bat"; //批次檔做為開啟exe
 505    String BAT_CONTENT1 = " del " + IN_FILE + sNewLine +
 506        " del " + IN_FILE_OK + sNewLine +
 507        " del " + OUT_FILE + sNewLine +
 508        " del " + OUT_FILE_OK;
 509    String BAT_CONTENT2 = "cd " + PATH + sNewLine + "ICERAPI.exe";
 510    String ContentXML = "";
 511    if (TYPE == 0) {
 512      ContentXML = CreateXML(_Req); // 登入
 513    } else if (TYPE == 1) {
 514      ContentXML = CreateXML1(_Req); // 扣款
 515    } else if (TYPE == 2) {
 516      ContentXML = CreateXML2(_Req); // 加值
 517    } else if (TYPE == 3) {
 518      ContentXML = CreateXML3(_Req); // 取消付款
 519    } else if (TYPE == 4) {
 520      ContentXML = CreateXML4(_Req); // 查詢
 521    } else if (TYPE == 5) {
 522      ContentXML = CreateXML5(_Req); // DONGLE 重傳
 523    } else if (TYPE == 6) {
 524      ContentXML = CreateXML6(_Req); // 扣款作廢
 525    } else if (TYPE == 7) {
 526      ContentXML = CreateXML7(_Req); //  加值作廢
 527    }
 528
 529    JavaScript.getCurrent().execute(
 530        " var util = new emisUtility(); \n" +
 531            // 設定路徑和檔案參數
 532            " var _sINI_XML = '" + INI_XML + "'; \n" +
 533            " var _sREQ_PATH = '" + IN_FILE + "'; \n" +
 534            " var _sREQ_PATH_OK = '" + IN_FILE_OK + "'; \n" +
 535            " var _sRES_PATH = '" + OUT_FILE + "'; \n" +
 536            " var _sRES_PATH_OK = '" + OUT_FILE_OK + "'; \n" +
 537            " var _sBAT_FILE1 = '" + BAT_FILE1 + "'; \n" +
 538            " var _sBAT_FILE2 = '" + BAT_FILE2 + "'; \n" +
 539            " var _sBAT_CONTENT1 = '" + BAT_CONTENT1 + "'; \n" +
 540            " var _sBAT_CONTENT2 = '" + BAT_CONTENT2 + "'; \n" +
 541            " var _sINContent = '" + ContentXML + "'; \n" +
 542            // 寫入BAT1檔
 543            " console.log('is or not write => BAT1'); \n" +
 544            " if (!util.exists(_sBAT_FILE1)) {" +
 545            " util.writeStringToUTF8File(_sBAT_FILE1, _sBAT_CONTENT1); " +
 546            " } \n" +
 547            // 執行刪檔
 548            " console.log('deletefile by BAT1 => REQ and RES'); \n" +
 549            " util.executewait(_sBAT_FILE1); \n" +
 550            //寫入REQ檔
 551            " console.log('write => REQ'); \n" +
 552            " util.writeStringToUTF8File(_sREQ_PATH, _sINContent); \n" +
 553            //寫入REQ.OK檔
 554            " console.log('write => REQ.OK'); \n" +
 555            " util.writeStringToUTF8File(_sREQ_PATH_OK, ''); \n" +
 556            //辨識檔案是否有寫成功
 557            " console.log('check => REQ'); \n" +
 558            " if (!util.exists(_sREQ_PATH)) { \n" +
 559            " ErrorMessage('1'); \n " +
 560            " } else {\n" +
 561            " var _sStr = util.readFileAsString(_sREQ_PATH); \n" +
 562            " CheckFile(_sStr); \n" +
 563            " }"
 564            /*
 565            //寫入BAT2檔
 566            " console.log('is or not write => BAT2'); \n" +
 567            " if (!util.exists(_sBAT_FILE2)) {" +
 568            " util.writeStringToUTF8File(_sBAT_FILE2, _sBAT_CONTENT2); } \n" +
 569            //執行ICERAPI.bat
 570            " console.log('executewait => BAT2'); \n" +
 571            " util.executewait(_sBAT_FILE2); \n" +
 572            //讀取out.dat
 573            " console.log('is or not read => RES'); \n" +
 574            " if (util.exists(_sRES_PATH_OK)) { \n" +
 575            " var _sStr = util.readFileAsString(_sRES_PATH); \n" +
 576            " var _sStr2 = util.readFileAsString(_sINI_XML); \n" +
 577            " getOutFileContent(_sStr, _sStr2); \n" +
 578            " console.log('End'); \n" +
 579            " } else { \n" +
 580            " ErrorMessage('2'); \n" +
 581            " return; \n" +
 582            " }"
 583            */
 584    );
 585  }
 586
 587  private void uRunIcerApi2() {
 588    String PATH = ccr.getPLUG_DISK() + "emis/senao/ICERAPI/"; // 悠遊卡
 589    String DATA_PATH = PATH + "ICERData/"; // DATA路徑
 590    String INI_XML = PATH + "ICERINI.xml"; // XML路徑
 591    String OUT_FILE = DATA_PATH + "ICERAPI.RES"; // RES檔
 592    String OUT_FILE_OK = DATA_PATH + "ICERAPI.RES.OK"; // RES檔
 593    String BAT_FILE2 = PATH + "ICERAPI2.bat"; //批次檔做為開啟exe
 594    String BAT_CONTENT2 = "cd " + PATH + sNewLine + "ICERAPI.exe";
 595
 596    JavaScript.getCurrent().execute(
 597        " var util = new emisUtility(); \n" +
 598            // 設定路徑和檔案參數
 599            " var _sINI_XML = '" + INI_XML + "'; \n" +
 600            " var _sRES_PATH = '" + OUT_FILE + "'; \n" +
 601            " var _sRES_PATH_OK = '" + OUT_FILE_OK + "'; \n" +
 602            " var _sBAT_FILE2 = '" + BAT_FILE2 + "'; \n" +
 603            " var _sBAT_CONTENT2 = '" + BAT_CONTENT2 + "'; \n" +
 604            //寫入BAT2檔
 605            " console.log('is or not write => BAT2'); \n" +
 606            " if (!util.exists(_sBAT_FILE2)) {" +
 607            " util.writeStringToUTF8File(_sBAT_FILE2, _sBAT_CONTENT2); } \n" +
 608            //執行ICERAPI.bat
 609            " console.log('executewait => BAT2'); \n" +
 610            " util.executewait(_sBAT_FILE2); \n" +
 611            //讀取out.dat
 612            " console.log('is or not read => RES'); \n" +
 613            " if (util.exists(_sRES_PATH_OK)) { \n" +
 614            " var _sStr = util.readFileAsString(_sRES_PATH); \n" +
 615            " var _sStr2 = util.readFileAsString(_sINI_XML); \n" +
 616            " getOutFileContent(_sStr, _sStr2); \n" +
 617            " console.log('End'); \n" +
 618            " } else { \n" +
 619            " ErrorMessage('2'); \n" +
 620            " return; \n" +
 621            " }"
 622    );
 623  }
 624
 625  private ICERAPIResp ReadResponseFile(String content) {
 626    BufferedReader br = null;
 627    ByteArrayInputStream bis = null;
 628    StringBuffer sb = new StringBuffer();
 629    ICERAPIResp resp = null;
 630    try {
 631      sb.append(content);
 632      //
 633      resp = new ICERAPIResp();
 634      bis = new ByteArrayInputStream(sb.toString().getBytes(CHARSET));
 635      Document doc = emisXmlUtil.getXML(bis);
 636      NodeList Nodelist = doc.getElementsByTagName("TRANS");
 637      NodeList Nodelistitem = doc.getElementsByTagName("T5548");
 638      ArrayList<ICERAPIRespItem> respItem = new ArrayList<ICERAPIRespItem>();
 639      ICERAPIRespItem item = null;
 640      for (int i = 0; i < Nodelist.getLength(); i++) {
 641        Node node = Nodelist.item(i);
 642        Node child = node.getFirstChild();
 643        while (child != null) {
 644//          System.out.println(child.getNodeName());
 645          Method method = ReflectUtils.getMethodByName(resp, "set" + child.getNodeName());
 646          if (method != null) {
 647            try {
 648              if (child.getNodeType() == node.ELEMENT_NODE) {
 649                Element element = (Element) child;
 650                if (child.getNodeName().equals(element.getTagName())) {
 651                  Node nItem = Nodelistitem.item(0);
 652                  if (nItem != null && child.getNodeName().equals(nItem.getNodeName())) {
 653                    //
 654                    item = new ICERAPIRespItem();
 655                    Node childitem = nItem.getFirstChild();
 656                    while (childitem != null) {
 657//                        System.out.println(childitem.getNodeName());
 658                      Method methodItem = ReflectUtils.getMethodByName(item, "set" + childitem.getNodeName());
 659                      if (methodItem != null) {
 660                        if (childitem.getNodeType() == nItem.ELEMENT_NODE) {
 661                          Element elementitem = (Element) childitem;
 662                          if (childitem.getNodeName().equals(elementitem.getTagName())) {
 663                            if (childitem.getFirstChild() != null) {
 664                              methodItem.invoke(item,
 665                                  emisUtil.parseString(elementitem.getFirstChild().getNodeValue()));
 666                            }
 667                          }
 668                        }
 669                      }
 670                      childitem= childitem.getNextSibling();
 671                    }
 672                    //
 673                    respItem.add(item);
 674                    if (child.getFirstChild() != null) {
 675                      method.invoke(resp,
 676                          respItem);
 677                    }
 678                  } else {
 679                    if (child.getFirstChild() != null) {
 680                      method.invoke(resp,
 681                          emisUtil.parseString(element.getFirstChild().getNodeValue()));
 682                    }
 683                  }
 684                }
 685              }
 686            } catch (Exception e) {
 687//              e.printStackTrace();
 688//              webccrlog.error(webccr.getClass(), e);
 689              CcrUtil.setMessage(emisUtil.getStackTrace(e));
 690            }
 691          }
 692          child= child.getNextSibling();
 693        }
 694      }
 695//      CcrUtil.setMessage(resp.toString());
 696    } catch (Exception e) {
 697//      e.printStackTrace();
 698//      webccrlog.error(webccr.getClass(), e);
 699      CcrUtil.setMessage(emisUtil.getStackTrace(e));
 700      return null;
 701    } finally {
 702      try {
 703        if(br != null) br.close();
 704        if(bis != null) bis.close();
 705      } catch (Exception e) {
 706      }
 707    }
 708    return resp;
 709  }
 710
 711  private void doAction(ICERAPIResp resp, ICERAPIReq _Req) {
 712    if (TYPE == 0) {
 713      // 登入
 714      if ("0".equals(resp.getT3901())) {
 715        CcrUtil.setMessage("---UU_CARD 登入成功---");
 716      } else {
 717//        ERROR_MSG(resp);
 718      }
 719    } else if (TYPE == 1) {
 720      // 扣款
 721      if ("0".equals(resp.getT3901())) {
 722        if (!_Req.T1200.equals(resp.getT1200()) ||
 723            !_Req.T1300.equals(resp.getT1300())) {
 724          //CcrUtil.setMessage("res內容與req所回傳不一致");
 725          ccr.UInotify.swErrMsg("res內容與req所回傳不一致");
 726          callBack(false, "");
 727          return;
 728        }
 729        CcrUtil.setMessage("---UU_CARD 扣款成功---");
 730        // 悠遊卡付款
 731        oPayment = new TPayment(TCcrConst.PAY_77, TCcrConst.PAY_NAME_77);
 732        oPayment.setSn(ccr.getCurrentSale().getPaymentCount() + 1); // RECNO
 733        oPayment.setAmount(iUuCardAmt); // 付款金額
 734        oPayment.setEASY_CARDNO(emisUtil.parseString(resp.getT0200())); // 悠遊卡明碼(T0211, 隱碼為載具使用) 為T0200
 735        oPayment.setSP_FIELD1("UU");
 736        oPayment.setSP_FIELD3(emisUtil.parseString(resp.getT0200()));
 737        ccr.getCurrentSale().addPayment(oPayment);
 738        // 列印內容
 739        String SL_KEY = ccr.getCurrentSale().getPrimarykey();
 740        String content = PrintContent(resp);
 741        // 列印扣款憑證
 742        PrintUUCard(content, SL_KEY);
 743        // 更新資料避免發生錯誤
 744        ccr.UInotify.updateMainForm();
 745        if (parentEvent != null) {
 746          parentEvent.finalProcedure();
 747        }
 748        callBack(true, "");
 749        // 尚有付款金額
 750        if (ccr.getCurrentSale().getUnpaidAmout() != 0) {
 751        } else {
 752          // 回到按鈕事件
 753          if (parentEvent != null) {
 754            //add by Ares 20191218 交易完成後不顯示結束確認視窗
 755            /*
 756            String MSG = "交易款項已付清, 是否結束本交易?";
 757            CcrUtil.setMessage("悠遊卡已付款是否結束本交易:" + ccr.getCurrentSale().getPrimarykey());
 758            ccr.UInotify.askYesOrNo(true, MSG, parentEvent, "clickYes", "clickNo");
 759            */
 760
 761            CcrUtil.setMessage("悠遊卡已付款, 確認結束交易:" + ccr.getCurrentSale().getPrimarykey());
 762            runEndSale();
 763          } else {
 764            runEndSale();
 765          }
 766        }
 767      } else {
 768        ERROR_MSG(resp);
 769        callBack(false, "");
 770      }
 771    } else if (TYPE == 2) {
 772      // 加值
 773      if ("0".equals(resp.getT3901())) {
 774        if (!_Req.T1200.equals(resp.getT1200()) ||
 775            !_Req.T1300.equals(resp.getT1300())) {
 776          ccr.UInotify.swErrMsg("res內容與req所回傳不一致");
 777          callBack(false, "");
 778          return;
 779        }
 780        CcrUtil.setMessage("---UU_CARD 加值成功 and 後續動作---");
 781        // 現金付款 
 782        oPayment = new TPayment(TCcrConst.PAY_CASH, TCcrConst.PAY_NAME_CASH);
 783        oPayment.setSn(ccr.getCurrentSale().getPaymentCount() + 1); // RECNO
 784        oPayment.setAmount(iUuCardAmt);
 785        oPayment.setSP_FIELD1("UU");
 786        oPayment.setSP_FIELD3(emisUtil.parseString(resp.getT0200()));
 787        oPayment.setEASY_CARDNO(emisUtil.parseString(resp.getT0200()));
 788        ccr.getCurrentSale().addPayment(oPayment);
 789        ccr.getCurrentSale().setbUUAddValue(true);  // 判斷為悠遊卡加值
 790        ccr.UInotify.updateMainForm();
 791        // 列印內容
 792        String SL_KEY = ccr.getCurrentSale().getPrimarykey();
 793        String content = PrintContent(resp);
 794        // 列印加值憑證
 795        PrintUUCard(content, SL_KEY);
 796        // 存檔
 797        runEndSale();
 798        //
 799        callBack(true, "");
 800      } else {
 801        ERROR_MSG(resp);
 802        callBack(false, "");
 803      }
 804    } else if (TYPE == 3) {
 805      // 取消付款
 806      if ("0".equals(resp.getT3901())) {
 807        if (!_Req.T1200.equals(resp.getT1200()) ||
 808            !_Req.T1300.equals(resp.getT1300())) {
 809          ccr.UInotify.swErrMsg("res內容與req所回傳不一致");
 810          callBack(false, "");
 811          return;
 812        }
 813        CcrUtil.setMessage("---UU_CARD 取消付款成功---");
 814        oPayment.setCancel(true);
 815        oPayment.setEASY_CARDNO_T0211(emisUtil.parseString(resp.getT0211()));
 816        // 列印內容
 817        String SL_KEY = ccr.getCurrentSale().getPrimarykey();
 818        String content = PrintContent(resp);
 819        // 列印取消付款憑證
 820        PrintUUCard(content, SL_KEY);
 821        // 返回取消付款按鈕的事件
 822        callBack(true, "");
 823      } else {
 824        // 是否返回按鈕?
 825        ERROR_MSG(resp);
 826        // 返回取消付款按鈕的事件
 827        callBack(false, "");
 828      }
 829    } else if (TYPE == 4) {
 830      // 查詢
 831      if ("0".equals(resp.getT3901())) {
 832        if (!_Req.T1200.equals(resp.getT1200()) ||
 833            !_Req.T1300.equals(resp.getT1300())) {
 834          ccr.UInotify.swErrMsg("res內容與req所回傳不一致");
 835          callBack(false, "");
 836          return;
 837        }
 838        String sAmount = resp.getT0410();
 839        try {
 840          int iAmount = emisUtil.parseInt(sAmount) / 100;
 841          CcrUtil.setMessage("悠遊卡餘額 = " + iAmount);
 842          ccr.UInotify.wrMessageToMainDisplay("悠遊卡餘額 = " + iAmount);
 843        } catch (Exception e) {
 844          CcrUtil.setMessage(emisUtil.getStackTrace(e));
 845          ccr.UInotify.swErrMsg("悠遊卡餘額 = " + sAmount);
 846        }
 847        callBack(true, "");
 848      } else {
 849        ERROR_MSG(resp);
 850        callBack(false, "");
 851      }
 852    } else if (TYPE == 5) {
 853      // DONGLE 重傳
 854      if ("0".equals(resp.getT3901())) {
 855        if (!_Req.T1200.equals(resp.getT1200()) ||
 856            !_Req.T1300.equals(resp.getT1300())) {
 857          ccr.UInotify.swErrMsg("res內容與req所回傳不一致");
 858          callBack(false, "");
 859          return;
 860        }
 861        CcrUtil.setMessage("序號:" + sNO + "---重傳成功---");
 862        //將當前處理的sNO刪除\
 863        if (sNOlist.size() > 0) {
 864          sNOlist.remove(0);
 865        }
 866//        webccrlog.info(webccr.getClass(),"移除當前序號:" + sNO);
 867        CcrUtil.setMessage("移除當前序號:" + sNO);
 868        // 一直call QueryUUcardRecord 直到 sNOlist陣列為0.
 869        QueryUUcardRecord();
 870      } else {
 871        ERROR_MSG(resp);
 872        if (parentWin != null) {
 873          parentWin.close();
 874        }
 875      }
 876    } else if (TYPE == 6) {
 877      // 扣款作廢
 878      if ("0".equals(resp.getT3901())) {
 879        if (!_Req.T1200.equals(resp.getT1200()) ||
 880            !_Req.T1300.equals(resp.getT1300())) {
 881          ccr.UInotify.swErrMsg("res內容與req所回傳不一致");
 882          callBack(false, "");
 883          return;
 884        }
 885        CcrUtil.setMessage("---UU_CARD 扣款作廢成功---");
 886        // 返回作廢動作
 887        //將當前處理的SALE_P刪除
 888        if (salePList.size() > 0) {
 889          salePList.remove(0);
 890        }
 891        // 列印內容
 892        String SL_KEY = ccr.getCurrentSale().getPrimarykey();
 893        String content = PrintContent(resp);
 894        // 列印退貨憑證
 895        PrintUUCard(content, SL_KEY);
 896        //
 897        if (salePList.size() > 0) {
 898          MessageBox _oMsgBox = MessageBox.createInfo();
 899          _oMsgBox.withCaption("訊息")
 900              .withMessage("處理完成,尚有悠遊卡" + salePList.size() + "筆交易未完成,請按確定繼續。")
 901              .withYesButton(() -> {
 902                // 取當前的資料
 903                oPayment = salePList.get(0);
 904                ICERAPIReq Req = new ICERAPIReq();
 905                try {
 906                  // 產生物件值
 907                  WriteReturnRequest(Req);
 908                  //
 909                  CallIcerApi(Req);
 910                } catch (Exception e) {
 911                  CcrUtil.setMessage(emisUtil.getStackTrace(e));
 912                }
 913              }, ButtonOption.focus())
 914              .open();
 915        } else {
 916          callBack(true, "");
 917        }
 918      } else {
 919        ERROR_MSG(resp);
 920        callBack(false, "");
 921      }
 922    } else if (TYPE == 7) {
 923      // 加值作廢
 924      if ("0".equals(resp.getT3901())) {
 925        if (!_Req.T1200.equals(resp.getT1200()) ||
 926            !_Req.T1300.equals(resp.getT1300())) {
 927          ccr.UInotify.swErrMsg("res內容與req所回傳不一致");
 928          callBack(false, "");
 929          return;
 930        }
 931        CcrUtil.setMessage("---UU_CARD 加值作廢成功---");
 932        // 列印內容
 933        String SL_KEY = ccr.getCurrentSale().getPrimarykey();
 934        String content = PrintContent(resp);
 935        // 列印退貨憑證
 936        PrintUUCard(content, SL_KEY);
 937        // 返回作廢動作
 938        callBack(true, "");
 939      } else {
 940        ERROR_MSG(resp);
 941        callBack(false, "");
 942      }
 943    }
 944  }
 945
 946  // 修改INI.XML
 947  private void updateINI(String INI) {
 948    StringBuffer sb = new StringBuffer();
 949    INI = INI.replace("??","<");
 950    INI = INI.replaceAll("\r\n", "\\\\r\\\\n");
 951    try {
 952      String S_NO = emisString.lPadB(ccr.getStore().getFLDxS_NO(), 10, '0');
 953      String ID_NO = ccr.getCcrID().substring(6);
 954
 955      int S_NO_S = INI.indexOf("<TMLocationID>");
 956      int S_NO_E = INI.indexOf("</TMLocationID>");
 957
 958      int ID_NO_S = INI.indexOf("<TMID>");
 959      int ID_NO_E = INI.indexOf("</TMID>");
 960
 961      sb.append(INI.substring(0, S_NO_S + "<TMLocationID>".length()));
 962      sb.append(S_NO);
 963      sb.append(INI.substring(S_NO_E, ID_NO_S + "<TMID>".length()));
 964      sb.append(ID_NO);
 965      sb.append(INI.substring(ID_NO_E, INI.length()));
 966      System.out.println("INI = " + sb.toString());
 967    } catch (Exception e) {
 968//      webccrlog.error(webccr.getClass(), e);
 969      CcrUtil.setMessage(emisUtil.getStackTrace(e));
 970    }
 971
 972    if (!emisUtil.isEmpty(sb.toString())) {
 973      String PATH = ccr.getPLUG_DISK() + "emis/senao/ICERAPI/ICERINI.xml"; // 悠遊卡
 974      JavaScript.getCurrent().execute(
 975          " var util = new emisUtility(); \n" +
 976          " var path = '" + PATH + "' \n" +
 977          " var a = '" + sb.toString() + "' \n" +
 978          " util.writeStringToUTF8File(path, a);"
 979      );
 980    }
 981  }
 982
 983  // 錯誤訊息
 984  private void ERROR_MSG(ICERAPIResp resp) {
 985    String sT3901 = resp.getT3901();
 986    String sT3902 = resp.getT3902();
 987    String sT3904 = resp.getT3904();
 988    String sT3900 = resp.getT3900();
 989    String sT3903 = resp.getT3903();
 990    StringBuffer sb = new StringBuffer();
 991    sb.append("錯誤代碼(3901):").append(emisUtil.parseString(sT3901)).append(",").append(ERROR_CODE_NAME("T3901", sT3901)).append("\n");
 992    sb.append("錯誤代碼(3900):").append(emisUtil.parseString(sT3900)).append(",").append(ERROR_CODE_NAME("T3900", sT3900)).append("\n");
 993    sb.append("錯誤代碼(3902):").append(emisUtil.parseString(sT3902)).append(",").append(ERROR_CODE_NAME("T3902", sT3902)).append("\n");
 994    sb.append("錯誤代碼(3903):").append(emisUtil.parseString(sT3903)).append(",").append(ERROR_CODE_NAME("T3903", sT3903)).append("\n");
 995    sb.append("錯誤代碼(3904):").append(emisUtil.parseString(sT3904)).append(",").append(ERROR_CODE_NAME("T3904", sT3904));
 996    ccr.UInotify.swErrMsg(sb.toString());
 997    CcrUtil.setMessage(sb.toString());
 998  }
 999
1000  // 0 登入物件
1001  private void WriteSignOnRequest(ICERAPIReq requset) {
1002    requset.setT0100(T0100_SIGNON);
1003    requset.setT0300(T0300_SIGNON); // 特定actoin code
1004    requset.setT1100(emisString.lPadB("", 4, '0'));  // 交易流水號
1005    requset.setT1200(emisUtil.todayTimeS());
1006    requset.setT1300(emisUtil.todayDate());
1007    try {
1008      Hashtable SQL_PARAMS = UU2_PARAMS.getInstance(emisUtil.getServletContext()).getHash();
1009      requset.setT4200(emisUtil.parseString(SQL_PARAMS.get(ccr.getCcrID() + "T4200"),
1010          "000000000000000")); // 按機台讀取設定值
1011      requset.setT5503(emisUtil.parseString(SQL_PARAMS.get(ccr.getCcrID() + "T5503"),
1012          "000000000000000")); // 門市編號
1013    } catch (Exception e) {
1014//      e.printStackTrace();
1015//      webccrlog.error(webccr.getClass(), e);
1016      CcrUtil.setMessage(emisUtil.getStackTrace(e));
1017    }
1018  }
1019
1020  // 1 扣款物件
1021  private void WriteDeductRequest(ICERAPIReq requset) {
1022    requset.setT0100(T0100_EACH);
1023    requset.setT0300(T0300_PAY); // 特定actoin code
1024    requset.setT0400(iUuCardAmt + "00"); // AMT
1025    requset.setT1100(emisString.lPadB(ccr.getCurrentSale().getSn() + "", 4, '0')); // 交易流水號
1026    requset.setT1200(emisUtil.todayTimeS());
1027    requset.setT1300(emisUtil.todayDate());
1028    try {
1029      Hashtable SQL_PARAMS = UU2_PARAMS.getInstance(emisUtil.getServletContext()).getHash();
1030      requset.setT4200(emisUtil.parseString(SQL_PARAMS.get(ccr.getCcrID() + "T4200"),
1031          "000000000000000")); // 按機台讀取設定值
1032      requset.setT5503(emisUtil.parseString(SQL_PARAMS.get(ccr.getCcrID() + "T5503"),
1033          "000000000000000")); // 門市編號
1034    } catch (Exception e) {
1035//      e.printStackTrace();
1036//      webccrlog.error(webccr.getClass(), e);
1037      CcrUtil.setMessage(emisUtil.getStackTrace(e));
1038    }
1039    requset.setT5501("000001"); // 固定值(1天只有1批, 卡機只批一次)
1040    requset.setT5509("E"); // 固定填入'E'
1041  }
1042
1043  // 2 加值物件
1044  private void WriteAddValueRequest(ICERAPIReq requset) {
1045    requset.setT0100(T0100_EACH);
1046    requset.setT0300(T0300_ADD_VALUE); // 特定actoin code
1047    requset.setT0400(iUuCardAmt + "00"); // AMT
1048    requset.setT1100(emisString.lPadB(ccr.getCurrentSale().getSn() + "", 4, '0')); // 交易流水號
1049    requset.setT1200(emisUtil.todayTimeS());
1050    requset.setT1300(emisUtil.todayDate());
1051    try {
1052      Hashtable SQL_PARAMS = UU2_PARAMS.getInstance(emisUtil.getServletContext()).getHash();
1053      requset.setT4200(emisUtil.parseString(SQL_PARAMS.get(ccr.getCcrID() + "T4200"),
1054          "000000000000000")); // 按機台讀取設定值
1055      requset.setT5503(emisUtil.parseString(SQL_PARAMS.get(ccr.getCcrID() + "T5503"),
1056          "000000000000000")); // 門市編號
1057    } catch (Exception e) {
1058//      e.printStackTrace();
1059//      webccrlog.error(webccr.getClass(), e);
1060      CcrUtil.setMessage(emisUtil.getStackTrace(e));
1061    }
1062    requset.setT5501("000001"); // 固定值(1天只有1批, 卡機只批一次)
1063    requset.setT5509("E"); // 固定填入'E'
1064  }
1065
1066  // 3 取消付款/重新付款 物件
1067  private void WriteCancelDeductRequest(ICERAPIReq requset) {
1068    requset.setT0100(T0100_EACH);
1069    requset.setT0300(T0300_PAY_VOID); // 特定actoin code
1070    requset.setT0400( ((int) Math.abs(oPayment.getAmount())) + "00" ); // AMT
1071    requset.setT1100(emisString.lPadB(ccr.getCurrentSale().getSn() + "", 4, '0')); // 交易流水號
1072    requset.setT1200(emisUtil.todayTimeS());
1073    requset.setT1300(emisUtil.todayDate());
1074    try {
1075      Hashtable SQL_PARAMS = UU2_PARAMS.getInstance(emisUtil.getServletContext()).getHash();
1076      requset.setT4200(emisUtil.parseString(SQL_PARAMS.get(ccr.getCcrID() + "T4200"),
1077          "000000000000000")); // 按機台讀取設定值
1078      requset.setT5503(emisUtil.parseString(SQL_PARAMS.get(ccr.getCcrID() + "T5503"),
1079          "000000000000000")); // 門市編號
1080    } catch (Exception e) {
1081//      e.printStackTrace();
1082//      webccrlog.error(webccr.getClass(), e);
1083      CcrUtil.setMessage(emisUtil.getStackTrace(e));
1084    }
1085    requset.setT5501("000001"); // 固定值(1天只有1批, 卡機只批一次)
1086    requset.setT5509("E"); // 固定填入'E'
1087  }
1088
1089  // 4 查詢餘額物件
1090  private void WriteQueryRequest(ICERAPIReq requset) {
1091    requset.setT0100(T0100_EACH);
1092    requset.setT0300(T0300_QUERY); // 特定actoin code
1093    requset.setT0400("000"); // {查詢填入000}
1094    requset.setT1100(emisString.lPadB("", 4, '0')); // 交易流水號
1095    requset.setT1200(emisUtil.todayTimeS());
1096    requset.setT1300(emisUtil.todayDate());
1097    try {
1098      Hashtable SQL_PARAMS = UU2_PARAMS.getInstance(emisUtil.getServletContext()).getHash();
1099      requset.setT4200(emisUtil.parseString(SQL_PARAMS.get(ccr.getCcrID() + "T4200"),
1100          "000000000000000")); // 按機台讀取設定值
1101      requset.setT5503(emisUtil.parseString(SQL_PARAMS.get(ccr.getCcrID() + "T5503"),
1102          "000000000000000")); // 門市編號
1103    } catch (Exception e) {
1104//      e.printStackTrace();
1105//      webccrlog.error(webccr.getClass(), e);
1106      CcrUtil.setMessage(emisUtil.getStackTrace(e));
1107    }
1108  }
1109
1110  // Dongle重傳物件
1111  private void WriteQueryRecordRequest(ICERAPIReq requset) {
1112    requset.setT0100(T0100_EACH);
1113    requset.setT0300(T0300_DONGLE); // 特定actoin code
1114    requset.setT1100(emisString.lPadB("", 4, '0')); // 交易流水號
1115    requset.setT1200(emisUtil.todayTimeS());
1116    requset.setT1300(emisUtil.todayDate());
1117    try {
1118      Hashtable SQL_PARAMS = UU2_PARAMS.getInstance(emisUtil.getServletContext()).getHash();
1119      requset.setT4200(emisUtil.parseString(SQL_PARAMS.get(ccr.getCcrID() + "T4200"),
1120          "000000000000000")); // 按機台讀取設定值
1121      requset.setT5503(emisUtil.parseString(SQL_PARAMS.get(ccr.getCcrID() + "T5503"),
1122          "000000000000000")); // 門市編號
1123    } catch (Exception e) {
1124//      e.printStackTrace();
1125//      webccrlog.error(webccr.getClass(), e);
1126      CcrUtil.setMessage(emisUtil.getStackTrace(e));
1127    }
1128    requset.setT5594(sNO); // 調閱序號
1129  }
1130
1131  // 6 扣款作廢物件
1132  private void WriteReturnRequest(ICERAPIReq requset) {
1133    requset.setT0100(T0100_EACH);
1134    requset.setT0300(T0300_PAY_VOID); // 特定actoin code
1135    requset.setT0400( ((int) Math.abs(oPayment.getAmount())) + "00" ); // AMT
1136    requset.setT1100(emisString.lPadB(ccr.getCurrentSale().getSL_NO(), 4, '0')); // 原交易流水號
1137    requset.setT1200(emisUtil.todayTimeS());
1138    requset.setT1300(emisUtil.todayDate());
1139    try {
1140      Hashtable SQL_PARAMS = UU2_PARAMS.getInstance(emisUtil.getServletContext()).getHash();
1141      requset.setT4200(emisUtil.parseString(SQL_PARAMS.get(ccr.getCcrID() + "T4200"),
1142          "000000000000000")); // 按機台讀取設定值
1143      requset.setT5503(emisUtil.parseString(SQL_PARAMS.get(ccr.getCcrID() + "T5503"),
1144          "000000000000000")); // 門市編號
1145    } catch (Exception e) {
1146//      e.printStackTrace();
1147//      webccrlog.error(webccr.getClass(), e);
1148      CcrUtil.setMessage(emisUtil.getStackTrace(e));
1149    }
1150    requset.setT5501("000001"); // 固定值(1天只有1批, 卡機只批一次)
1151    requset.setT5509("E"); // 固定填入'E'
1152  }
1153
1154  // 7 加值作廢物件
1155  private void WriteCancelAddValueRequest(ICERAPIReq requset) {
1156    requset.setT0100(T0100_EACH);
1157    requset.setT0300(T0300_ADD_CANCEL); // 特定actoin code
1158    requset.setT0400( iUuCardAmt + "00" ); // AMT
1159    requset.setT1100(emisString.lPadB(ccr.getCurrentSale().getSn() + "", 4, '0')); // 交易流水號
1160    requset.setT1200(emisUtil.todayTimeS());
1161    requset.setT1300(emisUtil.todayDate());
1162    try {
1163      Hashtable SQL_PARAMS = UU2_PARAMS.getInstance(emisUtil.getServletContext()).getHash();
1164      requset.setT4200(emisUtil.parseString(SQL_PARAMS.get(ccr.getCcrID() + "T4200"),
1165          "000000000000000")); // 按機台讀取設定值
1166      requset.setT5503(emisUtil.parseString(SQL_PARAMS.get(ccr.getCcrID() + "T5503"),
1167          "000000000000000")); // 門市編號
1168    } catch (Exception e) {
1169//      e.printStackTrace();
1170//      webccrlog.error(webccr.getClass(), e);
1171      CcrUtil.setMessage(emisUtil.getStackTrace(e));
1172    }
1173    requset.setT5501("000001"); // 固定值(1天只有1批, 卡機只批一次)
1174    requset.setT5509("E"); // 固定填入'E'
1175  }
1176
1177  // 0 SignOn檔
1178  private String CreateXML(ICERAPIReq requset) {
1179    StringBuffer sb = new StringBuffer();
1180    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>").append(sNewLine);
1181    sb.append("<TRANS>").append(sNewLine);
1182    //
1183    CreateNode(sb, "T0100", requset.T0100);
1184    CreateNode(sb, "T0300", requset.T0300);
1185    CreateNode(sb, "T1100", requset.T1100);
1186    CreateNode(sb, "T1200", requset.T1200);
1187    CreateNode(sb, "T1300", requset.T1300);
1188    CreateNode(sb, "T4200", requset.T4200);
1189    CreateNode(sb, "T5503", requset.T5503);
1190    //
1191    sb.append("</TRANS>");
1192    return sb.toString();
1193  }
1194
1195  // 1 扣款檔 
1196  private String CreateXML1(ICERAPIReq requset) {
1197    StringBuffer sb = new StringBuffer();
1198    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>").append(sNewLine);
1199    sb.append("<TRANS>").append(sNewLine);
1200    //
1201    CreateNode(sb, "T0100", requset.T0100);
1202    CreateNode(sb, "T0300", requset.T0300);
1203    CreateNode(sb, "T0400", requset.T0400);
1204    CreateNode(sb, "T1100", requset.T1100);
1205    CreateNode(sb, "T1200", requset.T1200);
1206    CreateNode(sb, "T1300", requset.T1300);
1207    CreateNode(sb, "T4200", requset.T4200);
1208    CreateNode(sb, "T5501", requset.T5501);
1209    CreateNode(sb, "T5503", requset.T5503);
1210    CreateNode(sb, "T5509", requset.T5509);
1211    //
1212    sb.append("</TRANS>");
1213    return sb.toString();
1214  }
1215
1216  // 2 加值檔 
1217  private String CreateXML2(ICERAPIReq requset) {
1218    StringBuffer sb = new StringBuffer();
1219    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>").append(sNewLine);
1220    sb.append("<TRANS>").append(sNewLine);
1221    //
1222    CreateNode(sb, "T0100", requset.T0100);
1223    CreateNode(sb, "T0300", requset.T0300);
1224    CreateNode(sb, "T0400", requset.T0400);
1225    CreateNode(sb, "T1100", requset.T1100);
1226    CreateNode(sb, "T1200", requset.T1200);
1227    CreateNode(sb, "T1300", requset.T1300);
1228    CreateNode(sb, "T4200", requset.T4200);
1229    CreateNode(sb, "T5501", requset.T5501);
1230    CreateNode(sb, "T5503", requset.T5503);
1231    CreateNode(sb, "T5509", requset.T5509);
1232    //
1233    sb.append("</TRANS>");
1234    return sb.toString();
1235  }
1236
1237  // 3 取消付款檔 
1238  private String CreateXML3(ICERAPIReq requset) {
1239    StringBuffer sb = new StringBuffer();
1240    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>").append(sNewLine);
1241    sb.append("<TRANS>").append(sNewLine);
1242    //
1243    CreateNode(sb, "T0100", requset.T0100);
1244    CreateNode(sb, "T0300", requset.T0300);
1245    CreateNode(sb, "T0400", requset.T0400);
1246    CreateNode(sb, "T1100", requset.T1100);
1247    CreateNode(sb, "T1200", requset.T1200);
1248    CreateNode(sb, "T1300", requset.T1300);
1249    CreateNode(sb, "T4200", requset.T4200);
1250    CreateNode(sb, "T5501", requset.T5501);
1251    CreateNode(sb, "T5503", requset.T5503);
1252    CreateNode(sb, "T5509", requset.T5509);
1253    //
1254    sb.append("</TRANS>");
1255    return sb.toString();
1256  }
1257
1258  // 4票卡查詢檔
1259  private String CreateXML4(ICERAPIReq requset) {
1260    StringBuffer sb = new StringBuffer();
1261    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>").append(sNewLine);
1262    sb.append("<TRANS>").append(sNewLine);
1263    //
1264    CreateNode(sb, "T0100", requset.T010

Large files files are truncated, but you can click here to view the full file