Ejemplo n.º 1
0
        public static void WebSocket()
        {
            using (var ws = new WebSocket("ws://messenger.happl.com:8080"))
            {
                string vremya = DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ss ");
                ws.OnOpen += (sender, e) =>
                {
                    IsConnected = true;
                };
                TimerCallback          tm    = new TimerCallback(Count);
                System.Threading.Timer timer = new System.Threading.Timer(tm, null, 10000, 60000);
                void Count(object obj)
                {
                    bool pr = ws.IsAlive;

                    otvet    = General.Check(timelast, idmes);
                    idmes    = Convert.ToInt64(Regex.Match(otvet, ".*(?=DEL)").Value);
                    timelast = Convert.ToInt64(Regex.Match(otvet, "(?<=DEL).*(?={\"e\":\")").Value);
                    otvet    = Regex.Match(otvet, "{\"e.*").Value;
                    string lengh = Regex.Match(otvet, "(?<=length\": ).*(?=}}})").Value;

                    if (lengh != "0,")
                    {
                        opendb.Insert(idmes, timelast);
                        WinApi.StartWork();
                        WinApi.ReadMessage();
                        ws.Send(otvet);
                        Console.WriteLine(DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ss ") + FindNumber.Useak() + " Новые сообщения");
                    }
                    return;
                }

                Thread.Sleep(3000);
                string telo = "{\"e\":\"login\",\"data\":{\"origins\":{\"" + "79093449994" + "\":{\"channels\":[\"viber\"]}}}}";
                telo          = telo.Replace("\\", "");
                ws.OnMessage += (sender, e) =>
                {
                    if (e.Data.Contains("\"e\":\"status\"".Replace("\\", "")) && General.ViberWork())
                    {
                        otvet = General.Status(e.Data);
                        otvet = otvet.Replace("msisdn", FindNumber.Useak());
                        ws.Send(otvet);
                        vconsol = Regex.Match(otvet, "(?<=to\":\").*?(?=\")").Value;
                        Console.WriteLine(DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ss ") + FindNumber.Useak() + " Статус номера " + vconsol);
                        return;
                    }
                    else if (e.Data.Contains("\"e\":\"status\",\"data\":{\"channel\":\"viber\"".Replace("\\", "")) && !General.ViberWork())
                    {
                        Console.WriteLine(DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ss ") + " Viber не авторизован ");
                        return;
                    }
                    else if (e.Data.Contains("{\"e\":\"send\"".Replace("\\", "")) && General.ViberWork())
                    {
                        otvet   = General.Send(e.Data);
                        otvet   = otvet.Replace("msisdn", FindNumber.Useak());
                        vconsol = Regex.Match(otvet, "(?<=to\":\").*?(?=\")").Value;
                        ws.Send(otvet);
                        Console.WriteLine(DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ss ") + FindNumber.Useak() + " Сообщение на номер " + vconsol);
                        return;
                    }
                    else if (e.Data.Contains("\"e\":\"status\",\"data\":{\"channel\":\"viber\"".Replace("\\", "")) && !General.ViberWork())
                    {
                        Console.WriteLine(DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ss ") + " Viber не авторизован ");
                        return;
                    }
                    Console.WriteLine(e.Data);
                };
                ws.OnError += (sender, e) =>
                {
                    IsConnected = false;
                };
                ws.OnClose += (sender, e) =>
                {
                    IsConnected = false;
                    Console.WriteLine(DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ss ") + "Ошибка соединения");
                };
                ws.Connect();
                ws.Send(telo);
                while (IsConnected)
                {
                    Thread.Sleep(300);
                }
            }
        }
Ejemplo n.º 2
0
        public static string Check(long timelast, long idmes)
        {
            string type          = "";
            int    z             = 0;
            string check         = "";
            var    chatidmsg     = opendb.ChatIdMsg();
            var    typemsg       = opendb.Type();
            var    images        = opendb.Image();
            var    info          = opendb.Info();
            var    timestamps    = opendb.TimeStamps();
            var    isread        = opendb.IsRead();
            var    subject       = opendb.Subject();
            var    contactidmsg  = opendb.ContactIdMsg();
            var    body          = opendb.Body();
            var    contactid     = opendb.ContactId();
            var    numbers       = opendb.Numbers();
            var    clientname    = opendb.ClientName();
            var    vibercontacts = opendb.ViberContacts();
            var    names         = opendb.Names();
            var    IdMes         = opendb.IdMes();
            var    messagestatus = opendb.MessageStatuses();
            int    count         = contactidmsg.Count;

            string[] newchat = new string[chatidmsg.Count];
            if (timelast == 0)
            {
                for (int i = 0; i < isread.Count; i++)
                {
                    if (isread[i] == "0" && messagestatus[i] == "0" && timelast < Convert.ToInt64(timestamps[i]))
                    {
                        idmes    = Convert.ToInt64(IdMes[IdMes.Count - 1]);
                        timelast = Convert.ToInt64(timestamps[timestamps.Count - 1]);
                        count    = i;
                        break;
                    }
                }
                for (int i = count; i < contactidmsg.Count; i++)
                {
                    if (!newchat.Contains(contactidmsg[i]) && contactidmsg[i] != "1" && isread[i] == "0")
                    {
                        newchat[z] = contactidmsg[i];
                        z++;
                    }
                }
                string[] newchat1 = new string[z];
                string[] name     = new string[z];
                string[] nomer    = new string[z];
                string[] messages = new string[z];
                for (int i = 0; i < z; i++)
                {
                    name[i] = names[Convert.ToInt32(newchat[i]) - 2];
                    if (name[i] == "")
                    {
                        name[i] = clientname[Convert.ToInt32(newchat[i]) - 2];
                    }
                    nomer[i]    = numbers[Convert.ToInt32(newchat[i]) - 2];
                    newchat1[i] = newchat[i];
                }
                string letter  = "";
                string letter1 = "";
                for (int i = 0; i < z; i++)
                {
                    string   letter2 = "";
                    string[] tipi    = new string[body.Count];
                    for (int ii = count; ii < body.Count; ii++)
                    {
                        if (isread[ii] == "0" && messagestatus[ii] == "0" && contactidmsg[ii] == newchat1[i])
                        {
                            if (typemsg[ii] == "1")
                            {
                                type    = "text";
                                letter2 = letter2 + "{\"type\":\"" + type + "\",\"text\":\"" + body[ii] + "\"},";
                            }
                            if (typemsg[ii] == "4")
                            {
                                type    = "stiсker";
                                letter2 = letter2 + "{\"type\":\"" + type + "\",\"text\":\"" + body[ii] + "\"},";
                            }
                            if (typemsg[ii] == "72")
                            {
                                type    = "text";
                                letter2 = letter2 + "{\"type\":\"" + type + "\",\"text\":\"" + "Сообщение удалено" + "\"},";
                            }
                            if (typemsg[ii] == "6")
                            {
                                type    = "voice";
                                letter2 = letter2 + "{\"type\":\"" + type + "\",\"text\":\"" + body[ii] + "\"},";
                            }
                            if (typemsg[ii] == "11")
                            {
                                type     = "file";
                                info[ii] = Regex.Match(info[ii], "(?<=FileName\": \").*?(?=\",)").Value;
                                letter2  = letter2 + "{\"type\":\"" + type + "\",\"text\":\"" + info[ii] + "\"},";
                            }
                            if (typemsg[ii] == "3")
                            {
                                type       = "video";
                                images[ii] = Regex.Match(images[ii], "(?<=ViberDownloads/).*").Value;
                                letter2    = letter2 + "{\"type\":\"" + type + "\",\"text\":\"" + body[ii] + "\"},";
                            }
                            if (typemsg[ii] == "2")
                            {
                                type       = "image";
                                images[ii] = Regex.Match(images[ii], "(?<=ViberDownloads/).*").Value;
                                letter2    = letter2 + "{\"type\":\"" + type + "\",\"text\":\"" + body[ii] + "\",\"file\":\"" + images[ii] + "\"},";
                            }
                            if (typemsg[ii] == "10")
                            {
                                type    = "contact";
                                letter2 = letter2 + "{\"type\":\"" + type + "\",\"text\":\"" + body[ii] + "\",\"file\":\"" + subject[ii] + "\"},";
                            }
                            if (body[ii].Contains("https://maps.yandex.ru"))
                            {
                                type     = "location";
                                body[ii] = Regex.Match(body[ii], "(?<=ActionBody\":\").*?(?=\")").Value;
                                letter2  = letter2 + "{\"type\":\"" + type + "\",\"text\":\"" + body[ii] + "\"},";
                            }
                        }
                        letter1 = "\"" + i + "\":{\"sender\":{\"name\":\"" + name[i] + "\",\"msisdn\":\"" + nomer[i] + "\"}," + "\"messages\":[" + letter2 + "]}";
                    }
                    if (letter1 != "" && !letter1.Contains("ges\":[]"))
                    {
                        letter1 = letter1.Substring(0, letter1.Length - 3) + "]}";
                    }
                    letter = letter.Insert(letter.Length, letter1 + ",");
                }
                //otvet = "\"0\":{\"sender\":{\"name\":\"Антоша\",\"msisdn\":\"+79828301578\"},\"messages\":[{\"type\":\"text\",\"text\":\"(inlove)\"},{\"type\":\"text\",\"text\":\"1\"},{\"type\":\"text\",\"text\":\"2\"}]}}}}";
                if (letter != "")
                {
                    letter = letter.Substring(0, letter.Length - 1);
                }

                check = idmes + "DEL" + timelast + "{\"e\":\"messages\",\"status\":\"ok\",\"data\":{\"origin\":\"" + FindNumber.Useak() + "\",\"channel\":\"viber\",\"chats\":{\"length\": " + z + "," + letter + "}}}".Replace("\\", "");;
            }
            else
            {
                for (int i = 0; i < isread.Count; i++)
                {
                    if (messagestatus[i] == "0" && timelast < Convert.ToInt64(timestamps[i]))
                    {
                        count = i;
                        break;
                    }
                }
                for (int i = count; i < contactidmsg.Count; i++)
                {
                    if (!newchat.Contains(contactidmsg[i]) && contactidmsg[i] != "1" && timelast < Convert.ToInt64(timestamps[i]))
                    {
                        newchat[z] = contactidmsg[i];
                        z++;
                    }
                }
                string[] newchat1 = new string[z];
                string[] name     = new string[z];
                string[] nomer    = new string[z];
                string[] messages = new string[z];
                for (int i = 0; i < z; i++)
                {
                    try
                    {
                        name[i] = names[Convert.ToInt32(newchat[i]) - 2];
                    }
                    catch { };
                    if (name[i] == "")
                    {
                        name[i] = clientname[Convert.ToInt32(newchat[i]) - 2];
                    }
                    nomer[i]    = numbers[Convert.ToInt32(newchat[i]) - 2];
                    newchat1[i] = newchat[i];
                }
                string letter  = "";
                string letter1 = "";
                for (int i = 0; i < z; i++)
                {
                    try
                    {
                        string   letter2 = "";
                        string[] tipi    = new string[body.Count];
                        for (int ii = count; ii < body.Count; ii++)
                        {
                            if (timelast < Convert.ToInt64(timestamps[ii]) && messagestatus[ii] == "0" && contactidmsg[ii] == newchat1[i])
                            {
                                if (typemsg[ii] == "1")
                                {
                                    type    = "text";
                                    letter2 = letter2 + "{\"type\":\"" + type + "\",\"text\":\"" + body[ii] + "\"},";
                                }
                                if (typemsg[ii] == "72")
                                {
                                    type    = "text";
                                    letter2 = letter2 + "{\"type\":\"" + type + "\",\"text\":\"" + "Сообщение удалено" + "\"},";
                                }
                                if (typemsg[ii] == "6")
                                {
                                    type    = "voice";
                                    letter2 = letter2 + "{\"type\":\"" + type + "\",\"text\":\"" + body[ii] + "\"},";
                                }
                                if (typemsg[ii] == "11")
                                {
                                    type     = "file";
                                    info[ii] = Regex.Match(info[ii], "(?<=FileName\": \").*?(?=\",)").Value;
                                    letter2  = letter2 + "{\"type\":\"" + type + "\",\"text\":\"" + info[ii] + "\"},";
                                }
                                if (typemsg[ii] == "3")
                                {
                                    type       = "video";
                                    images[ii] = Regex.Match(images[ii], "(?<=ViberDownloads/).*").Value;
                                    letter2    = letter2 + "{\"type\":\"" + type + "\",\"text\":\"" + body[ii] + "\"},";
                                }
                                if (typemsg[ii] == "2")
                                {
                                    type       = "image";
                                    images[ii] = Regex.Match(images[ii], "(?<=ViberDownloads/).*").Value;
                                    letter2    = letter2 + "{\"type\":\"" + type + "\",\"text\":\"" + body[ii] + "\",\"file\":\"" + images[ii] + "\"},";
                                }
                                if (typemsg[ii] == "10")
                                {
                                    type    = "contact";
                                    letter2 = letter2 + "{\"type\":\"" + type + "\",\"text\":\"" + body[ii] + "\",\"file\":\"" + subject[ii] + "\"},";
                                }
                                if (body[ii].Contains("https://maps.yandex.ru"))
                                {
                                    type     = "location";
                                    body[ii] = Regex.Match(body[ii], "(?<=ActionBody\":\").*?(?=\")").Value;
                                    letter2  = letter2 + "{\"type\":\"" + type + "\",\"text\":\"" + body[ii] + "\"},";
                                }
                            }
                            letter1 = "\"" + i + "\":{\"sender\":{\"name\":\"" + name[i] + "\",\"msisdn\":\"" + nomer[i] + "\"}," + "\"messages\":[" + letter2 + "]}";
                        }
                        if (letter1 != "")
                        {
                            letter1 = letter1.Substring(0, letter1.Length - 3) + "]}";
                        }
                        letter = letter.Insert(letter.Length, letter1 + ",");
                    }
                    catch (Exception)
                    { }
                }
                if (letter != "")
                {
                    letter = letter.Substring(0, letter.Length - 1);
                }
                idmes    = Convert.ToInt64(IdMes[IdMes.Count - 1]);
                timelast = Convert.ToInt64(timestamps[timestamps.Count - 1]);
                check    = idmes + "DEL" + timelast + "{\"e\":\"messages\",\"status\":\"ok\",\"data\":{\"origin\":\"" + FindNumber.Useak() + "\",\"channel\":\"viber\",\"chats\":{\"length\": " + z + "," + letter + "}}}".Replace("\\", "");;
            }
            return(check);
        }