Exemplo n.º 1
0
        public SmsSendModel GetSmsSendModel(ReceiveDataModel model)
        {
            var smsModel = new SmsSendModel();

            //短信发送两种逻辑,1、有报警则根据配置的时间间隔进行发送;2、当前与上一次接收的值超过了阈值,进行发送。

            //首先判断此监测点是否报警,若报警,则继续执行下一步
            if (string.IsNullOrEmpty(model.AlertId))
            {
                return(smsModel);
            }


            var stationKey = model.StationKey;

            var cache = _cache.Get <SmsCacheModel>("Default:Kylin:SMS:" + stationKey);

            //根据监测点编号判断是否有缓存
            if (cache == null)
            {
                return(smsModel);
            }

            smsModel.SystemCode = ConfigurationManager.AppSettings["SystemCode"];
            smsModel.IsSend     = cache.IsEnabled != 0;
            var smsInfo = cache.StationName + "," + model.TagName + "," + model.TagValue +
                          model.Units + "," + model.SaveTime;

            smsModel.MsgString  = smsInfo;
            smsModel.MsgTempId  = cache.TemplateId == ""? ConfigurationManager.AppSettings["DefaultTemplateId"] : cache.TemplateId;
            smsModel.Phone      = cache.PhoneString;
            smsModel.StationKey = stationKey;
            smsModel.Value      = decimal.Parse(model.TagValue);
            smsModel.SaveTime   = model.SaveTime;
            if (cache.Interval == 0)
            {
                cache.Interval = int.Parse(ConfigurationManager.AppSettings["DefaultSendInterval"]);
            }

            if (decimal.Parse(model.TagValue) - cache.LastValue >= cache.ChangeDiff)
            {
                //立刻发送
                UpdateCache(stationKey, cache, model.TagValue, model.SaveTime);
                return(smsModel);
            }
            else if (cache.LastTime.AddMinutes((int)cache.Interval) <= DateTime.Now)
            {
                //根据时间间隔发送
                UpdateCache(stationKey, cache, model.TagValue, model.SaveTime);
                return(smsModel);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
 public string SendMsg(SmsSendModel model)
 {
     try
     {
         _dtRestRequest = new DtRestRequest(Method.POST)
         {
             Resource = "application/x-www-form-urlencoded"
         };
         _dtRestRequest.AddParamete("phone", model.Phone);
         _dtRestRequest.AddParamete("message", model.MsgString);
         _dtRestRequest.AddParamete("templateId", model.MsgTempId);
         _dtRestRequest.AddParamete("systemCode", model.SystemCode);
         var     response = _dtRestClient.Execute(_dtRestRequest);
         dynamic content  = JsonConvert.DeserializeObject(response.Content);
         return(content.resp.respCode);
     }
     catch (Exception e)
     {
         return("");
     }
 }
Exemplo n.º 3
0
 //发送短信
 public bool SendMsg(SmsSendModel model)
 {
     throw new System.NotImplementedException();
 }