/// <summary>
        /// Response物件建立MAC並依據規格書轉轉換成byte[]
        /// </summary>
        /// <param name="msgUtility">Response Msg Parser</param>
        /// <param name="response">後端給的POCO</param>
        /// <param name="request">Origin Request byte array</param>
        /// <param name="doMAC">是否產生MAC:驗證失敗就不產了</param>
        /// <returns>response byte array</returns>
        protected virtual byte[] ParseResponse(IMsgUtility msgUtility, AL2POS_Domain response, byte[] request, bool doMAC = true)
        {
            log.Debug(m => m("7.轉換後台Response物件並建立MAC並轉成Response Byte[]"));
            byte[] rspResult = new byte[request.Length];
            Buffer.BlockCopy(request, 0, rspResult, 0, request.Length);//

            // modify request to response
            msgUtility.SetStr("02", rspResult, "Communicate");
            //return code
            msgUtility.SetStr(response.AL2POS_RC, rspResult, "ReturnCode");
            //承認編號
            msgUtility.SetStr(response.AL2POS_SN, rspResult, "CenterSeqNo");
            //Answer
            msgUtility.SetBytes(this.cardFormatMemberId, rspResult, "CardFormatMemberId");
            msgUtility.SetStr(this.cardNo, rspResult, "CardNo");
            msgUtility.SetStr(this.cardExpireDate1, rspResult, "CardExpireDate1");
            msgUtility.SetStr(this.cardExpireDate2, rspResult, "CardExpireDate2");
            //交易時間
            msgUtility.SetStr(this.transDateTime, rspResult, "TransDateTime");
            //是否產生mac
            if (doMAC)
            {
                // fetch sha1 data
                this.SetMAC(msgUtility, rspResult, this.readerId, this.transDateTime);//CheckMacContainer.Mac2Manager.GetAuthMac(response.READER_ID, response.AL_TRANSTIME, sha1Result);
            }
            else
            {
                //若Mac驗證失敗,則使用來源mac簡易回傳
                msgUtility.SetStr(this.mac, rspResult, "Mac");
            }
            // padding data
            this.SetPadding(msgUtility, rspResult);
            return(rspResult);
        }
        /// <summary>
        /// 設定Response的Padding部分
        /// </summary>
        /// <param name="resMsgUility">Response Msg Parser</param>
        /// <param name="response">要寫入的response byte array</param>
        protected virtual void SetPadding(IMsgUtility resMsgUility, byte[] response)
        {
            // padding data
            byte[] spacePadding = CheckMacContainer.ByteWorker.Fill(resMsgUility.GetTag("DataPadding").Length, 0x20);
            resMsgUility.SetBytes(spacePadding, response, "DataPadding");
            int length = response.Length;

            log.Debug(m => m("9.Response Padding End (array length:{0})", length));
        }
