public static void SendSMS(TickerSMSSettings ticker)
        {
            //StringBuilder postData = new StringBuilder("");
            //curl "https://platform.clickatell.com/messages/http/send?apiKey=gKDqcnrjTPe4sNiB88_pAA==&to=19143343722&content=Test+message+text"
            // curl - X POST https://rest.messagebird.com/messages -H 'Authorization: AccessKey HIDDEN_API_KEY'
            // -d "recipients=TO"
            // -d "originator=FROM"
            // -d "body=BODY"


            Client client = Client.CreateDefault(Properties.Settings.Default.SMSKeyValue);
            long   Msisdn;

            Int64.TryParse(ticker.Mobile, out Msisdn);

            MessageBird.Objects.Message message =
                client.SendMessage("MessageBird", ticker.TickerName + " - " + ticker.Current + " - Tresholds high: " + ticker.High + " low: " + ticker.Low, new[] { Msisdn });

            //// Create a request using a URL that can receive a post.
            //WebRequest request = WebRequest.Create(Properties.Settings.Default.SMSUrl);
            //// Set the Method property of the request to POST.
            //request.Method = "POST";

            //// Create POST data and convert it to a byte array.
            ////postData.AppendFormat(@"{""content"":""Ticker: {0}, current: {1}, high: {2}, low: {3}"", ""to"":[""{4}""]}",
            ////    ticker.TickerName, ticker.Current.ToString(), ticker.High.ToString(), ticker.Low.ToString(), "19143343722");

            //postData.Append(@"{""content"":""Ticker: 0, current: , high: 1 , low: 2"", ""to"":[""19143343722""]}");
            //// ticker.TickerName);//, ticker.Current.ToString(), ticker.High.ToString(), ticker.Low.ToString(), "19143343722");


            //byte[] byteArray = Encoding.UTF8.GetBytes(postData.ToString());

            //// Set the ContentType property of the WebRequest.
            //request.ContentType = "application/json";
            //request.Headers.Add("Authorization", "Bearer " + Properties.Settings.Default.SMSKeyValue);

            //// Set the ContentLength property of the WebRequest.
            //request.ContentLength = byteArray.Length;

            //// Get the request stream.
            //Stream dataStream = request.GetRequestStream();
            //// Write the data to the request stream.
            //dataStream.Write(byteArray, 0, byteArray.Length);
            //// Close the Stream object.
            //dataStream.Close();

            //// Get the response.
            //WebResponse response = request.GetResponse();

            //// Close the response.
            //response.Close();

            //ticker.Mobile = "";
        }
Beispiel #2
0
        public static void SendSMS(ref TickerSMSSettings _ticker)
        {
            StringBuilder postData = new StringBuilder("");
            //            curl - i \
            //-X POST \
            //-H "Content-Type: application/json" \
            //-H "Accept: application/json" \
            //-H "Authorization: Y3HSdmWsR--d4kvmDv2EOA==" \
            //-d '{"content": "blah blah", "to": ["19143343722"]}' \
            //-s https://platform.clickatell.com/messages


            // Create a request using a URL that can receive a post.
            WebRequest request = WebRequest.Create(ConfigurationManager.AppSettings["SMS:Url"]);

            // Set the Method property of the request to POST.
            request.Method = "POST";

            // Create POST data and convert it to a byte array.
            //postData.AppendFormat(@"{""content"":""Ticker: {0}, current: {1}, high: {2}, low: {3}"", ""to"":[""{4}""]}",
            //    _ticker.TickerName, _ticker.Current.ToString(), _ticker.High.ToString(), _ticker.Low.ToString(), "19143343722");

            postData.Append(@"{""content"":""Ticker: 0, current: , high: 1 , low: 2"", ""to"":[""19143343722""]}");
            // _ticker.TickerName);//, _ticker.Current.ToString(), _ticker.High.ToString(), _ticker.Low.ToString(), "19143343722");


            byte[] byteArray = Encoding.UTF8.GetBytes(postData.ToString());

            // Set the ContentType property of the WebRequest.
            request.ContentType = "application/json";
            request.Headers.Add("Authorization", "Bearer " + ConfigurationManager.AppSettings["SMS:Token"]);

            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;

            // Get the request stream.
            Stream dataStream = request.GetRequestStream();

            // Write the data to the request stream.
            dataStream.Write(byteArray, 0, byteArray.Length);
            // Close the Stream object.
            dataStream.Close();

            // Get the response.
            WebResponse response = request.GetResponse();

            // Close the response.
            response.Close();

            _ticker.Mobile = "";
        }
        public void AddUpdateTickerSMSSettings(TickerSMSSettings ticker)
        {
            var tickerSMSSettings = _db.TickerSMSSettings.SingleOrDefault(
                c => c.Mobile == ticker.Mobile);

            if (tickerSMSSettings == null)
            {
                _db.TickerSMSSettings.Add(ticker);
            }
            else
            {
                tickerSMSSettings.TickerName = ticker.TickerName;
                tickerSMSSettings.High       = ticker.High;
                tickerSMSSettings.Low        = ticker.Low;
                tickerSMSSettings.TickerDate = ticker.TickerDate;
            }
            _db.SaveChanges();
        }
        public static void SendSMS(TwilioConf twilioConfig, TickerSMSSettings ticker, Decimal current)
        {
            try
            {
                TwilioClient.Init(twilioConfig.Account, twilioConfig.Token);

                var message = MessageResource.Create(
                    body: ticker.TickerName + " - " + current + " - Thresholds high: " + ticker.High + " low: " + ticker.Low,
                    from: new Twilio.Types.PhoneNumber(twilioConfig.From),
                    to: new Twilio.Types.PhoneNumber(ticker.Mobile)
                    );

                Console.WriteLine(message.Sid);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }