Esempio n. 1
0
 public void Send(EditNpcMmsSendModel model)
 {
     if (!model.Receivers.Any())
     {
         throw new ArgumentException("接收人未指定");
     }
     var trans = TransactionManager.BeginTransaction();
     var newNpcMmsSend = new NpcMmsSend();
     try
     {
         newNpcMmsSend.NpcMms = _npcMmsRepository.Find(model.NpcMmsId);
         foreach (var receiver in model.Receivers)
         {
             newNpcMmsSend.NpcMmsReceivers.Add(new NpcMmsReceiver()
             {
                 TelNum = receiver
             });
         }
         newNpcMmsSend.TimeOfExceptSend = model.TimeOfExpectSend;
         newNpcMmsSend.Title = model.SendTitle;
         newNpcMmsSend.Unit = NpcContext.CurrentUser.Unit;
         trans.Begin();
         _npcMmsSendRepository.Save(newNpcMmsSend);
         trans.Commit();
     }
     catch (Exception)
     {
         trans.Rollback();
         throw;
     }
     SendMms(newNpcMmsSend);
 }
 public void TestMmsSendSave()
 {
     var npcMmsRepository = new NpcMmsRepository();
     var unitRepository = new UnitRepository();
     var npcMmsSendRepository = new NpcMmsSendRepository();
     var npcMmsSend = new NpcMmsSend();
     var mms = npcMmsRepository.Find(Guid.Parse("fc224427-5730-4438-8494-a13b00dba61c"));
     npcMmsSend.NpcMms = mms;
     npcMmsSend.Title = "新年快乐";
     npcMmsSend.Unit = mms.Unit;
     npcMmsSend.RecordDescription.CreateBy(null);
     npcMmsSendRepository.Save(npcMmsSend);
 }
Esempio n. 3
0
        public void SingleSend(NpcMmsSend npcMmsSend)
        {
            var trans = TransactionManager.BeginTransaction();
            trans.Begin();
            var mmsBuilder = new MmsBuilder();
            try
            {
                var parList = new List<ParInfo>();
                var config = _openMasConfigService.GetConfigOfUnit(npcMmsSend.Unit.Id);
                #region 创建彩信
                var count = 1;
                foreach (var content in npcMmsSend.NpcMms.NpcMmsContents.OrderBy(o => o.OrderSort))
                {
                    if (npcMmsSend.NpcMms.NpcMmsContents.Count == 1&&string.IsNullOrEmpty(content.Content))
                        content.LayoutType = LayoutType.PicTop;
                    var parInfo = new ParInfo();
                    parInfo.Dur = content.DueTime + "s";
                    var textContent = GetTextContent(content.Content + (count == npcMmsSend.NpcMms.NpcMmsContents.Count && !string.IsNullOrEmpty(config.Signature) ? "【" + config.Signature + "】" : string.Empty));
                    var picContent = GetMediaContent(content.UrlOfPic, MediaType.Pic);
                    var voiceContent = GetMediaContent(content.UrlOfVoice, MediaType.Voice);

                    if (content.LayoutType == LayoutType.PicBottom)
                    {
                        if (textContent != null)
                        {
                            mmsBuilder.AddContent(textContent);
                            parInfo.Text = new TextInfo { Src = textContent.ContentId, Region = "text" };
                        }
                        if (picContent != null)
                        {
                            mmsBuilder.AddContent(picContent);
                            parInfo.Img = new ImgInfo { Src = picContent.ContentId, Region = "image" };
                        }
                    }
                    else
                    {
                        if (picContent != null)
                        {
                            mmsBuilder.AddContent(picContent);
                            parInfo.Img = new ImgInfo { Src = picContent.ContentId, Region = "image" };
                        }
                        if (textContent != null)
                        {
                            mmsBuilder.AddContent(textContent);
                            parInfo.Text = new TextInfo { Src = textContent.ContentId, Region = "text" };
                        }
                    }
                    if (voiceContent != null)
                    {
                        parInfo.Audio = new AudioInfo { Src = voiceContent.ContentId };
                        mmsBuilder.AddContent(voiceContent);
                    }
                    count++;
                    parList.Add(parInfo);
                }
                var smil = CommonUtil.BuilderSmil(GetLayoutInfo(npcMmsSend.NpcMms.LayoutType, "image", "text"), parList);
                mmsBuilder.AddContent(GetSmilContent(smil));
                var mmsXml = mmsBuilder.BuildContentToXml();
                var mms = new Mms(config.MmsMasService);
                string messageId;
                if (npcMmsSend.TimeOfExceptSend == null)
                {
                    messageId = mms.SendMessage(npcMmsSend.NpcMmsReceivers.Select(o => o.TelNum).ToArray(), npcMmsSend.Title, mmsXml, config.MmsExtensionNo.ToString(CultureInfo.InvariantCulture), config.MmsAppAccount, config.MmsAppPwd);
                }
                else
                {
                    messageId = mms.SendMessage(npcMmsSend.NpcMmsReceivers.Select(o => o.TelNum).ToArray(), npcMmsSend.Title, mmsXml, config.MmsExtensionNo.ToString(CultureInfo.InvariantCulture), config.MmsAppAccount, config.MmsAppPwd, npcMmsSend.TimeOfExceptSend.Value);
                }
                #endregion
                npcMmsSend.SendStatus = SendStatus.Done;
                npcMmsSend.MessageId = messageId;
                _npcMmsSendRepository.Save(npcMmsSend);
                trans.Commit();
                _logger.ErrorFormat("npcMmsSendId={0}发送成功,返回MessageId:{1}", npcMmsSend.Id, messageId);
            }
            catch (Exception exception)
            {
                _logger.ErrorFormat("id={0}发送时出错:{1}", npcMmsSend.Id, exception);
                trans.Rollback();
                throw;
            }
        }
Esempio n. 4
0
 private void SendMms(NpcMmsSend npcMmsSend)
 {
     var npcMmsSendService = new NpcMmsSendService();
     try
     {
         npcMmsSendService.SingleSend(npcMmsSend);
     }
     catch (Exception exception)
     {
         Logger.ErrorFormat("发送npcMmsSendId={0}时错误:{1}", npcMmsSend.Id, exception);
     }
 }