예제 #1
0
        public string SendMessage(String mobile, String msg)
        {
            string ReturnMessage = "";

            try
            {
                string url;
                // url = "http://sms.jajasms.com/submitsms.jsp?user=shreemkt&key=33aaa719e5XX&mobile=" + mobile + "&message=" + msg + "&senderid=SOLARX&accusage=1";

                url = "http://sms.versatilesmshub.com/api/mt/SendSMS?user=CSKInfotronix&password=CSK@123&senderid=SOLARX&channel=Trans&DCS=0&flashsms=0&number=9426666404,8320399766," + mobile + "&text=" + msg + "&route=1";
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.AutomaticDecompression = DecompressionMethods.GZip;
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                Stream       dataStream  = response.GetResponseStream();
                StreamReader reader      = new StreamReader(dataStream);
                string       strResponse = reader.ReadToEnd();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    using (BAL.MessageSendLog objBal = new MessageSendLog())
                    {
                        objBal.Entity.IsSent          = 1;
                        objBal.Entity.Mobile          = mobile;
                        objBal.Entity.Response        = strResponse;
                        objBal.Entity.CreatedDateTime = DateTime.Now;
                        objBal.Entity.SystemDateTime  = DateTime.Now;
                        objBal.Insert(objBal.Entity);
                    }
                    ReturnMessage = "Message sent Successfully";
                }
                else
                {
                    using (BAL.MessageSendLog objBal = new MessageSendLog())
                    {
                        objBal.Entity.IsSent          = 2;
                        objBal.Entity.Mobile          = mobile;
                        objBal.Entity.Response        = strResponse;
                        objBal.Entity.CreatedDateTime = DateTime.Now;
                        objBal.Entity.SystemDateTime  = DateTime.Now;
                        objBal.Insert(objBal.Entity);
                    }
                    throw new Exception("Unable to send message due to error: " + response.StatusDescription);
                }
            }
            catch (Exception _Exception)
            {
                using (BAL.MessageSendLog objBal = new MessageSendLog())
                {
                    objBal.Entity.IsSent          = 1;
                    objBal.Entity.Mobile          = mobile;
                    objBal.Entity.Response        = _Exception.Message;
                    objBal.Entity.CreatedDateTime = DateTime.Now;
                    objBal.Entity.SystemDateTime  = DateTime.Now;
                    objBal.Insert(objBal.Entity);
                }
                ReturnMessage = "Could not send the message - error: " + _Exception.Message;
            }
            return(ReturnMessage);
        }
예제 #2
0
        private string SendMessage(String mobile, String EP, String PlantName)
        {
            string ReturnMessage = "";

            try
            {
                string url;

                String msg = "Today's Total Production for Plant : " + PlantName + " is " + EP + " .";

                //url = "http://sms.versatilesmshub.com/api/mt/SendSMS?user=CSKInfotronix&password=CSK@123&senderid=SOLARX&channel=Trans&DCS=0&flashsms=0&number=9426666404," + mobile+"&text="+msg+"&route=1";

                url = "http://sms.versatilesmshub.com/api/mt/SendSMS?user=websmithoffice&password=Web@12345&senderid=WEBSMH&channel=Trans&DCS=0&flashsms=0&number=9426666404," + mobile + "&text=" + msg + "&route=4";

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.AutomaticDecompression = DecompressionMethods.GZip;
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                Stream       dataStream  = response.GetResponseStream();
                StreamReader reader      = new StreamReader(dataStream);
                string       strResponse = reader.ReadToEnd();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    using (BAL.MessageSendLog objBal = new MessageSendLog())
                    {
                        objBal.Entity.IsSent          = 1;
                        objBal.Entity.Mobile          = mobile;
                        objBal.Entity.Response        = strResponse;
                        objBal.Entity.CreatedDateTime = DateTime.Now;
                        objBal.Entity.SystemDateTime  = DateTime.Now;
                        objBal.Entity.CreatedBy       = Guid.Parse("00000000-0000-0000-0000-000000000000");
                        objBal.Insert(objBal.Entity);
                    }
                    ReturnMessage = "Message sent Successfully";
                }
                else
                {
                    using (BAL.MessageSendLog objBal = new MessageSendLog())
                    {
                        objBal.Entity.IsSent          = 1;
                        objBal.Entity.Mobile          = mobile;
                        objBal.Entity.Response        = strResponse;
                        objBal.Entity.CreatedDateTime = DateTime.Now;
                        objBal.Entity.SystemDateTime  = DateTime.Now;
                        objBal.Entity.CreatedBy       = Guid.Parse("00000000-0000-0000-0000-000000000000");
                        objBal.Insert(objBal.Entity);
                    }
                    throw new Exception("Unable to send message due to error: " + response.StatusDescription);
                }
            }
            catch (Exception _Exception)
            {
                ReturnMessage = "Could not send the message - error: " + _Exception.Message;

                using (BAL.MessageSendLog objBal = new MessageSendLog())
                {
                    objBal.Entity.IsSent   = 1;
                    objBal.Entity.Mobile   = mobile;
                    objBal.Entity.Response = _Exception.Message;
                    objBal.Insert(objBal.Entity);
                }
                throw new Exception("Unable to send message due to error: " + _Exception.Message);
            }
            return(ReturnMessage);
        }