Пример #1
0
 public override void OnPageLoad(object sender, EventArgs e)
 {
     facade           = new SMSFacade(this);
     this.DataContext = viewModel;
     base.OnPageLoad(sender, e);
     if (!AuthMgr.HasFunctionPoint(AuthKeyConst.Customer_SMS_SendSMS))
     {
         this.btnSendSMS.IsEnabled = false;
     }
     SearchBuilder.KeyDown += new KeyEventHandler(SearchBuilder_KeyDown);
 }
Пример #2
0
    public static TraceEntity Send(SMSEntity entity)
    {
        TraceEntity result = new TraceEntity();

        try
        {
            result = new SMSFacade().Send(entity);
            if (string.IsNullOrEmpty(result.ErrorMsg))
            {
                Case.SetSMS(entity.CaseNo);
            }
        }
        catch (Exception ee)
        {
            Common.LogIt(ee.ToString());
            result.ErrorMsg = ee.Message;
        }

        return(result);
    }
Пример #3
0
        /// <summary>
        /// 发送邮件请求到MQ
        /// </summary>
        /// <param name="eRequest"></param>
        /// <returns></returns>
        public SMSResponse SendSMS(SMSRequest eRequest)
        {
            if (!CheckParas(eRequest))
            {
                return(_eResponse);
            }
            var smsId     = Guid.NewGuid().ToString("N");
            var smsFacade = new SMSFacade();

            try
            {
                while (smsFacade.IsSMSIdExist(smsId))
                {
                    smsId = Guid.NewGuid().ToString("N");
                }
            }
            catch (Exception ex)
            {
                loger.Error("数据库查询SMSId是否存在失败--SMSId:{0}--Exception:{1}".FormatWith(new object[] { smsId, ex }));
            }
            var smsDto = ConverToCommonDTO(smsId, eRequest);

            _eResponse.Success = true;
            _eResponse.SMSId   = smsId;
            _eResponse.ErrMsg  = "";

            loger.Info("开始转发--SMSId:{0}".FormatWith(smsId));
            var bus = MqBusMgr.GetInstance();

            if (!bus.IsConnected || bus.IsNull())
            {
                _eResponse.Success = false;
                _eResponse.ErrMsg  = "无法连接RabbitMQ";
                loger.Error("无法连接RabbitMQ--SMSId:{0}".FormatWith(smsId));
            }
            try
            {
                bus.PublishAsync(smsDto).ContinueWith(task =>
                {
                    if (!(task.IsCompleted && !task.IsFaulted))
                    {
                        _eResponse.Success = false;
                        _eResponse.ErrMsg  = string.Format("发送RabbitMQ失败");
                        loger.Error("发送RabbitMQ失败--SMSId:{0}--Exception:{1}".FormatWith(new object[] { smsId, task.Exception }));
                    }
                }).Wait();
            }
            catch (Exception ex)
            {
                _eResponse.Success = false;
                _eResponse.ErrMsg  = string.Format("发送RabbitMQ失败");
                loger.Error("发送RabbitMQ失败--SMSId:{0}--Exception:{1}".FormatWith(new object[] { smsId, ex }));
            }
            //保存数据库
            var sms = new SMS
            {
                SMSId           = smsDto.Id,
                AppId           = smsDto.AppId,
                SMSContent      = smsDto.Content,
                SMSErrMsg       = _eResponse.ErrMsg,
                SMSMobile       = smsDto.Mobile,
                SMSReceivedTime = DateTime.Now,
                SMSSentTime     = DateTime.Now,
                SMSStatus       = SMSStatus.Received.ToString()
            };

            try
            {
                smsFacade.AddSMS(sms);
            }
            catch (Exception ex)
            {
                loger.Error("数据库增加SMS记录失败--SMSId:{0}--Exception:{1}".FormatWith(new object[] { smsId, ex }));
            }
            loger.Info("结束转发--SMSId:{0}--结果:{1}".FormatWith(new object[] { smsId, _eResponse.Success }));
            return(_eResponse);
        }
Пример #4
0
        /// <summary>
        /// 依据SMSDTO对象内容发送短信
        /// </summary>
        /// <param name="smsDto">SMSDTO对象</param>
        private void SendSMS(SMSDTO smsDto)
        {
            var smsId = smsDto.Id;

            loger.Info("开始发送--SMSId:{0}".FormatWith(smsId));
            var sms = new SMS
            {
                SMSId           = smsDto.Id,
                AppId           = smsDto.AppId,
                SMSContent      = smsDto.Content,
                SMSErrMsg       = "",
                SMSMobile       = smsDto.Mobile,
                SMSReceivedTime = DateTime.Now,
                SMSSentTime     = DateTime.Now,
                SMSStatus       = SMSStatus.Received.ToString()
            };
            var smsFacade = new SMSFacade();
            //发送短信
            bool   result  = false;
            string mobile  = smsDto.Mobile;
            string content = smsDto.Content;

            //申讯短信内容需加签名
            if (ConfigMgr.SmsChannel == 2)
            {
                if (smsDto.AppId == "100204")//OEM项目,负责人:张业华
                {
                    content += "【登机宝】";
                }
                else
                {
                    content += "【今日天下通】";
                }
            }

            var sender = SMSSenderFactory.CreateSender(ConfigMgr.SmsChannel);

            try
            {
                result = sender.SendSMS(mobile, content);
            }
            catch (Exception ex)
            {
                sms.SMSErrMsg = ex.Message;
                loger.Error("短信发送异常--SMSId:{0}--Exception:{1}".FormatWith(new object[] { smsId, ex }));
            }
            if (result)
            {
                sms.SMSErrMsg = "";
            }
            //保存数据库
            sms.SMSStatus   = result ? SMSStatus.Sent.ToString() : SMSStatus.Fail.ToString();
            sms.SMSSentTime = DateTime.Now;
            try
            {
                smsFacade.UpdateSMS(sms);
            }
            catch (Exception ex)
            {
                loger.Error("数据库更新SMS记录失败--SMSId:{0}--Exception:{1}".FormatWith(new object[] { smsId, ex }));
            }
            loger.Info("结束发送--SMSId:{0}--发送结果{1}".FormatWith(new object[] { smsId, result? "成功":"失败" }));
        }