예제 #1
0
        protected Func <object, string, object> GetDicResourceConvert(int wxtype, string msgType, Func <NewsModelX, object> pFunc)
        {
            if (_DicResourceConvert == null || _DicResourceConvert.Count == 0)
            {
                var ps = wxtype == 1 ? "MP" : "QY";

                var pArticleSer = new WeChatArticleService(ps);
                pArticleSer.ArticleConvertFunc = pFunc;

                _DicResourceConvert = new Dictionary <string, Func <object, string, object> >();
                _DicResourceConvert.Add("text", (object content, string mType) => { return(content); });
                _DicResourceConvert.Add("image", (object media_id, string mType) => { return(media_id); });
                _DicResourceConvert.Add("voice", (object media_id, string mType) => { return(media_id); });
                _DicResourceConvert.Add("video", (object media_id, string mType) => { return(media_id); });
                _DicResourceConvert.Add("file", (object media_id, string mType) => { return(media_id); });
                _DicResourceConvert.Add("news", pArticleSer.LoadResources2News);
                _DicResourceConvert.Add("mpnews", pArticleSer.LoadResources2News);
                //pdicContent.Add("mpnews", .LoadResources2Mpnews);
            }

            if (!_DicResourceConvert.ContainsKey(msgType))
            {
                return(null);
            }
            return(_DicResourceConvert[msgType]);
        }
예제 #2
0
        /// <summary>
        /// 发送图文消息
        /// </summary>
        private void SendCSMessageMpnews(string openId, string pHost, int?lcId)
        {
            if (lcId == null)
            {
                return;
            }

            WeChatArticleService pService  = new WeChatArticleService("MP");
            List <Article>       pArticles = pService.LoadResources2LocalArticles(pHost, lcId.Value);
            var pResult = pService.GetActionResult();

            if (pResult != null || pArticles == null || pArticles.Count == 0)
            {
                return;
            }

            EG.WeChat.Service.WeiXin.WeixinMessageSender pSender = new WeixinMessageSender();
            pSender.SendArticle(openId, pArticles);
        }
예제 #3
0
파일: QYSdkETS.cs 프로젝트: zero1036/TGNet
        /// <summary>
        /// 获取素材转换方法——用于转换被动回复消息
        /// 暂时企业号独占
        /// </summary>
        /// <param name="msgType"></param>
        /// <returns></returns>
        public Func <int, string, Senparc.Weixin.QY.Entities.IResponseMessageBase> GetResConvertForResponse(string msgType)
        {
            if (_DicRCForResponse == null || _DicRCForResponse.Count == 0)
            {
                _DicRCForResponse = new Dictionary <string, Func <int, string, Senparc.Weixin.QY.Entities.IResponseMessageBase> >();


                _DicRCForResponse.Add("text", (int lcId, string mType) =>
                {
                    var responseMessage     = new Senparc.Weixin.QY.Entities.ResponseMessageText();
                    responseMessage.Content = "测试";
                    return(responseMessage);
                });
                _DicRCForResponse.Add("image", (int lcId, string mType) =>
                {
                    var pAr  = new WeChatPictureService("QY");
                    var pImg = pAr.LoadResourcesSingleBylcId(lcId);

                    var responseMessage = new Senparc.Weixin.QY.Entities.ResponseMessageImage();
                    if (pImg != null)
                    {
                        responseMessage.Image.MediaId = pImg.media_id;
                    }
                    return(responseMessage);
                });
                _DicRCForResponse.Add("voice", (int lcId, string mType) =>
                {
                    var pAr    = new WeChatVoiceService("QY");
                    var pVoice = pAr.LoadResourcesSingleBylcId(lcId);

                    var responseMessage = new Senparc.Weixin.QY.Entities.ResponseMessageVoice();
                    if (pVoice != null)
                    {
                        responseMessage.Voice.MediaId = pVoice.media_id;
                    }
                    return(responseMessage);
                });
                _DicRCForResponse.Add("video", (int lcId, string mType) =>
                {
                    var pAr    = new WeChatVideoService("QY");
                    var pVideo = pAr.LoadResourcesSingleBylcId(lcId);

                    var responseMessage = new Senparc.Weixin.QY.Entities.ResponseMessageVideo();
                    if (pVideo != null)
                    {
                        responseMessage.Video.Title   = pVideo.lcName;
                        responseMessage.Video.MediaId = pVideo.media_id;
                    }
                    return(responseMessage);
                });
                _DicRCForResponse.Add("news", (int lcId, string mType) =>
                {
                    var pAr = new WeChatArticleService("QY");
                    pAr.ArticleConvertFunc = this.CNews2RspArticle(msgType);
                    List <object> pos      = pAr.LoadResources2News(lcId, mType);
                    if (pos == null || pos.Count == 0)
                    {
                        return(null);
                    }

                    var responseMessage      = new Senparc.Weixin.QY.Entities.ResponseMessageNews();
                    responseMessage.Articles = pos.Select(p => (p as Senparc.Weixin.QY.Entities.Article)).ToList();
                    return(responseMessage);
                });
                _DicRCForResponse.Add("mpnews", (int lcId, string mType) =>
                {
                    var pAr = new WeChatArticleService("QY");
                    pAr.ArticleConvertFunc = this.CNews2RspArticle(msgType);
                    List <object> pos      = pAr.LoadResources2News(lcId, mType);

                    var responseMessage      = new Senparc.Weixin.QY.Entities.ResponseMessageNews();
                    responseMessage.Articles = pos.Select(p => (p as Senparc.Weixin.QY.Entities.Article)).ToList();
                    int idx = 0;
                    foreach (var a in responseMessage.Articles)
                    {
                        a.Url = string.Format("http://{0}/WXArticle/Index?lcid={1}&idx={2}", RHost, lcId, idx);
                        idx  += 1;
                    }
                    return(responseMessage);
                });
            }

            if (!_DicRCForResponse.ContainsKey(msgType))
            {
                return(null);
            }
            return(_DicRCForResponse[msgType]);
        }