Example #1
0
        /// <summary>
        /// 解析接收银行的报文
        /// </summary>
        /// <param name="TranMessage">带解析的结果字符串</param>
        /// <returns></returns>
        public ExHashTable ParsingTranMessageString(string TranMessage)
        {
            ExHashTable retKeyDict = Utils.InitRetDict(TranMessage);

            if (string.IsNullOrEmpty(TranMessage))
            {
                return(retKeyDict);
            }
            byte[] byteRetMessage = Utils.ToByte(TranMessage);
            if (byteRetMessage.Length < 222)
            {
                return(retKeyDict);
            }

            byte[] bNetHead  = new byte[222]; //通讯头
            byte[] bYeWuHead = new byte[122]; //业务头


            byte[] bTranFunc      = new byte[4];   //业务交易码
            byte[] bTargetSystem  = new byte[2];   //接入系统
            byte[] bRspCode       = new byte[6];   //响应码
            byte[] bRspMsg        = new byte[100]; //响应描述
            byte[] bRspMsgLength  = new byte[10];  //数据包的长度
            byte[] bRspQydm       = new byte[20];  //企业标识代码
            byte[] bRspDatetime   = new byte[14];  //交易日期时间
            byte[] bRspThirdLogNo = new byte[20];  //流水号
            byte[] bCounterId     = new byte[5];   //操作员

            Array.Copy(byteRetMessage, 0, bNetHead, 0, bNetHead.Length);
            Array.Copy(byteRetMessage, 4, bTargetSystem, 0, bTargetSystem.Length);
            Array.Copy(byteRetMessage, 10, bRspQydm, 0, bRspQydm.Length);
            Array.Copy(byteRetMessage, 30, bRspMsgLength, 0, bRspMsgLength.Length);
            Array.Copy(byteRetMessage, 46, bCounterId, 0, bCounterId.Length);
            Array.Copy(byteRetMessage, 53, bRspDatetime, 0, bRspDatetime.Length);
            Array.Copy(byteRetMessage, 67, bRspThirdLogNo, 0, bRspThirdLogNo.Length);
            Array.Copy(byteRetMessage, 87, bRspCode, 0, bRspCode.Length);
            Array.Copy(byteRetMessage, 93, bRspMsg, 0, bRspMsg.Length);

            string strHead       = Utils.ToGBK(bNetHead, 0, bNetHead.Length);
            string RspCode       = Utils.ToGBK(bRspCode, 0, bRspCode.Length);
            string RspMsg        = Utils.ToGBK(bRspMsg, 0, bRspMsg.Length);
            string Qydm          = Utils.ToGBK(bRspQydm, 0, bRspQydm.Length).Trim();
            string TargetSystem  = Utils.ToGBK(bTargetSystem, 0, bTargetSystem.Length);
            string RspDatetime   = Utils.ToGBK(bRspDatetime, 0, bRspDatetime.Length);
            string RspThirdLogNo = Utils.ToGBK(bRspThirdLogNo, 0, bRspThirdLogNo.Length).Trim();
            string RspMsgLength  = int.Parse(Utils.ToGBK(bRspMsgLength, 0, bRspMsgLength.Length)).ToString();
            string CounterId     = Utils.ToGBK(bCounterId, 0, bCounterId.Length);
            string TranFunc      = string.Empty;
            string BodyMsg       = string.Empty;

            if (byteRetMessage.Length >= 226)
            {
                Array.Copy(byteRetMessage, 222, bTranFunc, 0, bTranFunc.Length);
                TranFunc = Utils.ToGBK(bTranFunc, 0, bTranFunc.Length);
            }
            if (byteRetMessage.Length - bNetHead.Length - bYeWuHead.Length > 0)
            {
                byte[] bNetBody = new byte[byteRetMessage.Length - bNetHead.Length - bYeWuHead.Length];//响应内容
                Array.Copy(byteRetMessage, bNetHead.Length + bYeWuHead.Length, bNetBody, 0, bNetBody.Length);
                BodyMsg = Utils.ToGBK(bNetBody, 0, bNetBody.Length);
            }

            retKeyDict.Set("TranFunc", TranFunc);         //交易码
            retKeyDict.Set("TargetSystem", TargetSystem); //接入系统
            retKeyDict.Set("BodyMsg", BodyMsg);           //响应内容
            retKeyDict.Set("RspCode", RspCode);           //响应码
            retKeyDict.Set("RspMsg", RspMsg);             //响应描述
            retKeyDict.Set("TrandateTime", RspDatetime);  //交易日期
            retKeyDict.Set("RspMsgLength", RspMsgLength); //响应数据长度
            retKeyDict.Set("Qydm", Qydm);                 //企业标识代码
            retKeyDict.Set("CounterId", CounterId);       //操作员
            retKeyDict.Set("ThirdLogNo", RspThirdLogNo);  //请求流水号
            retKeyDict.Set("Data", TranMessage);          //原始数据
            return(retKeyDict);
        }
