Beispiel #1
0
 /// <summary>
 /// 加载响应码
 /// </summary>
 /// <param name="isRefresh">true:重新加载</param>
 /// <returns></returns>
 public static AnswerCode LoadAnswerCode(bool isRefresh = false)
 {
     if (answerCode == null || isRefresh)
     {
         answerCode = ConfigManage.GetAnswerList();
     }
     return(answerCode);
 }
Beispiel #2
0
 /// <summary>
 /// 加载配置文件数据
 /// </summary>
 /// <param name="isRefresh">true:重新加载</param>
 /// <returns></returns>
 public static PinganPayConfig LoadPinganConfig(bool isRefresh = false)
 {
     if (PinganPayConfig == null || isRefresh)
     {
         PinganPayConfig = ConfigManage.GetPinganPayConfig();
     }
     return(PinganPayConfig);
 }
Beispiel #3
0
        /// <summary>
        /// 银行和企业的  下行请求 发送请求
        /// </summary>
        /// <param name="message">发送的内容</param>
        /// <param name="setting">发送前的设置</param>
        /// <returns></returns>
        public string SendDownMessage(string message, Action <Socket> setting = null)
        {
            String recvMessage = string.Empty;

            try
            {
                var pinganPayConfig = ConfigManage.GetPinganPayConfig();
                using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
                {
                    if (setting == null)
                    {
                        //设置
                        socket.SendTimeout       = pinganPayConfig.DownSetting.SendTimeout * 1000;
                        socket.ReceiveTimeout    = pinganPayConfig.DownSetting.ReceiveTimeout * 1000;
                        socket.NoDelay           = pinganPayConfig.DownSetting.NoDelay;
                        socket.SendBufferSize    = pinganPayConfig.DownSetting.SendBufferSize;
                        socket.ReceiveBufferSize = pinganPayConfig.DownSetting.SendBufferSize;
                    }
                    else
                    {
                        setting(socket);
                    }
                    //连接
                    socket.Connect(pinganPayConfig.DownSetting.ListenIP, pinganPayConfig.DownSetting.ListenPort);
                    if (socket.Connected)
                    {
                        //发送数据
                        byte[] sendBytes = Utils.ToByte(message);
                        int    sendLen   = socket.Send(sendBytes);

                        //测试
                        //Thread.CurrentThread.Join();
                        //接收数据
                        recvMessage = RecvMessage(socket);
                    }
                    socket.Close();
                }
            }
            catch (Exception ex)
            {
                LogManager.GetCurrentClassLogger().Error("[请求数据]:" + message, ex);
                //throw ex;
            }
            return(recvMessage);
        }
Beispiel #4
0
        /// <summary>
        /// 上行请求 发送请求
        /// </summary>
        /// <param name="message">发送的内容</param>
        /// <param name="setting">发送前的设置</param>
        /// <returns></returns>
        public string SendUpMessage(string message, Action <TcpClient> setting = null)
        {
            String recvMessage = string.Empty;

            try
            {
                var pinganPayConfig = ConfigManage.GetPinganPayConfig();
                using (TcpClient tcpClient = new TcpClient())
                {
                    if (setting == null)
                    {
                        //设置
                        tcpClient.SendTimeout    = pinganPayConfig.UpSetting.SendTimeout * 1000;
                        tcpClient.ReceiveTimeout = pinganPayConfig.UpSetting.ReceiveTimeout * 1000;
                        tcpClient.NoDelay        = pinganPayConfig.UpSetting.NoDelay;
                        tcpClient.SendBufferSize = pinganPayConfig.UpSetting.SendBufferSize;
                    }
                    else
                    {
                        setting(tcpClient);
                    }
                    //连接
                    tcpClient.Connect(pinganPayConfig.UpSetting.IP, pinganPayConfig.UpSetting.Port);
                    if (tcpClient.Connected)
                    {
                        NetworkStream ns        = tcpClient.GetStream();
                        byte[]        sendBytes = Utils.ToByte(message);
                        ns.Write(sendBytes, 0, sendBytes.Length);
                        ns.Flush();
                        //获取内容
                        recvMessage = RecvMessage(tcpClient.Client);
                        ns.Close();
                        tcpClient.Close();

                        #region 无边界性的接收
                        //MemoryStream ms = new MemoryStream();
                        //byte[] buf = new byte[pinganPayConfig.UpSetting.SendBufferSize];
                        //int len = -1;
                        ////阻塞读取
                        //while ((len = ns.Read(buf, 0, buf.Length)) != -1)
                        //{
                        //    //断开连接或者超时
                        //    if (len == 0) break;
                        //    //写入到内存中
                        //    ms.Write(buf, 0, len);
                        //}
                        //ns.Close();

                        //byte[] resbyte = ms.ToArray();
                        //recvMessage = Utils.ToGBK(resbyte, 0, resbyte.Length);
                        //ms.Close();
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                LogManager.GetCurrentClassLogger().Error("[请求数据]:" + message + " 返回:" + recvMessage, ex);
                //throw ex;
            }
            return(recvMessage);
        }
Beispiel #5
0
 /// <summary>
 /// 保存配置
 /// </summary>
 /// <param name="pinganPayConfig"></param>
 public static void SavePinganConfig(PinganPayConfig pinganPayConfig)
 {
     PinganPayConfig = pinganPayConfig;
     ConfigManage.SetPinganPayConfig(pinganPayConfig);
 }