예제 #1
0
파일: LocaSMS.cs 프로젝트: trevizfe/SendSMS
        public string SendSMS(string phoneNumber, string message)
        {
            ServiceSMSSoapClient service = null;
            string retService            = "";

            try
            {
                service = new ServiceSMSSoapClient();

                retService = service.SendSMS("11987524404", "264783", new rSMS
                {
                    Destinations = new Destination[]
                    {
                        new Destination
                        {
                            Number = phoneNumber,
                        }
                    },
                    Msg     = message,
                    Subject = "ENVIOSMS_LOCASMS",
                    WarningBeginningTransmission = false,
                    Preso = false
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(retService);
        }
예제 #2
0
        /// <summary>
        /// envia a mensagem
        /// </summary>
        /// <returns>string retorno da api</returns>
        public virtual string Enviar()
        {
            string result = "";

            if (string.IsNullOrWhiteSpace(this.TelefoneDestinatario))
            {
                return("Telefone em branco");
            }

            if (string.IsNullOrWhiteSpace(this.Corpo))
            {
                return("Mensagem em branco");
            }

            try
            {
                EndpointAddress      endereco = new EndpointAddress(this.Servidor);
                BasicHttpBinding     binding  = new BasicHttpBinding();
                ServiceSMSSoapClient srv      = new ServiceSMSSoapClient(binding, endereco);

                List <Destination> list = new List <Destination>();

                list.Add(new Destination()
                {
                    Name   = NomeDestinatario,
                    Number = TelefoneDestinatario
                             .Replace(" ", "")
                             .Replace("-", "")
                             .Replace("(", "")
                             .Replace(")", "")
                });

                rSMS sms = new rSMS();

                sms.Destinations = list.ToArray();
                sms.Flash        = false;
                sms.Msg          = Corpo;
                sms.Preso        = false;
                sms.Subject      = Assunto;
                sms.WarningBeginningTransmission = false;


                result = srv.SendSMS(Usuario, Senha, sms);
            }
            catch (Exception err)
            {
                result = err.ToString();
            }

            return(result);
        }