public void NotifyMms(string messageId) { try { //2b03219a-2e44-414d-817d-8314e1f42c42 _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 mms = new Mms(openMasConfig.MmsMasService); var message = mms.GetMessage(messageId); if (message == null) { _logger.DebugFormat("收到的UnitId={0}的彩信上行操作,但获取的信息为null", unitId.Value); return; } var notifyMessage = new NotifyMessage(); notifyMessage.ApplicationId = message.ApplicationId; notifyMessage.Content = message.Content; notifyMessage.ExtendCode = message.ExtendCode; notifyMessage.From = message.From; notifyMessage.MessageId = messageId; notifyMessage.MessageType = MessageType.Sms; notifyMessage.ReceivedTime = message.ReceivedTime; notifyMessage.To = message.To; notifyMessage.Title = message.Subject; notifyMessage.Unit = openMasConfig.Unit; _logger.DebugFormat("收到的messageId={0}的彩信内容为:{1}", messageId, message.Content); _logger.DebugFormat("全文序列化内容为:{0}", Newtonsoft.Json.JsonConvert.SerializeObject(message)); //业务逻辑,彩信内容可以从message中获取 _logger.InfoFormat("接收到OpenMas发来的彩信messageId={0}", messageId); var repository = new NotifyMessageRepository(); repository.SaveOrUpdate(notifyMessage); } catch (Exception ex) { _logger.ErrorFormat("接收到OpenMas发来的彩信messageId={0},但处理时发生异常{1}", messageId, ex); } }
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); } }