Exemple #1
0
        /// <summary>
        /// 添加定时发送的短信
        /// </summary>
        /// <param name="model">定时发送的短信实体</param>
        /// <returns>返回1成功;其他失败</returns>
        public int AddSmsTimerTask(Model.SmsStructure.MSmsTimerTask model)
        {
            if (model == null || string.IsNullOrEmpty(model.CompanyId) ||
                model.Number == null || string.IsNullOrEmpty(model.Content))
            {
                return(0);
            }

            return(_dal.AddSmsTimerTask(model));
        }
Exemple #2
0
        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="info">计划信息</param>
        private void SendSms(Model.SmsStructure.MSmsTimerTask info)
        {
            if (info == null || string.IsNullOrEmpty(info.CompanyId) || string.IsNullOrEmpty(info.Content) ||
                info.Number == null)
            {
                return;
            }

            var sendMessage = new EyouSoft.BackgroundServices.SmsApi.MSendMessage();
            var number      = new EyouSoft.BackgroundServices.SmsApi.MSmsNumber[info.Number.Count];

            for (int i = 0; i < info.Number.Count; i++)
            {
                if (info.Number[i] == null)
                {
                    continue;
                }
                number[i] = new EyouSoft.BackgroundServices.SmsApi.MSmsNumber
                {
                    Code = info.Number[i].Code,
                    Type =
                        (EyouSoft.BackgroundServices.SmsApi.MobileType)
                        Convert.ToInt32(info.Number[i].Type)
                };
            }
            sendMessage.CompanyId    = info.CompanyId;
            sendMessage.Mobiles      = number;
            sendMessage.SendChannel  = info.Channel;
            sendMessage.SendTime     = info.SendTime;
            sendMessage.SendType     = EyouSoft.BackgroundServices.SmsApi.SendType.直接发送;
            sendMessage.SmsContent   = info.Content;
            sendMessage.UserFullName = string.Empty;
            sendMessage.UserId       = info.OperatorId;

            EyouSoft.BackgroundServices.SmsApi.MSendResult result = SmsUtils.GetSmsApi().SendMessage(sendMessage);

            if (result.IsSucceed == false)
            {
                IList <Model.SmsStructure.MSmsTaskState> list = new List <Model.SmsStructure.MSmsTaskState>
                {
                    new Model.SmsStructure.MSmsTaskState
                    {
                        RealTime   = null,
                        Status     = SendStatus.发送失败,
                        StatusDesc = result.ErrorMessage,
                        TaskId     = info.TaskId
                    }
                };

                _dal.UpdateSmsTimerTaskState(list);
            }
        }
Exemple #3
0
        /// <summary>
        /// 定时发送
        /// </summary>
        /// <param name="sendMessage">发送短信实体</param>
        /// <returns></returns>
        private Model.SmsStructure.MSendResult TimeSend(Model.SmsStructure.MSendMessage sendMessage)
        {
            var sysModel = new Model.SmsStructure.MSendResult();

            if (sendMessage == null || sendMessage.SendTime <= DateTime.Now)
            {
                sysModel.IsSucceed    = false;
                sysModel.ErrorMessage = "没有构造发送短信实体";

                return(sysModel);
            }
            var smsPlan = new SmsCenter.MSmsPlan
            {
                Channel    = (SmsCenter.Channel)Convert.ToInt32(sendMessage.SendChannel),
                Content    = sendMessage.SmsContentSendComplete,
                IssueTime  = DateTime.Now,
                Number     = GetSmsNumber(sendMessage.Mobiles).ToArray(),
                PlanId     = string.Empty,
                SendAmount = 0,
                SmsAccount = GetSmsAccount(sendMessage.CompanyId),
                IsSend     = false,
                SendTime   = null,
                UnitPrice  = 0
            };

            SmsCenter.MSendResult smsModel = _smsCenter.ValidateSend(smsPlan);

            if (smsModel == null)
            {
                sysModel.IsSucceed    = false;
                sysModel.ErrorMessage = "未知错误";
                return(sysModel);
            }

            if (smsModel.IsSucceed)
            {
                var taskModel = new Model.SmsStructure.MSmsTimerTask
                {
                    Channel    = sendMessage.SendChannel,
                    CompanyId  = sendMessage.CompanyId,
                    Content    = sendMessage.SmsContentSendComplete,
                    IssueTime  = DateTime.Now,
                    Number     = sendMessage.Mobiles,
                    OperatorId = sendMessage.UserId,
                    RealTime   = null,
                    SendTime   = sendMessage.SendTime,
                    Status     = SendStatus.未发送,
                    StatusDesc = string.Empty,
                    TaskId     = string.Empty
                };

                _smsBll.AddSmsTimerTask(taskModel);
            }

            sysModel.AccountMoney      = smsModel.AccountMoney;
            sysModel.CountFee          = smsModel.CountFee;
            sysModel.ErrorMessage      = smsModel.ErrorMessage;
            sysModel.FactCount         = smsModel.FactCount;
            sysModel.IsSucceed         = smsModel.IsSucceed;
            sysModel.MobileNumberCount = smsModel.MobileNumberCount;
            sysModel.PhsFactCount      = smsModel.PhsFactCount;
            sysModel.PhsNumberCount    = smsModel.PhsNumberCount;
            sysModel.PhsSuccessCount   = smsModel.PhsSuccessCount;
            sysModel.SmsCenterPlanId   = smsModel.SmsCenterPlanId;
            sysModel.SuccessCount      = smsModel.SuccessCount;

            return(sysModel);
        }