Exemplo n.º 1
0
        public void Run()
        {
            EyouSoft.Toolkit.Utils.WLog("短信中心发送短信后台服务开启", "/log/service.sms.smscenter.log");
            try
            {
                //获取要发送的短信集合
                if (_queue == null || _queue.Count == 0)
                {
                    _queue = _dal.GetSends(SmsUtils.GetSmsCenterTopNum());
                }

                //发送短信
                if (_queue != null && _queue.Count > 0)
                {
                    EyouSoft.Toolkit.Utils.WLog(string.Format("短信中心后台服务读取到{0}条短信需要发送", _queue.Count), "/log/service.sms.smscenter.log");
                    while (true)
                    {
                        if (_queue.Count == 0)
                        {
                            break;
                        }
                        var info = _queue.Dequeue();
                        SendSms(info);
                    }
                }
            }
            catch (Exception e)
            {
                EyouSoft.Toolkit.Utils.WLog(e.Message + e.Source + e.StackTrace, "/log/service.smscenter.exception.log");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 发送出团提醒短信
        /// </summary>
        /// <param name="model">出回团提醒短信任务实体</param>
        /// <param name="message">短信内容(未替换)</param>
        private void SendMessage(MSmsTourTimePlan model, string message)
        {
            if (model == null || string.IsNullOrEmpty(model.CompanyId) || model.Traveller == null ||
                model.Traveller.Count < 1 || string.IsNullOrEmpty(message))
            {
                return;
            }

            string smscontent = message.Replace("[线路名称]", model.RouteName).Replace("[出团时间]", model.LeaveTime.ToString("yyyy-MM-dd")).Replace("[集合方式]", model.Gather).Replace("[本团导游]", model.DaoYouName).Replace("[导游电话]", model.DaoYouTelephone);

            foreach (var t in model.Traveller)
            {
                var sendMessage = new EyouSoft.BackgroundServices.SmsApi.MSendMessage
                {
                    CompanyId = model.CompanyId,
                    Mobiles   =
                        new[] { new EyouSoft.BackgroundServices.SmsApi.MSmsNumber {
                                    Code = t.Code
                                } },
                    SendChannel  = 0,
                    SendTime     = DateTime.Now,
                    SendType     = SendType.直接发送,
                    SmsContent   = smscontent.Replace("[游客姓名]", t.Traveller),
                    UserFullName = string.Empty,                      //直接包含在内容中
                    UserId       = model.SellerId
                };

                SmsUtils.GetSmsApi().SendMessage(sendMessage);
            }
        }
Exemplo n.º 3
0
        public void Run()
        {
            SmsUtils.WLog("短信中心定时短信后台服务开启\r\n", "Config/BackgroundServicesLog.txt");

            try
            {
                //获取要发送的短信集合
                if (this._queue == null || this._queue.Count == 0)
                {
                    this._queue = this.dal.GetSends();
                }

                //发送短信
                if (this._queue != null && this._queue.Count > 0)
                {
                    SmsUtils.WLog(string.Format("短信中心定时短信后台服务发送短信记录数:{0}", this._queue.Count), "Config/BackgroundServicesLog.txt");
                    while (true)
                    {
                        if (this._queue.Count == 0)
                        {
                            break;
                        }
                        var info = this._queue.Dequeue();
                        this.SendSMS(info);
                    }
                }
            }
            catch { }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 发送固定时间(指定的时间值)短信
        /// </summary>
        private void SendFixedTimeMessage()
        {
            IList <EyouSoft.Model.CompanyStructure.CustomerCareforSendInfo> items = dal.GetTimeSend(DateTime.Now);

            if (items != null && items.Count > 0)
            {
                SmsUtils.WLog(string.Format("客户关怀后台服务发送固定时间(指定的时间值)短信记录数:{0}", items.Count), "Config/BackgroundServicesLog.txt");
                foreach (var item in items)
                {
                    this.SendMessage(item);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="info">计划信息</param>
        private void SendSms(Model.BackgroundServices.MSmsCenterService info)
        {
            if (info == null || string.IsNullOrEmpty(info.Content) || info.Number == null || info.Number.Count < 1)
            {
                return;
            }

            //每次调用发送接口时待发送的手机号码
            var waitMobiles = new StringBuilder();
            //总的要发送的手机号码个数
            int waitMobileLength = info.Number.Count;

            for (int indexC = 0; indexC < waitMobileLength; indexC++)
            {
                waitMobiles.AppendFormat("{0},", info.Number[indexC].Code);

                #region 判断是否开始发送短信

                //号码数量达到100或者循环完全部的号码时发送短信
                if ((indexC + 1) % WaitCanMobilesMax == 0 || (indexC + 1) == waitMobileLength)
                {
                    int sendResult = 0;
                    //string sendMsg = "";
                    try
                    {
                        _sms.Timeout = 1000;
                        Model.BackgroundServices.MSmsChannel smsChannel = SmsUtils.GetSmsChannelByChannel(info.Channel);
                        //发送结果返回值 返回int类型的0时成功 返回对应的负数时失败
                        sendResult = _sms.SendSms(_enterpriseId, waitMobiles.ToString().TrimEnd(','), info.Content,
                                                  smsChannel.UserName, smsChannel.Pw);
                        //sendMsg = GetServicesState(sendResult);
                    }
                    catch
                    {
                        //sendMsg = "超时";
                        sendResult = SendTimeOutEventCode;
                    }

                    //发送失败记录发送失败的号码
                    if (sendResult != 0)
                    {
                        _dal.AddSmsPlanLose(info.PlanId, sendResult, waitMobiles.ToString().TrimEnd(','));
                    }

                    //要发送的号码清空
                    waitMobiles.Remove(0, waitMobiles.Length);
                }

                #endregion 判断是否开始发送短信
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="info">计划信息</param>
        private void SendSMS(EyouSoft.Model.SMSStructure.SendPlanInfo info)
        {
            EyouSoft.BackgroundServices.SMSSOAP.SMSChannel channel = SmsUtils.GetSmsSendChannel(info.SendChannel.Index);

            EyouSoft.BackgroundServices.SMSSOAP.SendMessageInfo    messageInfo = new EyouSoft.BackgroundServices.SMSSOAP.SendMessageInfo();
            EyouSoft.BackgroundServices.SMSSOAP.AcceptMobileInfo[] mobiles     = new EyouSoft.BackgroundServices.SMSSOAP.AcceptMobileInfo[info.Mobiles.Count];
            for (int i = 0; i < info.Mobiles.Count; i++)
            {
                mobiles[i]           = new EyouSoft.BackgroundServices.SMSSOAP.AcceptMobileInfo();
                mobiles[i].Mobile    = info.Mobiles[i].Mobile;
                mobiles[i].IsEncrypt = info.Mobiles[i].IsEncrypt;
            }
            messageInfo.Mobiles      = mobiles;
            messageInfo.CompanyId    = info.CompanyId;
            messageInfo.CompanyName  = info.CompanyName;
            messageInfo.SendChannel  = channel;
            messageInfo.SendTime     = info.SendTime;
            messageInfo.SendType     = EyouSoft.BackgroundServices.SMSSOAP.SendType.直接发送;
            messageInfo.SMSContent   = info.SMSContent;
            messageInfo.SMSType      = info.SMSType;
            messageInfo.UserFullName = info.ContactName;
            messageInfo.UserId       = info.UserId;

            EyouSoft.BackgroundServices.SMSSOAP.SMSAPI api = EyouSoft.Services.BackgroundServices.SmsUtils.GetSmsApi();

            EyouSoft.BackgroundServices.SMSSOAP.SendResultInfo result = api.Send(messageInfo);

            /*
             * EyouSoft.Model.EnumType.SmsStructure.PlanStatus state = EyouSoft.Model.EnumType.SmsStructure.PlanStatus.未发送;
             * string stateDesc = string.Empty;
             *
             * if (result.IsSucceed)
             * {
             *  state = EyouSoft.Model.EnumType.SmsStructure.PlanStatus.发送成功;
             * }
             * else
             * {
             *  state = EyouSoft.Model.EnumType.SmsStructure.PlanStatus.发送失败;
             *  stateDesc = result.ErrorMessage;
             * }
             *
             * dal.SaveSendResult(info.PlanId, state, stateDesc);*/
        }
Exemplo n.º 8
0
        /// <summary>
        /// 发送生日提醒短信
        /// </summary>
        /// <param name="model">生日提醒短信配置实体</param>
        private void SendSms(MSmsSetting model)
        {
            if (model == null || string.IsNullOrEmpty(model.CompanyId))
            {
                return;
            }

            var list = _dal.GetSmsBirthdayRemindPlan(model.CompanyId, model.BeforeDay);

            if (list == null || list.Count < 1)
            {
                return;
            }

            EyouSoft.Toolkit.Utils.WLog(string.Format("系统{0}发送{1}条生日提醒短信", model.CompanyId, list.Count), "/log/service.sms.birthday.log");

            foreach (var t in list)
            {
                if (t == null || string.IsNullOrEmpty(t.CompanyId) || string.IsNullOrEmpty(t.MobilePhone))
                {
                    continue;
                }

                var sendMessage = new EyouSoft.BackgroundServices.SmsApi.MSendMessage
                {
                    CompanyId = t.CompanyId,
                    Mobiles   =
                        new[] { new EyouSoft.BackgroundServices.SmsApi.MSmsNumber {
                                    Code = t.MobilePhone
                                } },
                    SendChannel  = 0,
                    SendTime     = DateTime.Now,
                    SendType     = EyouSoft.BackgroundServices.SmsApi.SendType.直接发送,
                    SmsContent   = model.Message.Replace("[姓名]", t.Name).Replace("[生日]", t.Birthday.ToString("MM-dd")),
                    UserFullName = string.Empty,//直接包含在内容中
                    UserId       = model.OperatorId
                };

                SmsUtils.GetSmsApi().SendMessage(sendMessage);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 发送节假日及生日短信
        /// </summary>
        private void SendHolidaysMessage()
        {
            DateTime now = DateTime.Now;
            //客户关怀固定节假日及生日短信发送时间(点时间)验证
            int caringSmsSendHours = Utils.GetInt(Toolkit.ConfigHelper.ConfigClass.GetConfigString("CaringSmsSendHours"), 9);

            if (now.Hour != caringSmsSendHours)
            {
                return;
            }

            IList <EyouSoft.Model.CompanyStructure.CustomerCareforSendInfo> items = dal.GetFixTypeSend(this.GetSpecialTimeTypes());

            if (items != null && items.Count > 0)
            {
                SmsUtils.WLog(string.Format("客户关怀后台服务发送节假日及生日短信记录数:{0}", items.Count), "Config/BackgroundServicesLog.txt");
                foreach (var item in items)
                {
                    this.SendMessage(item);
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="info"></param>
        private void SendMessage(EyouSoft.Model.CompanyStructure.CustomerCareforSendInfo info)
        {
            if (info == null)
            {
                return;
            }
            if (string.IsNullOrEmpty(info.MobileCode) && (info.NameAndMobile == null || info.NameAndMobile.Count < 1))
            {
                return;
            }

            EyouSoft.BackgroundServices.SMSSOAP.SMSChannel channel = SmsUtils.GetSmsSendChannel(info.ChannelId);

            #region 输入号码
            if (!string.IsNullOrEmpty(info.MobileCode))//输入号码
            {
                EyouSoft.BackgroundServices.SMSSOAP.SendMessageInfo messageInfo = new EyouSoft.BackgroundServices.SMSSOAP.SendMessageInfo();
                string[] mobileArr = info.MobileCode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                EyouSoft.BackgroundServices.SMSSOAP.AcceptMobileInfo[] mobiles = new EyouSoft.BackgroundServices.SMSSOAP.AcceptMobileInfo[mobileArr.Length];
                for (int i = 0; i < mobileArr.Length; i++)
                {
                    mobiles[i]           = new EyouSoft.BackgroundServices.SMSSOAP.AcceptMobileInfo();
                    mobiles[i].Mobile    = mobileArr[i];
                    mobiles[i].IsEncrypt = false;
                }

                SmsUtils.WLog(string.Format("客户关怀后台服务发送固定时间(指定的时间值)将要发送短信条数:{0}", mobiles.Length), "Config/BackgroundServicesLog.txt");

                messageInfo.Mobiles      = mobiles;
                messageInfo.CompanyId    = info.CompanyId;
                messageInfo.CompanyName  = "";
                messageInfo.SendChannel  = channel;
                messageInfo.SendTime     = DateTime.Now;
                messageInfo.SendType     = EyouSoft.BackgroundServices.SMSSOAP.SendType.直接发送;
                messageInfo.SMSContent   = info.Content;
                messageInfo.SMSType      = 0;
                messageInfo.UserFullName = "";
                messageInfo.UserId       = info.OperatorId;

                EyouSoft.BackgroundServices.SMSSOAP.SMSAPI api = EyouSoft.Services.BackgroundServices.SmsUtils.GetSmsApi();

                EyouSoft.BackgroundServices.SMSSOAP.SendResultInfo result = api.Send(messageInfo);
            }
            #endregion

            #region 匹配号码
            if (info.NameAndMobile != null && info.NameAndMobile.Count > 0)//匹配号码
            {
                SmsUtils.WLog(string.Format("客户关怀后台服务发送节假日及生日短信将要发送短信条数:{0}", info.NameAndMobile.Count), "Config/BackgroundServicesLog.txt");
                foreach (var nameAndMobile in info.NameAndMobile)
                {
                    if (string.IsNullOrEmpty(nameAndMobile.ContactMobile))
                    {
                        continue;
                    }

                    EyouSoft.BackgroundServices.SMSSOAP.SendMessageInfo    messageInfo = new EyouSoft.BackgroundServices.SMSSOAP.SendMessageInfo();
                    EyouSoft.BackgroundServices.SMSSOAP.AcceptMobileInfo[] mobiles     = new EyouSoft.BackgroundServices.SMSSOAP.AcceptMobileInfo[1];
                    mobiles[0]           = new EyouSoft.BackgroundServices.SMSSOAP.AcceptMobileInfo();
                    mobiles[0].Mobile    = nameAndMobile.ContactMobile;
                    mobiles[0].IsEncrypt = false;

                    messageInfo.Mobiles      = mobiles;
                    messageInfo.CompanyId    = info.CompanyId;
                    messageInfo.CompanyName  = "";
                    messageInfo.SendChannel  = channel;
                    messageInfo.SendTime     = DateTime.Now;
                    messageInfo.SendType     = EyouSoft.BackgroundServices.SMSSOAP.SendType.直接发送;
                    messageInfo.SMSContent   = info.Content.Replace("[姓名]", nameAndMobile.ContactName);
                    messageInfo.SMSType      = 0;
                    messageInfo.UserFullName = "";
                    messageInfo.UserId       = info.OperatorId;

                    EyouSoft.BackgroundServices.SMSSOAP.SMSAPI api = EyouSoft.Services.BackgroundServices.SmsUtils.GetSmsApi();

                    EyouSoft.BackgroundServices.SMSSOAP.SendResultInfo result = api.Send(messageInfo);
                }
            }
            #endregion
        }
Exemplo n.º 11
0
 public void Run()
 {
     SmsUtils.WLog("客户关怀后台服务开启\r\n", "Config/BackgroundServicesLog.txt");
     this.SendFixedTimeMessage();
     this.SendHolidaysMessage();
 }