示例#1
0
        public void Execute(params object[] list)
        {
            try {
                var tmpEncoding = Encoding.UTF8;
                System.Console.OutputEncoding = Encoding.Default;
                System.Console.InputEncoding  = Encoding.Default;

                wa = new WhatsAppApi.WhatsApp(WAConfig["Sender"], WAConfig["Password"], WAConfig["NickName"], false);
                wa.OnLoginSuccess   += wa_OnLoginSuccess;
                wa.OnConnectSuccess += wa_OnConnectSuccess;
                wa.OnError          += wa_OnError;
                wa.OnConnectFailed  += wa_ConnectFailed;
                wa.OnLoginFailed    += wa_LoginFailed;
                wa.Connect();
                wa.Login();
                string MType = ((string)list [0]);
                switch (MType)
                {
                case "location":
                    wa.SendMessageLocation(WAConfig["Target"], double.Parse((string)list [1], System.Globalization.CultureInfo.InvariantCulture.NumberFormat), double.Parse((string)list [2], System.Globalization.CultureInfo.InvariantCulture.NumberFormat), (string)(list [3]), "");
                    break;

                case "text":
                    wa.SendMessage(WAConfig["Target"], ((string)list [1]));
                    break;

                case "picture":
                    wa.SendMessageImage(WAConfig["Target"], System.IO.File.ReadAllBytes(((string)list [1])), WhatsAppApi.ApiBase.ImageType.PNG);
                    break;

                case "audio":
                    wa.SendMessageAudio(WAConfig["Target"], System.IO.File.ReadAllBytes(((string)list [1])), ApiBase.AudioType.MP3);
                    break;

                case "video":
                    wa.SendMessageVideo(WAConfig["Target"], System.IO.File.ReadAllBytes(((string)list [1])), ApiBase.VideoType.MP4);
                    break;
                }
                de.SYStemiya.Helper.Logger.WriteLine("|  > [WhatsApp] *** Message(" + ((string)(list [0])).ToUpper() + ") sent: " + list[1]);
                PluginEvent messageSent = Event;
                if (messageSent != null)
                {
                    messageSent(this, 2, 2, 2, 2, 2, 2);
                }
            } catch (Exception ex) {
                de.SYStemiya.Helper.Logger.WriteLine(ex.Message);
                de.SYStemiya.Helper.Logger.WriteLine(ex.StackTrace);
                if (ex.InnerException != null)
                {
                    de.SYStemiya.Helper.Logger.WriteLine(ex.InnerException.Message);
                    de.SYStemiya.Helper.Logger.WriteLine(ex.InnerException.StackTrace);
                }
            }
        }