예제 #1
0
파일: JNKY.cs 프로젝트: lmj823/dianpiao
        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="zhdh"></param>
        /// <param name="pinBlock"></param>
        /// <param name="nodeNo"></param>
        /// <returns></returns>
        public static string Decrypt(string zhdh, string pinBlock, string nodeNo)
        {
            string s = "error";

            try
            {
                XmlHelper xher = setCommPara("E141", nodeNo);
                xher.UpdateContent(@"/union/body/pinBlock", pinBlock);
                xher.UpdateContent(@"/union/body/accNo", zhdh);
                string send = xher.GetXmlDoc().OuterXml;
                string recv = SendData(send, nodeNo);

                if (recv.IndexOf("error") != 0)
                {
                    XmlHelper xher1 = new XmlHelper(recv);
                    if (xher1.ReadByNode(@"/union/head/responseCode") == "000000")
                    {
                        s = xher1.ReadByNode(@"/union/body/plainPin");
                    }
                }
            }
            catch (Exception e)
            {
                LogWrite.WriteLog("账号:[" + zhdh + "],原因:[" + e.Message + "]", "调用加密机【解密】失败", nodeNo);
            }
            return(s);
        }
예제 #2
0
파일: ET.cs 프로젝트: lmj823/dianpiao
        private string retCatch(Exception ex)
        {
            LogWrite.WriteLog(ex.Message, "交易处理失败(" + trandType + "),原因:", nodeNo);

            retSysError(errMsg);
            return(DocToStr(xher.GetXmlDoc()));
        }
예제 #3
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            try
            {
                mydataset myds = new mydataset();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "IpFormat失败");
                this.Close();
            }
            ////////////////////////debug//////////////////////
            //string hex = "504f5354202f626273702f73657276696365732f62696c6c45646974536572766963652f62696c6c456469745365727669636520485454502f312e310d0a436f6e74656e742d547970653a20746578742f786d6c0d0a486f73743a203136332e312e392e39333a383238320d0a436f6e74656e742d4c656e6774683a20313639320d0a4578706563743a203130302d636f6e74696e75650d0a436f6e6e656374696f6e3a204b6565702d416c6976650d0a0d0a";
            //byte[] bytes = new byte[hex.Length / 2];
            //for (int i = 0; i < bytes.Length; i++)
            //{
            //    try
            //    {
            //        // 每两个字符是一个 byte。
            //        bytes[i] = byte.Parse(hex.Substring(i * 2, 2),
            //        System.Globalization.NumberStyles.HexNumber);
            //    }
            //    catch
            //    {

            //    }
            //}
            //System.Text.Encoding chs = System.Text.Encoding.GetEncoding("utf-8");
            //string bb = chs.GetString(bytes);



            ///////////////////////////////////////////////////



            startThreading();


            sdt  = DateTime.Now;
            run1 = true;


            timer1.Interval = int.Parse(ConfigApp.TimerTick) * 60 * 1000;
            timer1.Enabled  = true;


            lbVer.Text       = "版本: " + Common.AssemblyFileVersion();
            lbStartTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            Thread thShow = new Thread(new ThreadStart(doDispos));

            thShow.Start();

            LogWrite.WriteLog("", "程序开始运行...");
        }
예제 #4
0
 private void add()
 {
     try
     {
         if (this.listView1.InvokeRequired)
         {
             DelegateShowResult dsr = new DelegateShowResult(show);
             this.Invoke(dsr, new object[] { });
         }
         else
         {
             show();
         }
     }
     catch (Exception ee)
     {
         LogWrite.WriteLog(ee.Message, "界面显示出错");
     }
 }
