예제 #1
0
        private static void Main(string[] args)
        {
            //Turkish Encoding
            System.Console.OutputEncoding = Encoding.GetEncoding(857);
            System.Console.InputEncoding  = Encoding.GetEncoding(857);

            //UTF-8 Encoding
            //System.Console.OutputEncoding = Encoding.UTF8;
            //System.Console.InputEncoding = Encoding.UTF8;

            string _Nickname = "";
            string _Sender   = ""; //Mobile Number with Country Code (but without + or 00)
            string _Password = ""; //v2 password
            string _Target   = ""; // Mobile Number to Send the Message to

            _WhatsAppApi = new WhatsApp(_Sender, _Password, _Nickname, true);

            //Event Bindings
            _WhatsAppApi.OnLoginSuccess             += OnLoginSuccess;
            _WhatsAppApi.OnLoginFailed              += OnLoginFailed;
            _WhatsAppApi.OnGetMessage               += OnGetMessage;
            _WhatsAppApi.OnGetMessageReadedClient   += OnGetMessageReadedClient;
            _WhatsAppApi.OnGetMessageReceivedClient += OnGetMessageReceivedClient;
            _WhatsAppApi.OnGetMessageReceivedServer += OnGetMessageReceivedServer;
            _WhatsAppApi.OnNotificationPicture      += OnNotificationPicture;
            _WhatsAppApi.OnGetPresence              += OnGetPresence;
            _WhatsAppApi.OnGetGroupParticipants     += OnGetGroupParticipants;
            _WhatsAppApi.OnGetLastSeen              += OnGetLastSeen;
            _WhatsAppApi.OnGetTyping          += OnGetTyping;
            _WhatsAppApi.OnGetPaused          += OnGetPaused;
            _WhatsAppApi.OnGetMessageImage    += OnGetMessageImage;
            _WhatsAppApi.OnGetMessageAudio    += OnGetMessageAudio;
            _WhatsAppApi.OnGetMessageVideo    += OnGetMessageVideo;
            _WhatsAppApi.OnGetMessageLocation += OnGetMessageLocation;
            _WhatsAppApi.OnGetMessageVcard    += OnGetMessageVcard;
            _WhatsAppApi.OnGetPhoto           += OnGetPhoto;
            _WhatsAppApi.OnGetPhotoPreview    += OnGetPhotoPreview;
            _WhatsAppApi.OnGetGroups          += OnGetGroups;
            _WhatsAppApi.OnGetSyncResult      += OnGetSyncResult;
            _WhatsAppApi.OnGetStatus          += OnGetStatus;
            _WhatsAppApi.OnGetPrivacySettings += OnGetPrivacySettings;
            _WhatsAppApi.OnGetBroadcastLists  += OnGetBroadcastLists;

            /*Debug Code*/
            DebugAdapter.Instance.OnPrintDebug += Instance_OnPrintDebug;

            _WhatsAppApi.SendGetServerProperties();

            // Error Notification ErrorAxolotl
            _WhatsAppApi.OnErrorAxolotl += OnErrorAxolotl;

            _WhatsAppApi.Connect();

            string datFile = GetDatFileName(_Sender);

            byte[] nextChallenge = null;
            if (File.Exists(datFile))
            {
                try
                {
                    String foo = File.ReadAllText(datFile);
                    nextChallenge = Convert.FromBase64String(foo);
                }
                catch (Exception)
                {
                };
            }

            _WhatsAppApi.Login(nextChallenge);

            ProcessChat(_WhatsAppApi, _Target);
            Console.ReadKey();
        }