Example #2
0
        /// <summary>
        /// 解析结果
        /// </summary>
        /// <returns></returns>
        public ExHashTable ParsingBankEnterpriseMessageString(string bankEnterpriseMessage)
        {
            ExHashTable retKeyDict = Utils.InitRetDict(bankEnterpriseMessage);

            if (string.IsNullOrEmpty(bankEnterpriseMessage))
            {
                return(retKeyDict);
            }
            byte[] messageByte = Utils.ToByte(bankEnterpriseMessage);
            if (messageByte.Length < 222)
            {
                return(retKeyDict);
            }

            byte[] bNetHead       = new byte[222];
            byte[] bNetBody       = new byte[messageByte.Length - bNetHead.Length];
            byte[] bRspMsg        = new byte[100]; //描述
            byte[] bRspMsgLength  = new byte[10];  //数据包的长度
            byte[] bRspQydm       = new byte[20];  //企业标识代码
            byte[] bRspDatetime   = new byte[14];  //日期时间
            byte[] bRspThirdLogNo = new byte[20];  //流水号
            byte[] bCounterId     = new byte[5];   //操作员
            byte[] bTargetSystem  = new byte[2];   //接入系统
            Array.Copy(messageByte, 0, bNetHead, 0, bNetHead.Length);
            Array.Copy(messageByte, 4, bTargetSystem, 0, bTargetSystem.Length);
            Array.Copy(messageByte, 11, bRspQydm, 0, bRspQydm.Length);
            Array.Copy(messageByte, 30, bRspMsgLength, 0, bRspMsgLength.Length);
            Array.Copy(messageByte, 46, bCounterId, 0, bCounterId.Length);
            Array.Copy(messageByte, 53, bRspDatetime, 0, bRspDatetime.Length);
            Array.Copy(messageByte, 67, bRspThirdLogNo, 0, bRspThirdLogNo.Length);
            Array.Copy(messageByte, 93, bRspMsg, 0, bRspMsg.Length);
            string strMessageBody = string.Empty;

            if (bNetBody.Length > 0)
            {
                Array.Copy(messageByte, bNetHead.Length, bNetBody, 0, bNetBody.Length);
                strMessageBody = Utils.ToGBK(bNetBody, 0, bNetBody.Length);
            }
            string strHead  = Utils.ToGBK(bNetHead, 0, bNetHead.Length);
            string TranFunc = strHead.Length > 40 ? strHead.Substring(40, 6) : string.Empty;

            TranFunc = TranFunc.Trim();
            string bRspCode      = strHead.Length > 87 ? strHead.Substring(87, 6) : string.Empty;
            string RspMsg        = Utils.ToGBK(bRspMsg, 0, bRspMsg.Length);
            int    _RspMsgLength = 0;
            string RspMsgLength  = Utils.ToGBK(bRspMsgLength, 0, bRspMsgLength.Length);

            int.TryParse(RspMsgLength, out _RspMsgLength);
            string Qydm          = Utils.ToGBK(bRspQydm, 0, bRspQydm.Length);
            string TargetSystem  = Utils.ToGBK(bTargetSystem, 0, bTargetSystem.Length);
            string CounterId     = Utils.ToGBK(bCounterId, 0, bCounterId.Length);
            string RspDatetime   = Utils.ToGBK(bRspDatetime, 0, bRspDatetime.Length);
            string RspThirdLogNo = Utils.ToGBK(bRspThirdLogNo, 0, bRspThirdLogNo.Length).Trim();

            retKeyDict.Set("TranFunc", TranFunc);          //业务交易码
            retKeyDict.Set("TargetSystem", TargetSystem);  //接入系统
            retKeyDict.Set("RspCode", bRspCode);           //响应码
            retKeyDict.Set("RspMsg", RspMsg);              //响应描述
            retKeyDict.Set("TrandateTime", RspDatetime);   //交易日期时间
            retKeyDict.Set("BodyMsg", strMessageBody);     //响应内容
            retKeyDict.Set("RspMsgLength", RspMsgLength);  //响应数据长度
            retKeyDict.Set("Qydm", Qydm);                  //企业标识代码
            retKeyDict.Set("CounterId", CounterId);        //操作员
            retKeyDict.Set("ThirdLogNo", RspThirdLogNo);   //请求流水号
            retKeyDict.Set("Data", bankEnterpriseMessage); //原始数据
            return(retKeyDict);
        }