コード例 #1
0
 public void SetStatus(SMSStatus status, int?errorCode = null, string errorMessage = null)
 {
     this.Attempts++;
     this.Status       = status;
     this.Error        = $"{errorCode}: {errorMessage}";
     this.ErrorCode    = errorCode != null ? (SMSErrorCode)errorCode : SMSErrorCode.None;
     this.ErrorMessage = errorMessage;
 }
コード例 #2
0
        public IEnumerable <SMSStatus> Send(int id)
        {
            var accountSid = "AC543bddcd8e90efaebd92577531c694d0";
            var authToken  = "bba190cb04207b30a04a1126bef1ed1d";

            TwilioClient.Init(accountSid, authToken);

            List <string> toList = new List <string>();

            toList.Add("+919971740711");
            toList.Add("+919971740711");
            toList.Add("+919810447915");
            toList.Add("+91xxxxxxxxxx");

            var to   = new PhoneNumber("+919971740711");
            var from = new PhoneNumber("+12244772941");

            List <SMSStatus> statusList = new List <SMSStatus>();


            foreach (string value in toList)
            {
                //Console.WriteLine(value);
                try
                {
                    var message = MessageResource.Create(
                        body: "Hi there! This is a test SMS using Twilio.",
                        from: from,
                        to: new PhoneNumber(value)
                        );

                    var status = new SMSStatus()
                    {
                        ToNumber = value, Status = message.Sid
                    };
                    statusList.Add(status);
                }
                catch (TwilioException e)
                {
                    var status = new SMSStatus()
                    {
                        ToNumber = value, Status = e.Message
                    };
                    statusList.Add(status);
                    //Console.WriteLine($"The file was not found: '{e}'");
                }
            }



            //Twilio.Exceptions.

            return(statusList);
        }
コード例 #3
0
        public static string GetStatus(this SMSStatus statusCode)
        {
            string result = "partly_deliver";

            switch (statusCode)
            {
            case SMSStatus.Cancelled:
                //return 'Сообщение отменено';
                result = "not_deliver";
                break;

            case SMSStatus.CancellationPending:
                //return 'Сообщение отменяется';
                result = "not_deliver";
                break;

            case SMSStatus.InQueue:
                //return 'Сообщение находится в очереди';
                result = "partly_deliver";
                break;

            case SMSStatus.Send:
                //return 'Сообщение отправлено';
                result = "partly_deliver";
                break;

            case SMSStatus.Delivered:
                //return 'Сообщение доставлено';
                result = "deliver";
                break;

            case SMSStatus.ValidationError:
                //return 'Ошибка валидации запроса';
                result = "not_deliver";
                break;

            case SMSStatus.SendError:
                //return 'Ошибка: сообщение отклонено СМС центром';
                result = "not_deliver";
                break;

            default:
                //return 'Статус не распознан';
                result = "not_deliver";
                break;
            }
            return(result);
        }
コード例 #4
0
        public ActionResult TextXStatus(string ID, string status, string receiver)
        {
            int TextID = 0;

            if (string.IsNullOrWhiteSpace(ID) || !int.TryParse(ID, out TextID))
            {
                new HttpStatusCodeResult(HttpStatusCode.OK);
            }
            int SendStatus = 0;

            if (string.IsNullOrWhiteSpace(status) || !int.TryParse(status, out SendStatus))
            {
                new HttpStatusCodeResult(HttpStatusCode.OK);
            }
            SMSStatus ST = (SMSStatus)SendStatus;

            reposetory.UpdateStatusMessage(TextID, ST);

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
コード例 #5
0
 private List<int> GetMessages(SMSStatus status)
 {
     List<int> result = new List<int>();
     try
         {
         string[] Messages;
         if ( Autorize() )
             {
             string answer = SendCommandAndReceiveAnswer("+cmgl", ( int ) status);
             Messages = answer.Split(new string[] { "\r\n+CMGL: " }, StringSplitOptions.RemoveEmptyEntries);
             for ( int i = 1; i < Messages.Length; i++ )
                 {
                 result.Add(Convert.ToInt32(Messages[i].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)[0]));
                 }
             }
         }
     catch ( Exception exp )
         {
         ErrorMessage = "Error: " + exp.Message;
         }
     return result;
 }
