Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            bool res = processArgs(args);

            if (!res)
            {
                printHelp();
                return;
            }

            Instance = new WhatsAppApi.WhatsApp(Username, Password, "WhatsApp", Debug, true);
            if (Debug)
            {
                WhatsAppApi.Helper.DebugAdapter.Instance.OnPrintDebug += Instance_OnPrintDebug;
            }
            Instance.OnError         += Instance_OnError;
            Instance.OnGetSyncResult += Instance_OnGetSyncResult;
            Instance.Connect();
            Instance.Login();
            if (Instance.ConnectionStatus == WhatsAppApi.ApiBase.CONNECTION_STATUS.LOGGEDIN)
            {
                //logged in
                Instance.SendSync(Numbers, Mode, Context);

                while (Instance.pollMessage(false))
                {
                    ;
                }
            }
            else
            {
                Console.WriteLine("Login failed: {0}", Instance.ConnectionStatus);
            }
        }
Ejemplo n.º 2
0
        public static void ChekWALoginMy(DataRow dr, DataMy dt)
        {
            Int32   ok = 1;
            Int32   no = 0;
            decimal iiii;
            Int32   i = Convert.ToInt32(dr[0].ToString());

            dr[1] = dr[1].ToString().Replace("+", "");
            dr[1] = dr[1].ToString().Replace("-", "");
            dr[1] = dr[1].ToString().Replace("(", "");
            dr[1] = dr[1].ToString().Replace(")", "");
            dr[1] = dr[1].ToString().TrimStart(new char[] { '0' });
            // MessageBox.Show(dr[1].ToString()+"Первый");
            decimal.TryParse(dr[1].ToString().Trim(), out iiii);
            if (iiii <= 0)
            {
                return;
            }
            if (i >= 0 && i < 2147483647)
            {
                //  MessageBox.Show(dr[1].ToString()+"Второй"+iiii.ToString());
                string namber = dr[1].ToString() ?? " ";
                //WhatsAppApi.Parser.PhoneNumber pn =new WhatsAppApi.Parser.PhoneNumber(namber);
                string passWord         = dr[2].ToString() ?? " ";
                string nik              = dr[3].ToString() ?? " ";
                WhatsAppApi.WhatsApp wa = new WhatsAppApi.WhatsApp(namber, passWord, nik);

                wa.OnConnectSuccess += () =>
                {
                    // MessageBox.Show("Присоеденились");
                    wa.OnLoginSuccess += (phoneNumber, data) =>
                    {
                        MessageBox.Show("Залогинились");
                        dt.UpdateIsActive(i, ok);
                        dt.UpdateEror(i, " ");
                        dt.UpdateDateLastLogin(i, LogicMy.dtToUnix(DateTime.Now));
                    };
                    wa.OnLoginFailed += (data) =>
                    {
                        MessageBox.Show("Не удалось залогиниться: " + data);
                        dt.UpdateIsActive(i, no);
                        dt.UpdateEror(i, data.ToString());
                        dt.UpdateDateBlock(i, LogicMy.dtToUnix(DateTime.Now));
                    };
                    wa.OnError += (id, from, code, text) =>
                    {
                        dt.UpdateIsActive(i, no);
                        dt.UpdateEror(i, id + " : " + @from + " : " + code + " : " + text);
                        MessageBox.Show(id + " : " + from + " : " + code + " : " + text);
                    };
                    wa.Login();
                };
                wa.OnConnectFailed += (ex) =>
                {
                    MessageBox.Show("Не удалось присоедениться");
                    dt.UpdateEror(i, ex.Message);
                };
                wa.Connect();
                wa.Disconnect();
            }
        }