Beispiel #3
0
        /// <summary>
        /// Response物件轉換成byte[]
        /// </summary>
        /// <param name="msgUtility">Msg Parser Object</param>
        /// <param name="response">後端給的POCO</param>
        /// <param name="request">Origin Request byte array</param>
        /// <returns>response byte array</returns>
        protected virtual byte[] ParseResponse(IMsgUtility msgUtility, ALTxlog_Domain response, byte[] request)
        {
            log.Debug(m => m("5.轉換後台自動加值TxLog Response物件 => Byte[]"));
            byte[] rspResult = new byte[request.Length];
            Buffer.BlockCopy(request, 0, rspResult, 0, request.Length);//
            // modify request to response
            msgUtility.SetStr("02", rspResult, "Communicate");
            msgUtility.SetStr(response.TXLOG_RC, rspResult, "ReturnCode");
            //取得資料部分的大小並設定
            string sizeStr = CheckMacContainer.StrHelper.LeftPad(msgUtility.GetSize("DataVersion", "EndOfData"), msgUtility.GetTag("DecryptSize").Length, '0');

            msgUtility.SetStr(sizeStr, rspResult, "DecryptSize");
            msgUtility.SetStr(sizeStr, rspResult, "EncryptSize");
            //寫入空白
            msgUtility.SetBytes(CheckMacContainer.ByteWorker.Fill(msgUtility.GetTag("DataPadding").Length, 0x20), rspResult, "DataPadding");
            //依據定義改變Response大小(因Request資料部分長度與Response資料部分長度不一樣)
            rspResult = CheckMacContainer.ByteWorker.SubArray(rspResult, 0, msgUtility.GetSize("HeaderVersion", "EndOfData"));
            log.Debug(m => m("6.轉換後台自動加值TxLog Response物件完畢"));
            return(rspResult);
        }
 /// <summary>
 /// 設定Response的Padding部分
 /// </summary>
 /// <param name="resMsgUility">Response Msg Parser</param>
 /// <param name="response">要寫入的response byte array</param>
 protected virtual void SetPadding(IMsgUtility resMsgUility, byte[] response)
 {
     // padding data
     byte[] spacePadding = CheckMacContainer.ByteWorker.Fill(resMsgUility.GetTag("DataPadding").Length, 0x20);
     resMsgUility.SetBytes(spacePadding, response, "DataPadding");
     //log.Debug(m => m("9.Response Byte[]轉換完成, length:{0}", response.Length));
     int length = response.Length;
     log.Debug(m => m("9.Response Padding End (array length:{0})", length));
 }
        /// <summary>
        /// Response物件建立MAC並依據規格書轉轉換成byte[]
        /// </summary>
        /// <param name="msgUtility">Response Msg Parser</param>
        /// <param name="response">後端給的POCO</param>
        /// <param name="request">Origin Request byte array</param>
        /// <param name="doMAC">是否產生MAC:驗證失敗就不產了</param>
        /// <returns>response byte array</returns>
        protected virtual byte[] ParseResponse(IMsgUtility msgUtility, AL2POS_Domain response, byte[] request, bool doMAC = true)
        {
            log.Debug(m => m("7.轉換後台Response物件並建立MAC並轉成Response Byte[]"));
            byte[] rspResult = new byte[request.Length];
            Buffer.BlockCopy(request, 0, rspResult, 0, request.Length);//

            // modify request to response
            msgUtility.SetStr("02", rspResult, "Communicate");
            //return code
            msgUtility.SetStr(response.AL2POS_RC, rspResult, "ReturnCode");
            //承認編號
            msgUtility.SetStr(response.AL2POS_SN, rspResult, "CenterSeqNo");
            //Answer
            msgUtility.SetBytes(this.cardFormatMemberId, rspResult, "CardFormatMemberId");
            msgUtility.SetStr(this.cardNo, rspResult, "CardNo");
            msgUtility.SetStr(this.cardExpireDate1, rspResult, "CardExpireDate1");
            msgUtility.SetStr(this.cardExpireDate2, rspResult, "CardExpireDate2");
            //交易時間
            msgUtility.SetStr(this.transDateTime, rspResult, "TransDateTime");
            //是否產生mac
            if (doMAC)
            {
                // fetch sha1 data
                this.SetMAC(msgUtility, rspResult, this.readerId, this.transDateTime);//CheckMacContainer.Mac2Manager.GetAuthMac(response.READER_ID, response.AL_TRANSTIME, sha1Result);
            }
            else
            {
                //若Mac驗證失敗,則使用來源mac簡易回傳
                msgUtility.SetStr(this.mac, rspResult, "Mac");
            }
            // padding data
            this.SetPadding(msgUtility, rspResult);
            return rspResult;
        }
 /// <summary>
 /// Response物件轉換成byte[]
 /// </summary>
 /// <param name="msgUtility">Response Msg Parser</param>
 /// <param name="response">後端給的POCO</param>
 /// <param name="request">Origin Request byte array</param>
 /// <returns>response byte array</returns>
 protected virtual byte[] ParseResponse(IMsgUtility msgUtility, Txlog_Domain response, byte[] request)
 {
     log.Debug(m => m("5.轉換後台購貨取消TxLog Response物件 => Byte[]"));
     byte[] rspResult = new byte[request.Length];
     Buffer.BlockCopy(request, 0, rspResult, 0, request.Length);//
     // modify request to response
     msgUtility.SetStr("02", rspResult, "Communicate");
     msgUtility.SetStr(response.TXLOG_RC, rspResult, "ReturnCode");
     //取得資料部分的大小並設定
     string sizeStr = CheckMacContainer.StrHelper.LeftPad(msgUtility.GetSize("DataVersion", "EndOfData"), msgUtility.GetTag("DecryptSize").Length, '0');
     msgUtility.SetStr(sizeStr, rspResult, "DecryptSize");
     msgUtility.SetStr(sizeStr, rspResult, "EncryptSize");
     //寫入空白
     msgUtility.SetBytes(CheckMacContainer.ByteWorker.Fill(msgUtility.GetTag("DataPadding").Length, 0x20), rspResult, "DataPadding");
     //依據定義改變Response大小(因Request資料部分長度與Response資料部分長度不一樣)
     rspResult = CheckMacContainer.ByteWorker.SubArray(rspResult, 0, msgUtility.GetSize("HeaderVersion", "EndOfData"));
     log.Debug(m => m("6.轉換後台購貨取消TxLog Response物件完畢"));
     return rspResult;
 }