コード例 #1
0
ファイル: SmsSender.cs プロジェクト: openzones/OMI
        public static string SendOneSms(SMSMessage sms)
        {
            if (!string.IsNullOrEmpty(sms.SenderId))
            {
                sms.SenderId.Trim();
            }

            SmsMessage input = new SmsMessage()
            {
                MessageId = sms.Id,
                SenderId  = sms.SenderId,
                Phone     = sms.Phone,
                Message   = sms.Message
            };

            SmsSendingResult result = new SmsSendingResult();

            using (EasySmsServiceClient client = new EasySmsServiceClient())
            {
                client.Open();
                result = client.SendMessage(input);
                client.Close();
            }
            return(result.ErrorMessage);
        }
コード例 #2
0
ファイル: SmsSender.cs プロジェクト: openzones/OMI
        public static List <SmsResult> Send(List <SMSMessage> list)
        {
            List <SmsMessage> items = new List <SmsMessage>();

            foreach (var sms in list)
            {
                SmsMessage item = new SmsMessage();
                item.MessageId = sms.Id;
                if (string.IsNullOrEmpty(sms.SenderId))
                {
                    item.SenderId = string.Empty;
                }
                else
                {
                    item.SenderId = sms.SenderId.Trim();
                }

                if (string.IsNullOrEmpty(sms.Phone))
                {
                    item.Phone = string.Empty;
                }
                else
                {
                    item.Phone = ClearPhone(sms.Phone);
                }

                if (string.IsNullOrEmpty(sms.Message))
                {
                    item.Message = string.Empty;
                }
                else
                {
                    item.Message = sms.Message.Trim();
                }
                items.Add(item);
            }

            if (items.Count == 0)
            {
                return(null);
            }

            List <SmsSendingResult> resultService = new List <SmsSendingResult>();

            using (EasySmsServiceClient client = new EasySmsServiceClient())
            {
                client.Open();
                resultService.AddRange(client.SendMessages(items));
                client.Close();
            }
            List <SmsResult> results = new List <SmsResult>();

            foreach (var sms in resultService)
            {
                results.Add(new SmsResult()
                {
                    Id                 = sms.MessageId,
                    StatusIdInside     = 1, //смс было отправлено
                    StatusFromService  = sms.ErrorCode,
                    MessageFromService = sms.ErrorMessage,
                    SendDate           = DateTime.Now,
                    IsSuccess          = sms.IsSuccess
                });
            }

            //WriteFileItems(items);
            //WriteFileResult(resultService);
            //results = Stab(items);
            return(results);
        }