예제 #2
0
        private static void Main(string[] args)
        {
            var tmpEncoding = Encoding.UTF8;

            Console.OutputEncoding = Encoding.Default;
            Console.InputEncoding  = Encoding.Default;
            string nickname = "QA Tim";
            string sender   = "553193087883";                 // Mobile number with country code (but without + or 00)
            string password = "******"; //v2 password
            string target   = "553188717292";                 // Mobile number to send the message to

            wa = new WhatsApp(sender, password, nickname, true);

            //event bindings
            wa.OnLoginSuccess             += wa_OnLoginSuccess;
            wa.OnLoginFailed              += wa_OnLoginFailed;
            wa.OnGetMessage               += wa_OnGetMessage;
            wa.OnGetMessageReadedClient   += wa_OnGetMessageReadedClient;
            wa.OnGetMessageReceivedClient += wa_OnGetMessageReceivedClient;
            wa.OnGetMessageReceivedServer += wa_OnGetMessageReceivedServer;
            wa.OnNotificationPicture      += wa_OnNotificationPicture;
            wa.OnGetPresence              += wa_OnGetPresence;
            wa.OnGetGroupParticipants     += wa_OnGetGroupParticipants;
            wa.OnGetLastSeen              += wa_OnGetLastSeen;
            wa.OnGetTyping                     += wa_OnGetTyping;
            wa.OnGetPaused                     += wa_OnGetPaused;
            wa.OnGetMessageImage               += wa_OnGetMessageImage;
            wa.OnGetMessageAudio               += wa_OnGetMessageAudio;
            wa.OnGetMessageVideo               += wa_OnGetMessageVideo;
            wa.OnGetMessageLocation            += wa_OnGetMessageLocation;
            wa.OnGetMessageVcard               += wa_OnGetMessageVcard;
            wa.OnGetPhoto                      += wa_OnGetPhoto;
            wa.OnGetPhotoPreview               += wa_OnGetPhotoPreview;
            wa.OnGetGroups                     += wa_OnGetGroups;
            wa.OnGetSyncResult                 += wa_OnGetSyncResult;
            wa.OnGetStatus                     += wa_OnGetStatus;
            wa.OnGetPrivacySettings            += wa_OnGetPrivacySettings;
            DebugAdapter.Instance.OnPrintDebug += Instance_OnPrintDebug;
            wa.SendGetServerProperties();
            //ISessionStore AxolotlStore
            wa.OnstoreSession         += wa_OnstoreSession;
            wa.OnloadSession          += wa_OnloadSession;
            wa.OngetSubDeviceSessions += wa_OngetSubDeviceSessions;
            wa.OncontainsSession      += wa_OncontainsSession;
            wa.OndeleteSession        += wa_OndeleteSession;
            // IPreKeyStore AxolotlStore
            wa.OnstorePreKey    += wa_OnstorePreKey;
            wa.OnloadPreKey     += wa_OnloadPreKey;
            wa.OnloadPreKeys    += wa_OnloadPreKeys;
            wa.OncontainsPreKey += wa_OncontainsPreKey;
            wa.OnremovePreKey   += wa_OnremovePreKey;
            // ISignedPreKeyStore AxolotlStore
            wa.OnstoreSignedPreKey    += wa_OnstoreSignedPreKey;
            wa.OnloadSignedPreKey     += wa_OnloadSignedPreKey;
            wa.OnloadSignedPreKeys    += wa_OnloadSignedPreKeys;
            wa.OncontainsSignedPreKey += wa_OncontainsSignedPreKey;
            wa.OnremoveSignedPreKey   += wa_OnremoveSignedPreKey;
            // IIdentityKeyStore AxolotlStore
            wa.OngetIdentityKeyPair     += wa_OngetIdentityKeyPair;
            wa.OngetLocalRegistrationId += wa_OngetLocalRegistrationId;
            wa.OnisTrustedIdentity      += wa_OnisTrustedIdentity;
            wa.OnsaveIdentity           += wa_OnsaveIdentity;
            wa.OnstoreLocalData         += wa_OnstoreLocalData;
            // Error Notification ErrorAxolotl
            wa.OnErrorAxolotl += wa_OnErrorAxolotl;

            wa.Connect();

            string datFile = getDatFileName(sender);

            byte[] nextChallenge = null;
            if (File.Exists(datFile))
            {
                try
                {
                    string foo = File.ReadAllText(datFile);
                    nextChallenge = Convert.FromBase64String(foo);
                }
                catch (Exception) { };
            }

            wa.Login(nextChallenge);
            wa.SendGetPrivacyList();
            wa.SendGetClientConfig();

            if (wa.LoadPreKeys() == null)
            {
                wa.sendSetPreKeys(true);
            }

            ProcessChat(wa, target);
            Console.ReadKey();
        }
