Esempio n. 1
0
        /// <summary>
        /// 处理消息
        /// </summary>
        /// <param name="recv">接收到的数据</param>
        /// <param name="ns">网络流对象</param>
        private void HandleMessage(string recv, NetworkStream ns)
        {
            //给银行的应答数据
            string back = string.Empty, TargetSystem = "", ExMessage = string.Empty;
            //解析的值
            ExHashTable retKeyDict = new ExHashTable();

            try
            {
                if (!string.IsNullOrEmpty(recv))
                {
                    //解析接收到的银行的数据
                    BankInterface bankReq = new BankInterface();
                    TargetSystem = Utils.GetTargetSystem(recv);
                    if (TargetSystem == "03")
                    {
                        //老版本 交易资金03
                        retKeyDict = bankReq.ParsingTranMessageString(recv);
                        back       = bankReq.GetTranMessageRes(retKeyDict);
                    }
                    else if (TargetSystem == "01")
                    {
                        //新版本 银企直连01
                        retKeyDict = bankReq.ParsingBankEnterpriseMessageString(recv);
                        //构建返回数据给银行
                        back = string.Join("", bankReq.GetBankEnterpriseMessageRes(retKeyDict).ToArray());
                    }
                }
                byte[] BackBytes = Utils.ToByte(back);
                ns.Write(BackBytes, 0, BackBytes.Length);
                ns.Flush();
                ns.Close();
            }
            catch (Exception ex)
            {
                ExMessage = ex.Message;
                throw ex;
            }
            finally
            {
                StringBuilder sbLog = new StringBuilder();
                sbLog.AppendFormat("时间:{0}\r\n", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                sbLog.AppendFormat("接收数据:{0}\r\n", recv);
                sbLog.AppendFormat("响应数据:{0}\r\n", back);
                if (!string.IsNullOrEmpty(ExMessage))
                {
                    sbLog.AppendFormat("异常信息:{0}\r\n", ExMessage);
                }
                sbLog.AppendFormat("解析结果:\r\n{0}\r\n\r\n\r\n", retKeyDict.ToString());
                if (GlobalData.LoadPinganConfig().OpenLog)
                {
                    FileHelper.SaveFile(string.Format("Log\\Recv\\{0}{1}\\bankRecv_{2}.txt", (!string.IsNullOrEmpty(TargetSystem) ? (TargetSystem + "\\") : ""), System.DateTime.Now.ToString("yyyyMMdd"), System.DateTime.Now.ToString("HH")), sbLog.ToString());
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 根据请求参数 返回结果
        /// </summary>
        /// <param name="parmaKeyDict"></param>
        /// <returns></returns>
        private DataResult GetResult(ExHashTable parmaKeyDict)
        {
            //记录日志
            StringBuilder sbLog      = new StringBuilder();
            ExHashTable   retKeyDict = new ExHashTable();

            try
            {
                //检测
                Utils.PayCheckData((string)parmaKeyDict.Get("ThirdLogNo"), (string)parmaKeyDict.Get("CounterId"));
                //获取请求报文
                BankInterface msg = new BankInterface();
                //调用函数生成请求的而完整报文
                List <string> messageList     = msg.GetBankEnterpriseMessageReq(parmaKeyDict, this.IsSpecialLine);
                var           pinganPayConfig = GlobalData.LoadPinganConfig();
                string        reqMessage      = string.Join("", (pinganPayConfig.BankEnterpriseNetHead.NetMessageHead.TeleProtocol == "01" ? messageList.ToArray() : messageList.GetRange(1, 2).ToArray()));
                sbLog.AppendFormat("时间:{0}\r\n", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                sbLog.AppendFormat("请求:{0}\r\n", reqMessage);
                //发送请求报文  //获取银行返回报文
                string recvMessage = msg.SendMessage(reqMessage, pinganPayConfig.BankEnterpriseNetHead.NetMessageHead.TeleProtocol);
                sbLog.AppendFormat("响应:{0}\r\n", recvMessage);
                //解析返回结果
                retKeyDict = msg.ParsingBankEnterpriseMessageString(recvMessage);
                sbLog.AppendFormat("解析结果:\r\n{0}\r\n", retKeyDict.ToString());
            }
            catch (Exception ex)
            {
                sbLog.AppendFormat("异常信息:{0}\r\n", ex.Message);
                throw ex;
            }
            finally
            {
                //写入日志
                if (GlobalData.LoadPinganConfig().OpenLog)
                {
                    FileHelper.SaveFile(string.Format("Log\\Req\\ReqData_{0}.txt", System.DateTime.Now.ToString("yyyyMMdd")), sbLog.ToString() + "\r\n\r\n");
                }
            }
            //转换
            return(Utils.ToDataResult(retKeyDict, GlobalData.DirectErpBankVersion));
        }