예제 #5
0
        private void Acceptclient()
        {
            try
            {
                IPAddress   ip     = IPAddress.Any;
                int         myport = int.Parse(ConfigApp.MyPort);
                TcpListener tl     = new TcpListener(ip, myport);
                TcpClient   tc;

                while (true)
                {
                    tl.Start();
                    tc = tl.AcceptTcpClient();
                    string ip1 = tc.Client.RemoteEndPoint.ToString();
                    if (Common.isAllowIP(ip1))
                    {
                        Listen listen = new Listen(tc);
                        Thread thread = new Thread(new ThreadStart(listen.startAccept));
                        thread.Start();
                    }
                    else
                    {
                        LogWrite.WriteLog(ip1, "非法客户端:");
                        tc.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                LogWrite.WriteLog(ex.ToString(), "Socket错误");
                DialogResult dr = MessageBox.Show("创建socket连接失败。", "退出程序", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (dr == DialogResult.OK)
                {
                    Application.ExitThread();
                    Application.Exit();
                }
            }
        }
예제 #6
0
        private static ArrayList getAllowIPlist()
        {
            ArrayList al = new ArrayList();

            try
            {
                string file = System.Windows.Forms.Application.StartupPath + "\\hosts";
                System.IO.FileStream   fs = new System.IO.FileStream(file, System.IO.FileMode.Open);
                System.IO.StreamReader sr = new System.IO.StreamReader(fs, System.Text.Encoding.GetEncoding("GBK"));

                while (true)
                {
                    string line = sr.ReadLine();
                    if (line == null)
                    {
                        break;
                    }
                    else if (line.IndexOf(';') == 0)
                    {
                        continue;
                    }
                    else
                    {
                        al.Add(line.Trim());
                    }
                }

                sr.Close();
                fs.Close();
            }
            catch (Exception ex)
            {
                LogWrite.WriteLog(ex.Message, "加载hosts出错");
                al.Add("*.*.*.*");
            }
            return(al);
        }
예제 #7
0
파일: Listen.cs 프로젝트: lmj823/dianpiao
        public void startAccept()
        {
            try
            {
                NetworkStream ns    = tcpClient.GetStream();
                int           l1    = 6;
                byte[]        cRead = new byte[l1];

                int it1 = 0;
                while (it1 < l1)
                {
                    int ct1 = ns.Read(cRead, it1, l1 - it1);
                    if (ct1 <= 0)
                    {
                        break;
                    }
                    it1 += ct1;
                }


                string head = System.Text.Encoding.GetEncoding("GBK").GetString(cRead);
                int    len  = int.Parse(head);
                byte[] text = new byte[len];
                int    it   = 0;
                while (it < len)
                {
                    int ct = ns.Read(text, it, len - it);
                    if (ct <= 0)
                    {
                        break;
                    }
                    it += ct;
                }

                string body = Encoding.GetEncoding("GBK").GetString(text);
                sdata.Jysj = DateTime.Now.ToString("HH:mm:ss");
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(body);
                XmlNode tranCode  = doc.SelectSingleNode("//ebank//tranCode");
                XmlNode nodeNo    = doc.SelectSingleNode("//ebank//nodeNo");
                string  trandType = ""; //内部交易代码
                string  nodeno    = ""; //机构号
                string  sendEbank = ""; //返回报文
                if (tranCode != null && nodeNo != null)
                {
                    string index = ConfigApp.Lsh;
                    trandType = tranCode.InnerText;
                    nodeno    = nodeNo.InnerText.Replace("|", "");

                    LogWrite.WriteLog(head + body, "接收(" + trandType + ")" + "[" + index + "]", nodeno);



                    ET bm = new ET(doc, trandType, nodeno);
                    sendEbank = bm.Done();

                    //Eticket bm1 = new Eticket(doc, trandType, nodeno);
                    //sendEbank = bm1.Done();

                    if (ConfigApp.Show)//显示交易结果
                    {
                        sdata.Wd    = nodeno;
                        sdata.Wdm   = MultPara.getBankName(nodeno);
                        sdata.Jym   = trandType;
                        sdata.Jysj1 = DateTime.Now.ToString("HH:mm:ss");
                        try
                        {
                            XmlDocument xxd = new XmlDocument();
                            xxd.LoadXml(sendEbank.Substring(6));
                            sdata.Errcode = xxd.SelectSingleNode("//ebank//hostReturnCode").InnerText.Trim();
                            sdata.Errmsg  = xxd.SelectSingleNode("//ebank//hostErrorMessage").InnerText.Trim();
                        }
                        catch
                        {
                            sdata.Errcode = "";
                            sdata.Errmsg  = sendEbank;
                        }
                    }

                    byte[] sendData = Encoding.GetEncoding("GBK").GetBytes(sendEbank);
                    if (ns.CanWrite)
                    {
                        ns.Write(sendData, 0, sendData.Length);
                        LogWrite.WriteLog(sendEbank, "返回(" + trandType + ")" + "[" + index + "]", nodeno);
                    }
                    else
                    {
                        LogWrite.WriteLog("", "返回网银端时通讯异常(" + trandType + ")" + "[" + index + "]", nodeno);
                        sdata.Errcode = "9999";
                        sdata.Errmsg  = "通讯异常";
                    }
                }
                else
                {
                    LogWrite.WriteLog(body, "非法的请求报文:");
                    sdata.Errcode = "9999";
                    sdata.Errmsg  = "无效交易码";
                }
                ns.Close();
                if (ConfigApp.Show)
                {
                    try { Form1.FinalQueue.Enqueue(sdata); }
                    catch { }
                }
            }
            catch (Exception ex)
            {
                LogWrite.WriteLog(ex.ToString(), "处理失败:");
            }
            finally
            {
                tcpClient.Close();
            }
        }
예제 #8
0
파일: dataset.cs 프로젝트: lmj823/dianpiao
        public void DD()
        {
            int count = 0;

            try
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("id");
                dt.Columns.Add("net");
                dt.Columns.Add("cor");
                dataDic = new DataSet();
                dataDic.Tables.Add(dt);

                string line = null;
                string id   = "";
                string net  = "";
                string cor  = "";



                FileStream   fs = new FileStream(@"DD.txt", FileMode.Open);
                StreamReader sr = new StreamReader(fs);
                while (true)
                {
                    line = sr.ReadLine();
                    count++;
                    if (line != null)
                    {
                        line = line.Trim();
                        if (line.Length > 0)
                        {
                            if (line.IndexOf(";") == 0)
                            {
                                continue;
                            }

                            if (line.IndexOf("[") == 0 && line.IndexOf("]") > 0)
                            {
                                id = line.Substring(line.IndexOf('[') + 1, line.IndexOf(']') - (line.IndexOf('[') + 1));

                                continue;
                            }
                            else
                            {
                                int itmp = line.IndexOf(" ");
                                net  = line.Substring(0, itmp);
                                line = line.Substring(itmp).Trim();
                                itmp = line.IndexOf(" ");
                                cor  = line.Substring(0, itmp);

                                DataRow dr = dataDic.Tables[0].NewRow();
                                dr["id"]  = id;
                                dr["net"] = net;
                                dr["cor"] = cor;
                                dataDic.Tables[0].Rows.Add(dr);
                            }
                        }
                        else
                        {
                            id = "";
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                sr.Close();
                fs.Close();
            }
            catch (Exception ex)
            {
                LogWrite.WriteLog("原因:" + ex.Message, "'DD' 初始化失败,行" + count.ToString());
                throw ex;
            }
        }
예제 #9
0
파일: JNKY.cs 프로젝트: lmj823/dianpiao
        private static string SendData(string s, string nodeNo)
        {
            string recv = "error";

            byte[] body = Encoding.GetEncoding("GBK").GetBytes(s);

            byte[] head = new byte[2];
            head[0] = Convert.ToByte(body.Length >> 8);
            head[1] = Convert.ToByte(body.Length % 256);
            TcpClient sendTcp = new TcpClient();
            //string Restr = "";
            ini        myini       = new ini(filename);
            int        apphostport = Convert.ToInt32(myini.ReadValue(nodeNo, "hostPort").ToString());
            IPAddress  ip          = IPAddress.Parse(myini.ReadValue(nodeNo, "hostIP").ToString());
            IPEndPoint ipe         = new IPEndPoint(ip, apphostport);

            sendTcp.SendBufferSize = 10240;
            sendTcp.SendTimeout    = 10 * 1000;

            try
            {
                sendTcp.Connect(ip, apphostport);
            }
            catch (Exception ex)
            {
                sendTcp.Close();
                LogWrite.WriteLog("原因:" + ex.Message, "[加密机]连接服务器失败", nodeNo);
                return(recv);
            }
            NetworkStream ns = sendTcp.GetStream();

            ns.WriteTimeout = 10 * 1000;
            ns.ReadTimeout  = 10 * 1000;
            try
            {
                if (ns.CanWrite)
                {
                    ns.Write(head, 0, head.Length);
                    ns.Write(body, 0, body.Length);
                    //LogWrite.WriteLog(s, "[加密机]发送数据:", nodeNo);
                    if (ns.CanRead)
                    {
                        byte[] len = new byte[2];
                        ns.Read(len, 0, 2);
                        int    L       = len[0] * 256 + len[1];
                        byte[] recbuff = new byte[L];

                        int index = 0;
                        while (index < L)
                        {
                            int cout = ns.Read(recbuff, index, L - index);
                            if (cout <= 0)
                            {
                                break;
                            }
                            index += cout;
                        }

                        recv = Encoding.GetEncoding("gbk").GetString(recbuff);
                        //LogWrite.WriteLog(recv, "[加密机]接收数据:", nodeNo);
                    }
                }
                else
                {
                    LogWrite.WriteLog("连接不可用", "[加密机]发数据失败:", nodeNo);
                }
            }
            catch (Exception ex)
            {
                LogWrite.WriteLog(ex.Message, "[加密机]通讯故障,原因:", nodeNo);
            }
            finally
            {
                ns.Close();
                sendTcp.Close();
            }
            return(recv);
        }