예제 #3
0
        public void Start()
        {
            dtEmisores_UsuariosEN = SchoolManager.WhatsApp.LogicaNegocios.Emisores_UsuariosLN.DtEmisorActivoPorUsuario(Usuario, _prioridad);
            if (dtEmisores_UsuariosEN.Rows.Count == 0)
            {
                System.Windows.Forms.MessageBox.Show(string.Format("Usuario: {0}.- No hay emisor para enviar mensajes", Usuario));
                return;
            }
            _listen = true;
            wa      = new WhatsApp(dtEmisores_UsuariosEN.Rows[0]["EMISOR"].ToString(), dtEmisores_UsuariosEN.Rows[0]["APIKEY"].ToString(), dtEmisores_UsuariosEN.Rows[0]["NOMBREPERFIL"].ToString(), true);

            wa.OnLoginSuccess             += wa_OnLoginSuccess;
            wa.OnLoginFailed              += wa_OnLoginFailed;
            wa.OnGetMessage               += wa_OnGetMessage;
            wa.OnGetMessageReceivedClient += wa_OnGetMessageReceivedClient;
            wa.OnGetMessageReceivedServer += wa_OnGetMessageReceivedServer;
            wa.OnNotificationPicture      += wa_OnNotificationPicture;
            wa.OnGetPresence              += wa_OnGetPresence;
            wa.OnGetGroupParticipants     += wa_OnGetGroupParticipants;
            wa.OnGetLastSeen              += wa_OnGetLastSeen;
            wa.OnGetTyping                     += wa_OnGetTyping;
            wa.OnGetPaused                     += wa_OnGetPaused;
            wa.OnGetMessageImage               += wa_OnGetMessageImage;
            wa.OnGetMessageAudio               += wa_OnGetMessageAudio;
            wa.OnGetMessageVideo               += wa_OnGetMessageVideo;
            wa.OnGetMessageLocation            += wa_OnGetMessageLocation;
            wa.OnGetMessageVcard               += wa_OnGetMessageVcard;
            wa.OnGetPhoto                      += wa_OnGetPhoto;
            wa.OnGetPhotoPreview               += wa_OnGetPhotoPreview;
            wa.OnGetGroups                     += wa_OnGetGroups;
            wa.OnGetSyncResult                 += wa_OnGetSyncResult;
            wa.OnGetStatus                     += wa_OnGetStatus;
            wa.OnGetPrivacySettings            += wa_OnGetPrivacySettings;
            DebugAdapter.Instance.OnPrintDebug += Instance_OnPrintDebug;

            dtUltimaConexion = DateTime.Now;
            wa.Connect();
            //wa.Login();
            string datFile = getDatFileName(dtEmisores_UsuariosEN.Rows[0]["EMISOR"].ToString());

            if (File.Exists(datFile))
            {
                try
                {
                    string foo = File.ReadAllText(datFile);
                    nextChallenge = Convert.FromBase64String(foo);
                }
                catch (Exception) { };
            }
            wa.Login(nextChallenge);
            wa.SendGetServerProperties();

            thRecv = new System.Threading.Thread(t =>
            {
                try
                {
                    while (_listen)
                    {
                        wa.PollMessages();
                        System.Threading.Thread.Sleep(100);
                        continue;
                    }
                }
                catch (System.Threading.ThreadAbortException)
                {
                }
            })
            {
                IsBackground = true
            };
            thRecv.Start();

            if (_types != null && _types.Length > 0)
            {
                // Using only the XmlMessageFormatter. You can use other formatters as well
                _queue.Formatter = new XmlMessageFormatter(_types);
            }

            _queue.PeekCompleted    += new PeekCompletedEventHandler(OnPeekCompleted);
            _queue.ReceiveCompleted += new ReceiveCompletedEventHandler(OnReceiveCompleted);

            StartListening();
        }