コード例 #6
0
ファイル: SMS.cs プロジェクト: sandalkuilang/texto
        /// <summary>
        /// Returns List Messages.
        /// </summary>
        /// <param name="status">Select status of the message</param> 
        public List<BaseResult<SMSReadResult>> Read(SMSStatus status)
        { 
            List<BaseResult<SMSReadResult>> listReads = new List<BaseResult<SMSReadResult>>();
            System.Diagnostics.Stopwatch sp = new System.Diagnostics.Stopwatch();

            BaseResult<GenericTypeResult<PhoneActivityStatus>> activityStatus = Connection.GetActivityStatus();
            if (activityStatus.Response.Result != PhoneActivityStatus.Ready)
            {
                return listReads;
            }

            SetMessageFormat(Connection.PDUMode);
            string readValue = "ALL";
            string response;
            Regex regexReadPattern;
            if (Connection.PDUMode)
            { 
                regexReadPattern = new Regex("\\+CMGL: (\\d+),(\\d+),(?:\"(.*[A-Z0-9-_ ].*)\")?,(\\d+)\\r(\\w+)");
                switch (status)
                {
                    case SMSStatus.ReceivedUnreadMessage:
                        readValue = "0";
                        break;
                    case SMSStatus.ReceivedReadMessage:
                        readValue = "1";
                        break;
                    case SMSStatus.StoredUnsentMessage:
                        readValue = "2";
                        break;
                    case SMSStatus.StoredSentMessage:
                        readValue = "3";
                        break;
                    case SMSStatus.AllMessages:
                        readValue = "4";
                        break;
                }
            }
            else
            {
                regexReadPattern = new Regex(@"\+CMGL: (\d+)," + (char)34 + "(.*[A-Z0-9-_ ].*)" + (char)34 + "," + (char)34 + "(.*[0-9-_ +].*)" + (char)34 + ",(?:\"(.*[A-Z0-9-_ ].*)\")?," + @"(.*[0-9-_ +/:].*)" + "\r([ 0-9A-Za-z#$%=@!{},`~&*()'<>?.:;_|^/+\t\r\n\\[\\]\"-]([^(CMGL)]+)*)");
                switch (status)
                {
                    case SMSStatus.ReceivedUnreadMessage:
                        readValue = "\"REC UNREAD\"";
                        break;
                    case SMSStatus.ReceivedReadMessage:
                        readValue = "\"REC READ\"";
                        break;
                    case SMSStatus.StoredUnsentMessage:
                        readValue = "\"STO UNSENT\"";
                        break;
                    case SMSStatus.StoredSentMessage:
                        readValue = "\"STO SENT\"";
                        break;
                    case SMSStatus.AllMessages:
                        readValue = "\"ALL\"";
                        break;
                }
            } 
            Connection.Connector.DiscardBuffer();

            sp.Start();
            response = Connection.Connector.Execute(Command.Set(Commands.CMGL, readValue));
            sp.Stop();

            int index = 1;
            BaseResult<SMSReadResult> smp; 
            for (Match match = regexReadPattern.Match(response); match.Success; match = match.NextMatch())
            {
                IncomingSmsPdu sms = IncomingSmsPdu.Decode(match.Groups[5].Value, true); 

                if (!string.IsNullOrEmpty(match.Groups[1].Value))
                {
                    index = int.Parse(match.Groups[1].Value);
                }
                SMSReadResult read = new SMSReadResult(index, 
                                                        ((GSMCommunication.PDUDecoder.SmsDeliverPdu)(sms)).OriginatingAddress,
                                                        ((GSMCommunication.PDUDecoder.SmsDeliverPdu)(sms)).UserDataText, 
                                                        ((GSMCommunication.PDUDecoder.SmsDeliverPdu)(sms)).SCTimestamp.ToDateTime(),
                                                        match.Groups[2].Value, 
                                                        Connection.Operator); 
                smp = new BaseResult<SMSReadResult>();
                smp.Response = read;
                smp.ExecutionTime = sp.Elapsed;
                listReads.Add(smp);
            }
            return listReads;
        }
