Beispiel #1
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;
            }
        }
Beispiel #2
0
 ///<summary>
 ///</summary>
 ///<param name="node"></param>
 ///<param name="nmManager"></param>
 ///<param name="prefix"></param>
 internal BodyInfo(XmlNode node, XmlNamespaceManager nmManager, string prefix)
 {
     foreach (XmlNode item in node.SelectNodes(string.Format(CultureInfo.CurrentCulture, "//{0}:par", prefix), nmManager))
     {
         var par = new ParInfo(item);
         _parList.Add(par);
     }
 }