public static SmsMessage NotifySms(string messageId)
 {
     try
     {
         //调用上行短信获取接口获取短消息
         string      _SmsServiceUrl = GetServiceURL;
         OpenMas.Sms _Sms           = new OpenMas.Sms(_SmsServiceUrl);
         SmsMessage  message        = _Sms.GetMessage(messageId);
         return(message);
         //业务逻辑,短信内容可以从message中获取
         //......
     }
     catch (Exception ex)
     {
         //处理异常信息
         //.......
         return(null);
     }
 }
예제 #2
0
        public void NotifySms(string messageId)
        {
            try
            {
                _logger.DebugFormat("收到的messageId={0}的短信上行操作", messageId);
                var unitId = UnitMapping.UnitId;
                if (!unitId.HasValue)
                    return;
                _logger.DebugFormat("收到的UnitId={0}的短信上行操作", unitId.Value);
                var openMasConfig = new OpenMasConfigRepository().GetOpenMasConfigByUnit(unitId.Value);
                //调用上行短信获取接口获取短消息
                var sms = new OpenMas.Sms(openMasConfig.SmsMasService);
                var message = sms.GetMessage(messageId);
                if (message == null)
                {
                    _logger.ErrorFormat("接收到OpenMas发来的短信messageId={0},使用{1}去获取时失败", messageId, openMasConfig.SmsMasService);
                    return;

                }
                var proposalInfo = ProposalParser(message.Content);
                if (proposalInfo == null)
                {
                    NpcSmsSendService.SendSms(openMasConfig, GetDescirption(), new[] { message.From });
                    _logger.ErrorFormat("接收到OpenMas发来的短信messageId={0},内容{1}不符合格式!", messageId, message);
                    return;
                }
                var notifyMessage = new NotifyMessage();

                notifyMessage.MessageId = messageId;
                notifyMessage.ApplicationId = message.ApplicationId;
                notifyMessage.ProposalType = proposalInfo.Item1;
                notifyMessage.Title = proposalInfo.Item2;
                notifyMessage.Content = proposalInfo.Item3;
                notifyMessage.ExtendCode = message.ExtendCode;
                notifyMessage.From = message.From;
                notifyMessage.MessageType = MessageType.Sms;
                notifyMessage.ReceivedTime = message.ReceivedTime;
                notifyMessage.To = message.To;
                notifyMessage.Unit = openMasConfig.Unit;

                _logger.DebugFormat("收到的messageId={0}的短信内容为:{1}", messageId, message.Content);
                _logger.DebugFormat("全文序列化内容为:{0}", Newtonsoft.Json.JsonConvert.SerializeObject(message));
                //业务逻辑,短信内容可以从message中获取

                var repository = new NotifyMessageRepository();
                repository.SaveOrUpdate(notifyMessage);
            }
            catch (Exception ex)
            {
                _logger.ErrorFormat("接收到OpenMas发来的短信messageId={0},但处理时发生异常{1}", messageId, ex);
            }
        }