コード例 #7
0
        private static List <SMSStatus> SendSMS(EnumtestbdType smsType, List <SMSRequest> smsList, SystemInformation sysInfo)
        {
            List <SMSStatus> smsResponses = new List <SMSStatus>();

            if (sysInfo.SMSServiceEnable == 0)
            {
                return(smsResponses);
            }

            StringBuilder SMS      = new StringBuilder();
            string        result   = string.Empty;
            string        MobileNo = string.Empty;
            string        BASE_URL = string.Empty;

            int Counter = 0, Length = 0;;

            HttpResponseMessage response;

            try
            {
                switch (smsType)
                {
                    #region One To One username and password
                case EnumtestbdType.OneToOne:
                    #region URL
                    //https://api2.testbd.com/HttpSendSms.ashx?op=OneToOne&type=TEXT&mobile=01738474602
                    //&smsText=Your Text&username=username&password=password&maskName=&campaignName=
                    #endregion
                    var SMSInfo = smsList.FirstOrDefault();

                    if (SMSInfo != null)
                    {
                        MobileNo = SMSInfo.MobileNo;
                        //SMS.Append(sysInfo.Name + Environment.NewLine);
                        if (SMSInfo.SMSType == EnumSMSType.CashCollection)
                        {
                            SMS.Append("Date: " + Global.DateddMMMYYYY(SMSInfo.Date) + Environment.NewLine);
                            SMS.Append("A/C No: " + SMSInfo.CustomerCode + Environment.NewLine);
                            SMS.Append("Pre. Due: " + SMSInfo.PreviousDue + Environment.NewLine);
                            SMS.Append("Receive Amt: " + SMSInfo.ReceiveAmount + Environment.NewLine);
                            SMS.Append("Present Due: " + SMSInfo.PresentDue + Environment.NewLine);
                        }
                        else if (SMSInfo.SMSType == EnumSMSType.SalesTime)
                        {
                            string ProductName = string.Join(",", SMSInfo.ProductNameList);
                            SMS.Append("Dear Sir," + Environment.NewLine + "you are welcome to buy a Honda Motorcycle," + Environment.NewLine);
                            SMS.Append("Date: " + Global.DateddMMMYYYY(SMSInfo.Date) + Environment.NewLine);
                            SMS.Append("A/C No: " + SMSInfo.CustomerCode + Environment.NewLine);
                            SMS.Append("Model: " + ProductName + Environment.NewLine);
                            SMS.Append("Price: " + SMSInfo.SalesAmount + Environment.NewLine);
                            //SMS.Append("Pre. Due: " + SMSInfo.PreviousDue + Environment.NewLine);
                            SMS.Append("Today Payment: " + SMSInfo.ReceiveAmount + Environment.NewLine);
                            SMS.Append("Present Due: " + SMSInfo.PresentDue + Environment.NewLine);
                            //SMS.Append("Paid Date: " + SMSInfo.PresentDue + Environment.NewLine);
                        }
                        else if (SMSInfo.SMSType == EnumSMSType.InstallmentCollection)
                        {
                            SMS.Append("Date: " + Global.DateddMMMYYYY(SMSInfo.Date) + Environment.NewLine);
                            SMS.Append("A/C No: " + SMSInfo.CustomerCode + Environment.NewLine);
                            SMS.Append("Installment: " + SMSInfo.ReceiveAmount + Environment.NewLine);
                            SMS.Append("Cash to Date: " + SMSInfo.TotalReceiveAmount + Environment.NewLine);
                            SMS.Append("Remaining: " + SMSInfo.PresentDue + Environment.NewLine);
                        }
                        else if (SMSInfo.SMSType == EnumSMSType.Registration)
                        {
                            MobileNo = sysInfo.InsuranceContactNo;
                            SMS.Append(SMSInfo.CustomerName + ", S/O ");
                            SMS.Append(SMSInfo.CustomerFatherName + ", ");
                            SMS.Append(SMSInfo.CustomerAddress + "." + Environment.NewLine);
                            string EngineNo = string.Empty;
                            string ChasisNo = string.Empty;
                            foreach (var item in SMSInfo.ProductDetailList)
                            {
                                EngineNo = item.EngineNo.Length >= 7 ? item.EngineNo.Substring(item.EngineNo.Length - 7) : item.EngineNo;    //Take Last 7 Digits
                                ChasisNo = item.ChasisNo.Length >= 6 ? item.ChasisNo.Substring(item.ChasisNo.Length - 6) : item.ChasisNo;    //Take Last 6 Digits
                                SMS.Append(item.ProductName + ", " + item.ColorName + ", EN-" + EngineNo + ", CH-" + ChasisNo + Environment.NewLine);
                            }
                        }
                        SMS.Append("Thank you." + Environment.NewLine + sysInfo.Name);
                    }


                    BASE_URL = new Uri(Global.TESTBD_BASE_URL + "op=" + smsType + "&type=TEXT").ToString();

                    response = new HttpClient().GetAsync(BASE_URL + "&mobile=" + MobileNo + "&smsText=" + SMS + "&username="******"&password="******"&maskName=&campaignName=").Result;
                    result   = response.Content.ReadAsStringAsync().Result;
                    //var obj = JObject.Parse(result);
                    #region response
                    //Success response: 1900||01762125041||100782732/
                    #endregion

                    if (result != null)
                    {
                        var smsResponse = new SMSStatus();
                        smsResponse.Code         = result.Substring(0, result.IndexOf("||"));
                        smsResponse.SMSFormateID = (int)SMSInfo.SMSType;
                        smsResponse.NoOfSMS      = SMSCounter(SMS.ToString());
                        smsResponse.ResponseMsg  = result;
                        smsResponse.SMS          = SMS.ToString();
                        smsResponse.CreatedDate  = DateTime.Now;
                        smsResponse.EntryDate    = DateTime.Today;
                        smsResponse.CreatedBy    = Global.CurrentUser.UserID;
                        smsResponse.CustomerID   = SMSInfo.CustomerID;
                        smsResponse.ContactNo    = MobileNo;
                        if (smsResponse.Code.Equals("1900"))
                        {
                            smsResponse.SendingStatus = (int)EnumSMSSendStatus.Success;
                        }
                        else
                        {
                            smsResponse.SendingStatus = (int)EnumSMSSendStatus.Fail;
                        }
                        smsResponses.Add(smsResponse);
                    }
                    break;
                    #endregion

                    #region One to Many API
                case EnumtestbdType.NumberSms:     //One to Many API
                    #region URL
                    // https://api2.testbd.com/HttpSendSms.ashx?op=NumberSms&apiKey=ApiKey&type=TEXT
                    //&mobile=01738474602, 01738474602&smsText=YourText&maskName=&campaignName=
                    #endregion
                    if (smsList.Count() == 0)
                    {
                        return(smsResponses);
                    }

                    foreach (var item in smsList)
                    {
                        Counter++;
                        if (smsList.Count != Counter)
                        {
                            MobileNo = MobileNo + item.MobileNo + ",";
                        }
                        else
                        {
                            MobileNo = MobileNo + item.MobileNo;
                        }
                    }
                    SMSInfo = smsList.FirstOrDefault();
                    SMS.Append(SMSInfo.SMS);
                    SMS.Append("Thank you." + Environment.NewLine + sysInfo.Name);

                    BASE_URL = new Uri(Global.TESTBD_BASE_URL + "op=" + smsType + "&apiKey=" + Global.TESTBD_APIKEY + "&type=TEXT").ToString();

                    response = new HttpClient().PostAsync(BASE_URL + "&mobile=" + MobileNo + "&smsText=" + SMS + "&maskName=&campaignName=", null).Result;
                    result   = response.Content.ReadAsStringAsync().Result;
                    //var obj = JObject.Parse(result);
                    //Response: 1900||01714||39.../1900||017...||39.../
                    if (result != null)
                    {
                        string[] IndividulsResponse = result.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                        for (int i = 0; i < IndividulsResponse.Length; i++)
                        {
                            var smsResponse = new SMSStatus();

                            smsResponse.Code = IndividulsResponse[i].Substring(0, IndividulsResponse[i].IndexOf("||"));
                            Length           = (IndividulsResponse[i].LastIndexOf("||") - IndividulsResponse[i].IndexOf("||")) - 2;
                            MobileNo         = IndividulsResponse[i].Substring(IndividulsResponse[i].IndexOf("||") + 2, Length);
                            SMSInfo          = smsList.FirstOrDefault(c => c.MobileNo.Contains(MobileNo.Trim()));

                            smsResponse.SMSFormateID = (int)SMSInfo.SMSType;
                            smsResponse.NoOfSMS      = SMSCounter(SMS.ToString());
                            smsResponse.ResponseMsg  = IndividulsResponse[i];
                            smsResponse.SMS          = SMS.ToString();
                            smsResponse.CreatedDate  = DateTime.Now;
                            smsResponse.EntryDate    = DateTime.Today;
                            smsResponse.CreatedBy    = Global.CurrentUser.UserID;
                            smsResponse.CustomerID   = SMSInfo.CustomerID;
                            smsResponse.ContactNo    = MobileNo;
                            if (smsResponse.Code.Equals("1900"))
                            {
                                smsResponse.SendingStatus = (int)EnumSMSSendStatus.Success;
                            }
                            else
                            {
                                smsResponse.SendingStatus = (int)EnumSMSSendStatus.Fail;
                            }
                            smsResponses.Add(smsResponse);
                        }
                    }
                    break;
                    #endregion

                    #region Many to Many API
                case EnumtestbdType.ListSms:     //Many to Many API
                    #region URL
                    //https://api2.testbd.com/HttpSendSms.ashx?op=ListSms&apiKey=ApiKey&type=TEXT
                    //&smsListJson=[{"MobileNumber":"01738474602","SmsText":"Individual List SMS is ok","Type":"TEXT"},{"MobileNumber":"0180000000","SmsText":"Individual List SMS2 is ok","Type":"TEXT"}]&maskName=&campaignName=
                    #endregion

                    if (smsList.Count == 0)
                    {
                        return(smsResponses);
                    }

                    var jsonList = from sms in smsList
                                   select new
                    {
                        MobileNumber = sms.MobileNo,
                        SmsText      = "Dear Mr./Mrs. " + sms.CustomerName + "," + Environment.NewLine + "your due payment Date is " + Global.DateddMMMYYYY(sms.Date) + " and due amout is " + sms.PresentDue + ". Thank you." + Environment.NewLine + sysInfo.Name,
                        Type         = "TEXT"
                    };

                    using (var output = new StringWriter())
                    {
                        JSON.SerializeDynamic(jsonList, output);
                        SMS.Append(output.ToString());
                    }

                    BASE_URL = new Uri(Global.TESTBD_BASE_URL + "op=" + smsType + "&apiKey=" + Global.TESTBD_APIKEY + "&type=TEXT").ToString();

                    response = new HttpClient().PostAsync(BASE_URL + "&smsListJson=" + SMS + "&maskName=&campaignName=", null).Result;
                    result   = response.Content.ReadAsStringAsync().Result;
                    Length   = 0;
                    if (result != null)
                    {
                        string[] IndividulsResponse = result.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                        for (int i = 0; i < IndividulsResponse.Length; i++)
                        {
                            var smsResponse = new SMSStatus();

                            smsResponse.Code = IndividulsResponse[i].Substring(0, IndividulsResponse[i].IndexOf("||"));

                            Length   = (IndividulsResponse[i].LastIndexOf("||") - IndividulsResponse[i].IndexOf("||")) - 2;
                            MobileNo = IndividulsResponse[i].Substring(IndividulsResponse[i].IndexOf("||") + 2, Length);

                            SMSInfo                  = smsList.FirstOrDefault(c => c.MobileNo.Contains(MobileNo.Trim()));
                            smsResponse.SMS          = jsonList.FirstOrDefault(c => c.MobileNumber.Contains(MobileNo.Trim())).SmsText;
                            smsResponse.SMSFormateID = (int)SMSInfo.SMSType;
                            smsResponse.NoOfSMS      = SMSCounter(smsResponse.SMS);
                            smsResponse.ResponseMsg  = IndividulsResponse[i];
                            smsResponse.CreatedDate  = DateTime.Now;
                            smsResponse.EntryDate    = DateTime.Today;
                            smsResponse.CreatedBy    = Global.CurrentUser.UserID;
                            smsResponse.CustomerID   = SMSInfo.CustomerID;
                            smsResponse.ContactNo    = MobileNo;
                            if (smsResponse.Code.Equals("1900"))
                            {
                                smsResponse.SendingStatus = (int)EnumSMSSendStatus.Success;
                            }
                            else
                            {
                                smsResponse.SendingStatus = (int)EnumSMSSendStatus.Fail;
                            }
                            smsResponses.Add(smsResponse);
                        }
                    }
                    break;
                    #endregion

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                var smsResponse = new SMSStatus();
                smsResponse.Code          = "0000";
                smsResponse.ResponseMsg   = ex.Message;
                smsResponse.SMSFormateID  = (int)EnumSMSType.Error;
                smsResponse.NoOfSMS       = 0;
                smsResponse.SMS           = SMS.ToString();
                smsResponse.CreatedDate   = DateTime.Now;
                smsResponse.EntryDate     = DateTime.Today;
                smsResponse.CreatedBy     = Global.CurrentUser.UserID;
                smsResponse.ContactNo     = MobileNo;
                smsResponse.CustomerID    = 0;
                smsResponse.SendingStatus = (int)EnumSMSSendStatus.Fail;
                smsResponses.Add(smsResponse);
                return(smsResponses);
            }

            return(smsResponses);
        }
コード例 #8
0
ファイル: SMSManager.cs プロジェクト: Tigrifer/PNEVMOTOOLS
 public static string GetStringStatus(SMSStatus status)
 {
     switch (status)
     {
       case SMSStatus.AUTH_FAILED:
     return "Не удалось авторизоваться в сервисе рассылки сообщений";
       case SMSStatus.NO_RECIPIENTS:
     return "Неправильно указан получатель";
       case SMSStatus.NOT_ENOUGH_CREDITS:
     return "Недостаточно средств для отправки сообщений";
       case SMSStatus.OK:
     return "Сообщение успешно отправлено.";
       case SMSStatus.XML_ERROR:
     return "Неверно сформирован запрос на сервер SMS.";
     }
     return "Сообщение успешно отправлено.";
 }
コード例 #9
0
ファイル: SMS.cs プロジェクト: sandalkuilang/texto
        /// <summary>
        /// Returns List Messages.
        /// </summary>
        /// <param name="status">Select status of the message</param>
        public List <BaseResult <SMSReadResult> > Read(SMSStatus status)
        {
            List <BaseResult <SMSReadResult> > listReads = new List <BaseResult <SMSReadResult> >();

            System.Diagnostics.Stopwatch sp = new System.Diagnostics.Stopwatch();

            BaseResult <GenericTypeResult <PhoneActivityStatus> > activityStatus = Connection.GetActivityStatus();

            if (activityStatus.Response.Result != PhoneActivityStatus.Ready)
            {
                return(listReads);
            }

            SetMessageFormat(Connection.PDUMode);
            string readValue = "ALL";
            string response;
            Regex  regexReadPattern;

            if (Connection.PDUMode)
            {
                regexReadPattern = new Regex("\\+CMGL: (\\d+),(\\d+),(?:\"(.*[A-Z0-9-_ ].*)\")?,(\\d+)\\r(\\w+)");
                switch (status)
                {
                case SMSStatus.ReceivedUnreadMessage:
                    readValue = "0";
                    break;

                case SMSStatus.ReceivedReadMessage:
                    readValue = "1";
                    break;

                case SMSStatus.StoredUnsentMessage:
                    readValue = "2";
                    break;

                case SMSStatus.StoredSentMessage:
                    readValue = "3";
                    break;

                case SMSStatus.AllMessages:
                    readValue = "4";
                    break;
                }
            }
            else
            {
                regexReadPattern = new Regex(@"\+CMGL: (\d+)," + (char)34 + "(.*[A-Z0-9-_ ].*)" + (char)34 + "," + (char)34 + "(.*[0-9-_ +].*)" + (char)34 + ",(?:\"(.*[A-Z0-9-_ ].*)\")?," + @"(.*[0-9-_ +/:].*)" + "\r([ 0-9A-Za-z#$%=@!{},`~&*()'<>?.:;_|^/+\t\r\n\\[\\]\"-]([^(CMGL)]+)*)");
                switch (status)
                {
                case SMSStatus.ReceivedUnreadMessage:
                    readValue = "\"REC UNREAD\"";
                    break;

                case SMSStatus.ReceivedReadMessage:
                    readValue = "\"REC READ\"";
                    break;

                case SMSStatus.StoredUnsentMessage:
                    readValue = "\"STO UNSENT\"";
                    break;

                case SMSStatus.StoredSentMessage:
                    readValue = "\"STO SENT\"";
                    break;

                case SMSStatus.AllMessages:
                    readValue = "\"ALL\"";
                    break;
                }
            }
            Connection.Connector.DiscardBuffer();

            sp.Start();
            response = Connection.Connector.Execute(Command.Set(Commands.CMGL, readValue));
            sp.Stop();

            int index = 1;
            BaseResult <SMSReadResult> smp;

            for (Match match = regexReadPattern.Match(response); match.Success; match = match.NextMatch())
            {
                IncomingSmsPdu sms = IncomingSmsPdu.Decode(match.Groups[5].Value, true);

                if (!string.IsNullOrEmpty(match.Groups[1].Value))
                {
                    index = int.Parse(match.Groups[1].Value);
                }
                SMSReadResult read = new SMSReadResult(index,
                                                       ((GSMCommunication.PDUDecoder.SmsDeliverPdu)(sms)).OriginatingAddress,
                                                       ((GSMCommunication.PDUDecoder.SmsDeliverPdu)(sms)).UserDataText,
                                                       ((GSMCommunication.PDUDecoder.SmsDeliverPdu)(sms)).SCTimestamp.ToDateTime(),
                                                       match.Groups[2].Value,
                                                       Connection.Operator);
                smp               = new BaseResult <SMSReadResult>();
                smp.Response      = read;
                smp.ExecutionTime = sp.Elapsed;
                listReads.Add(smp);
            }
            return(listReads);
        }
コード例 #10
0
ファイル: SMSDA.cs プロジェクト: jeanmahai/ProductComponents
 /// <summary>
 /// 更新短信状态
 /// </summary>
 /// <param name="sysNo">短信编号</param>
 /// <param name="status">状态</param>
 /// <param name="note">备注</param>
 public void UpdateSMSStatus(long sysNo, SMSStatus status, string note)
 {
     string sql = @"UPDATE [SohoEmailAndSMS].[dbo].[SMS]
                       SET [Status] = @Status,
                           [LastUpdateTime] = GETDATE(),
                           [Note] = ISNULL([Note], N'') + @Note
                       WHERE [SysNo] = @SysNo";
     SqlServerDBHelper db = new SqlServerDBHelper();
     try
     {
         SqlParameter[] para = new SqlParameter[]
         {
             new SqlParameter("@SysNo", sysNo),
             new SqlParameter("@Status", status),
             new SqlParameter("@Note", note)
         };
         db.ExecuteNonQuery(CommandType.Text, sql, para);
     }
     catch (Exception ex)
     {
         Logger.WriteException(ex.ToString());
     }
     finally
     {
         db.Dispose();
     }
 }
コード例 #11
0
 /// <summary>
 /// 更新短信状态
 /// </summary>
 /// <param name="sysNo">短信编号</param>
 /// <param name="status">状态</param>
 /// <param name="note">备注</param>
 public void UpdateSMSStatus(long sysNo, SMSStatus status, string note = "")
 {
     GetDAInstance.UpdateSMSStatus(sysNo, status, note);
 }