예제 #4
0
        private void OnReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
        {
            try
            {
                System.Messaging.Message msg = _queue.EndReceive(e.AsyncResult);
                FireRecieveEvent(msg);
                string[] strArr    = null;
                char[]   splitchar = { '|' };
                strArr = e.Message.Label.Split(splitchar);
                string folio, receptor, recurso;
                folio    = strArr[0];
                receptor = strArr[1];
                recurso  = strArr[2];
                bool nuevaConexion = false;
volver_conectar:
                try
                {
                    SchoolManager.WhatsApp.LogicaNegocios.WhatsApp_UsuarioLN.PonerStatusListoParaEnviar(Usuario, dtEmisores_UsuariosEN.Rows[0]["EMISOR"].ToString(), folio, "");
                    WhatsUserManager usrMan = new WhatsUserManager();
                    var tmpUser             = usrMan.CreateUser(receptor, "User" + receptor);
                    WhatsAppApi.Parser.FMessage.FMessageIdentifierKey key = new WhatsAppApi.Parser.FMessage.FMessageIdentifierKey(tmpUser.GetFullJid(), true, folio);
                    WhatsAppApi.Parser.FMessage msj = new WhatsAppApi.Parser.FMessage(key);
                    msj.data = e.Message.Body.ToString();
                    if (dtUltimaConexion.AddMinutes(1) < DateTime.Now | nuevaConexion)
                    {
                        wa.Connect();
                        //wa.Login();
                        string datFile = getDatFileName(dtEmisores_UsuariosEN.Rows[0]["EMISOR"].ToString());
                        if (File.Exists(datFile))
                        {
                            try
                            {
                                string foo = File.ReadAllText(datFile);
                                nextChallenge = Convert.FromBase64String(foo);
                            }
                            catch (Exception) { };
                        }
                        wa.Login(nextChallenge);
                        wa.SendGetServerProperties();
                    }
                    dtUltimaConexion = DateTime.Now;
                    if (wa.ConnectionStatus == ApiBase.CONNECTION_STATUS.CONNECTED | wa.ConnectionStatus == ApiBase.CONNECTION_STATUS.DISCONNECTED)
                    {
                        wa.Connect();
                        //wa.Login();
                        string datFile = getDatFileName(dtEmisores_UsuariosEN.Rows[0]["EMISOR"].ToString());
                        if (File.Exists(datFile))
                        {
                            try
                            {
                                string foo = File.ReadAllText(datFile);
                                nextChallenge = Convert.FromBase64String(foo);
                            }
                            catch (Exception) { };
                        }
                        wa.Login(nextChallenge);
                        wa.SendGetServerProperties();
                    }
                    else if (wa.ConnectionStatus == ApiBase.CONNECTION_STATUS.UNAUTHORIZED)
                    {
                        SchoolManager.WhatsApp.LogicaNegocios.WhatsApp_UsuarioLN.PonerStatusErrorEnvio(Usuario, dtEmisores_UsuariosEN.Rows[0]["EMISOR"].ToString(), folio, "No Autorizado para enviar");
                        this.Stop();
                        return;
                    }
                    wa.SendMessage(msj);
                    Random objRandom = new Random();
                    System.Threading.Thread.Sleep(objRandom.Next(2000, 3000));
                }
                catch (Exception ex)
                {
                    if (ex.Message == "Se ha anulado una conexión establecida por el software en su equipo host")
                    {
                        nuevaConexion = true;
                        wa.Disconnect();
                        System.Threading.Thread.Sleep(5000);
                        goto volver_conectar;
                    }
                    else
                    {
                        SchoolManager.WhatsApp.LogicaNegocios.WhatsApp_UsuarioLN.PonerStatusErrorEnvio(Usuario, dtEmisores_UsuariosEN.Rows[0]["EMISOR"].ToString(), folio, "Error al enviar: " + ex.Message);
                        return;
                    }
                }
                SchoolManager.WhatsApp.LogicaNegocios.WhatsApp_UsuarioLN.PonerStatusEnviando(Usuario, dtEmisores_UsuariosEN.Rows[0]["EMISOR"].ToString(), folio, "");
                StartListening();
            }
            catch (Exception ex)
            {
                this.Stop();
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }
예제 #5
0
        private static void Main(string[] args)
        {
            var tmpEncoding = Encoding.UTF8;

            System.Console.OutputEncoding = Encoding.Default;
            System.Console.InputEncoding  = Encoding.Default;
            string nickname = "";
            string sender   = ""; // Mobile number with country code (but without + or 00)
            string password = ""; //v2 password
            string target   = ""; // Mobile number to send the message to

            WhatsApp wa = new WhatsApp(sender, password, nickname, true);

            //event bindings
            wa.OnLoginSuccess             += wa_OnLoginSuccess;
            wa.OnLoginFailed              += wa_OnLoginFailed;
            wa.OnGetMessage               += wa_OnGetMessage;
            wa.OnGetMessageReadedClient   += wa_OnGetMessageReadedClient;
            wa.OnGetMessageReceivedClient += wa_OnGetMessageReceivedClient;
            wa.OnGetMessageReceivedServer += wa_OnGetMessageReceivedServer;
            wa.OnNotificationPicture      += wa_OnNotificationPicture;
            wa.OnGetPresence              += wa_OnGetPresence;
            wa.OnGetGroupParticipants     += wa_OnGetGroupParticipants;
            wa.OnGetLastSeen              += wa_OnGetLastSeen;
            wa.OnGetTyping                     += wa_OnGetTyping;
            wa.OnGetPaused                     += wa_OnGetPaused;
            wa.OnGetMessageImage               += wa_OnGetMessageImage;
            wa.OnGetMessageAudio               += wa_OnGetMessageAudio;
            wa.OnGetMessageVideo               += wa_OnGetMessageVideo;
            wa.OnGetMessageLocation            += wa_OnGetMessageLocation;
            wa.OnGetMessageVcard               += wa_OnGetMessageVcard;
            wa.OnGetPhoto                      += wa_OnGetPhoto;
            wa.OnGetPhotoPreview               += wa_OnGetPhotoPreview;
            wa.OnGetGroups                     += wa_OnGetGroups;
            wa.OnGetSyncResult                 += wa_OnGetSyncResult;
            wa.OnGetStatus                     += wa_OnGetStatus;
            wa.OnGetPrivacySettings            += wa_OnGetPrivacySettings;
            DebugAdapter.Instance.OnPrintDebug += Instance_OnPrintDebug;

            wa.Connect();

            string datFile = getDatFileName(sender);

            byte[] nextChallenge = null;
            if (File.Exists(datFile))
            {
                try
                {
                    string foo = File.ReadAllText(datFile);
                    nextChallenge = Convert.FromBase64String(foo);
                }
                catch (Exception) { };
            }

            wa.Login(nextChallenge);
            wa.SendGetServerProperties();

            ProcessChat(wa, target);
            Console.ReadKey();

            wa.SendMessage(sender, "test");
            while (true)
            {
                wa.pollMessage();
            }
        }
예제 #6
0
        private static void Main(string[] args)
        {
            LoadSession();
            var tmpEncoding = Encoding.UTF8;

            System.Console.OutputEncoding = Encoding.UTF8;
            System.Console.InputEncoding  = Encoding.UTF8;
            string nickname = "stico";

            string password = "******"; //v2 password
            string target   = "34629171696";                  // Mobile number to send the message to

            password = WhatsAppApi.Register.WhatsRegisterV2.RequestExist(sender);

            wa = new WhatsApp(sender, password, nickname, false);

            //event bindings
            wa.OnLoginSuccess             += wa_OnLoginSuccess;
            wa.OnLoginFailed              += wa_OnLoginFailed;
            wa.OnGetMessage               += wa_OnGetMessage;
            wa.OnGetMessageReadedClient   += wa_OnGetMessageReadedClient;
            wa.OnGetMessageReceivedClient += wa_OnGetMessageReceivedClient;
            wa.OnGetMessageReceivedServer += wa_OnGetMessageReceivedServer;
            wa.OnNotificationPicture      += wa_OnNotificationPicture;
            wa.OnGetPresence              += wa_OnGetPresence;
            wa.OnGetGroupParticipants     += wa_OnGetGroupParticipants;
            wa.OnGetLastSeen              += wa_OnGetLastSeen;
            wa.OnGetTyping                     += wa_OnGetTyping;
            wa.OnGetPaused                     += wa_OnGetPaused;
            wa.OnGetMessageImage               += wa_OnGetMessageImage;
            wa.OnGetMessageAudio               += wa_OnGetMessageAudio;
            wa.OnGetMessageVideo               += wa_OnGetMessageVideo;
            wa.OnGetMessageLocation            += wa_OnGetMessageLocation;
            wa.OnGetMessageVcard               += wa_OnGetMessageVcard;
            wa.OnGetPhoto                      += wa_OnGetPhoto;
            wa.OnGetPhotoPreview               += wa_OnGetPhotoPreview;
            wa.OnGetGroups                     += wa_OnGetGroups;
            wa.OnGetSyncResult                 += wa_OnGetSyncResult;
            wa.OnGetStatus                     += wa_OnGetStatus;
            wa.OnGetPrivacySettings            += wa_OnGetPrivacySettings;
            DebugAdapter.Instance.OnPrintDebug += Instance_OnPrintDebug;
            wa.SendGetServerProperties();
            //ISessionStore AxolotlStore
            wa.OnstoreSession         += wa_OnstoreSession;
            wa.OnloadSession          += wa_OnloadSession;
            wa.OngetSubDeviceSessions += wa_OngetSubDeviceSessions;
            wa.OncontainsSession      += wa_OncontainsSession;
            wa.OndeleteSession        += wa_OndeleteSession;
            // IPreKeyStore AxolotlStore
            wa.OnstorePreKey    += wa_OnstorePreKey;
            wa.OnloadPreKey     += wa_OnloadPreKey;
            wa.OnloadPreKeys    += wa_OnloadPreKeys;
            wa.OncontainsPreKey += wa_OncontainsPreKey;
            wa.OnremovePreKey   += wa_OnremovePreKey;

            //Sender key
            wa.OnstoreSenderKey    += wa_OnstoreSenderKey;
            wa.OnloadSenderKey     += wa_OnloadSenderKey;
            wa.OnremoveSenderKey   += wa_OnremoveSenderKey;
            wa.OncontainsSenderKey += wa_OncontainsSenderKey;

            // ISignedPreKeyStore AxolotlStore
            wa.OnstoreSignedPreKey    += wa_OnstoreSignedPreKey;
            wa.OnloadSignedPreKey     += wa_OnloadSignedPreKey;
            wa.OnloadSignedPreKeys    += wa_OnloadSignedPreKeys;
            wa.OncontainsSignedPreKey += wa_OncontainsSignedPreKey;
            wa.OnremoveSignedPreKey   += wa_OnremoveSignedPreKey;
            // IIdentityKeyStore AxolotlStore
            wa.OngetIdentityKeyPair     += wa_OngetIdentityKeyPair;
            wa.OngetLocalRegistrationId += wa_OngetLocalRegistrationId;
            wa.OnisTrustedIdentity      += wa_OnisTrustedIdentity;
            wa.OnsaveIdentity           += wa_OnsaveIdentity;
            wa.OnstoreLocalData         += wa_OnstoreLocalData;
            // Error Notification ErrorAxolotl
            wa.OnErrorAxolotl += wa_OnErrorAxolotl;

            wa.Connect();

            string datFile = getDatFileName(sender);

            byte[] nextChallenge = null;
            if (File.Exists(datFile))
            {
                try
                {
                    string foo = File.ReadAllText(datFile);
                    nextChallenge = Convert.FromBase64String(foo);
                }
                catch (Exception) { };
            }

            wa.Login(nextChallenge);
            wa.SendGetPrivacyList();
            wa.SendGetClientConfig();

            if (wa.LoadPreKeys() == null)
            {
                wa.sendSetPreKeys(true);
            }

            ProcessChat(wa, target);
            Console.ReadKey();
        }