Ejemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Json"></param>
        /// <returns></returns>
        public static Messages Deal(string Json)
        {
            Messages mes = new Messages();

            var jsons = Json.Replace("\"", "");

            return mes;
        }
Ejemplo n.º 2
0
        // 从一个Json串生成对象信息
        public static Messages JsonToObject(string jsonString)
        {
            var jsons = jsonString.Replace("\"", "").Replace("{", "").Replace("}", "").Split(',');

            string serviceip = jsons[7].Split(':')[1];
            string userip = jsons[8].Split(':')[1];
            if (serviceip == "" && userip == "")
            {
                return JsonConvert.DeserializeObject<Messages>(jsonString);
            }
            else
            {
                Messages m = new Messages();
                m.NickID = jsons[0].Split(':')[1];
                m.NickName = jsons[1].Split(':')[1];
                m.Msg = jsons[2].Split(':')[1];
                m.IsFirst = jsons[3].Split(':')[1] == "true" ? true : false;
                m.IsUser = jsons[4].Split(':')[1] == "true" ? true : false;
                m.PairingServiceID = jsons[5].Split(':')[1];
                m.PairingUserID = jsons[6].Split(':')[1];
                m.PairingServiceIP = null;
                m.PairingUserIP = null;
                m.Headimgurl = jsons[9].Split(':')[1];
                if (serviceip != "")
                {
                    serviceip = jsons[7].Split(':')[1] + ":" + jsons[7].Split(':')[2];
                    IPAddress ipadr = IPAddress.Parse(serviceip.Split(':')[0]);
                    m.PairingServiceIP = new IPEndPoint(ipadr, int.Parse(serviceip.Split(':')[1]));
                }
                if (userip != "")
                {
                    userip = jsons[8].Split(':')[1] + ":" + jsons[8].Split(':')[2];
                    IPAddress ipadr = IPAddress.Parse(userip.Split(':')[0]);
                    m.PairingUserIP = new IPEndPoint(ipadr, int.Parse(userip.Split(':')[1]));
                }

                return m;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 处理接受到的消息并分发对应人员
        /// </summary>
        /// <param name="client"></param>
        /// <param name="msg"></param>
        private void ShowClientMsg(IPEndPoint client, string msg)
        {
            if (this.InvokeRequired)
            {
                this.msgobj = UCTools.JsonToObject(msg);

                #region 客服
                if (this.msgobj.IsUser != true)
                {
                    if (this.msgobj.IsFirst == true)
                    {
                        this.ServiceIP = client;
                        this.msgobj.IsFirst = false;
                        this.BeginInvoke(new CbDelegate<IPEndPoint, string>(this.ShowClientMsg), client, "客服:" + this.msgobj.NickName + " 登录客服系统!");
                    }
                    else
                    {
                        this.BeginInvoke(new CbDelegate<IPEndPoint, string>(this.ShowClientMsg), client, msg);
                        string json = "";
                        this.msgobj.PairingServiceIP = client;
                        //发送对应人员
                        //private string jsonstr = "{\"NickID\":\"{0}\",\"NickName\":\"{1}\",\"Msg\":\"{2}\",\"IsFirst\":{3},\"IsUser\":{4},\"PairingServiceID\":\"{5}\",\"PairingUserID\": \"{6}\",\"PairingServiceIP\":\"{7}\",\"PairingUserIP\":\"{8}\"}";
                        json = "{" + string.Format("\"NickID\":\"{0}\",\"NickName\":\"{1}\",\"Msg\":\"{2}\",\"IsFirst\":\"{3}\",\"IsUser\":\"{4}\",\"PairingServiceID\":\"{5}\",\"PairingUserID\": \"{6}\",\"PairingServiceIP\":\"{7}\",\"PairingUserIP\":\"{8}\",\"Headimgurl\":\"{9}\"",
                                                    this.msgobj.NickID,
                                                    this.msgobj.NickName,
                                                    this.msgobj.Msg,
                                                    this.msgobj.IsFirst,
                                                    this.msgobj.IsUser,
                                                    this.msgobj.PairingServiceID,
                                                    this.msgobj.PairingUserID,
                                                    this.msgobj.PairingServiceIP.ToString(),
                                                    this.msgobj.PairingUserIP.ToString(),
                                                    this.msgobj.Headimgurl
                                                   ) + "}";

                        byte[] bMsg = Encoding.UTF8.GetBytes(json);//消息使用UTF-8编码
                        this.tcpServerEngine.SendMessageToClient(this.msgobj.PairingUserIP, bMsg);
                    }
                }
                #endregion

                #region 用户
                else if (this.ServiceIP != null)
                {
                    this.msgobj.PairingServiceIP = this.ServiceIP;
                    this.msgobj.PairingUserIP = client;

                    if (this.msgobj.IsFirst == false)
                    {
                        this.msgobj.PairingUserIP = client;

                        this.BeginInvoke(new CbDelegate<IPEndPoint, string>(this.ShowClientMsg), client, msg);
                        //发送对应人员
                        //private string jsonstr = "{\"NickID\":\"{0}\",\"NickName\":\"{1}\",\"Msg\":\"{2}\",\"IsFirst\":{3},\"IsUser\":{4},\"PairingServiceID\":\"{5}\",\"PairingUserID\": \"{6}\",\"PairingServiceIP\":\"{7}\",\"PairingUserIP\":\"{8}\"}";
                        string json = "{" + string.Format("\"NickID\":\"{0}\",\"NickName\":\"{1}\",\"Msg\":\"{2}\",\"IsFirst\":\"{3}\",\"IsUser\":\"{4}\",\"PairingServiceID\":\"{5}\",\"PairingUserID\": \"{6}\",\"PairingServiceIP\":\"{7}\",\"PairingUserIP\":\"{8}\",\"Headimgurl\":\"{9}\"",
                                                    this.msgobj.NickID,
                                                    this.msgobj.NickName,
                                                    this.msgobj.Msg,
                                                    this.msgobj.IsFirst,
                                                    this.msgobj.IsUser,
                                                    this.msgobj.PairingServiceID,
                                                    this.msgobj.PairingUserID,
                                                    this.msgobj.PairingServiceIP.ToString(),
                                                    this.msgobj.PairingUserIP.ToString(),
                                                    this.msgobj.Headimgurl
                                                   ) + "}";

                        byte[] bMsg = Encoding.UTF8.GetBytes(json);//消息使用UTF-8编码
                        this.tcpServerEngine.SendMessageToClient(this.msgobj.PairingServiceIP, bMsg);
                    }
                    else
                    {
                        this.BeginInvoke(new CbDelegate<IPEndPoint, string>(this.ShowClientMsg), client, "用户:" + this.msgobj.NickName + " 使用客服系统!");
                    }
                }
                #endregion

            }
            else
            {
                ListViewItem item = new ListViewItem(new string[] { DateTime.Now.ToString(), client.ToString(), msg });
                this.listView1.Items.Insert(0, item);
            }
        }