Exemplo n.º 1
0
 public ActionResult Index(string openId, int articleId)
 {
     try
     {
         WX_Article article = WXArticleServices.QueryById(articleId);
         if (article == null)
         {
             return(RedirectToAction("NotPage", "ErrorPrompt", new { message = "获取微信基础信息失败" }));
         }
         return(View(article));
     }
     catch (Exception ex) {
         ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "Index方法处理异常", ex, LogFrom.WeiXin);
         return(RedirectToAction("NotPage", "ErrorPrompt", new { message = "获取数据异常" }));
     }
 }
Exemplo n.º 2
0
        public IWRespBase ReplyContent(WX_ApiConfig config, WX_Keyword gKey, WReqBase request, string qValue)
        {
            var response = request.CreateResponse <WRespNews>();
            var articles = WXArticleServices.QueryByGroupID(gKey.ArticleGroupID);

            foreach (var item in articles.OrderBy(o => o.Sort))
            {
                var article = new Article
                {
                    Title       = item.Title,
                    Description = item.Description,
                    PicUrl      = string.IsNullOrWhiteSpace(item.ImagePath) ? string.Empty : string.Format("{0}{1}", config.Domain, item.ImagePath)
                };
                switch (item.ArticleType)
                {
                case ArticleType.Text:
                    article.Url = string.Format("{0}/WxArticleDetail/Index?openId={1}&articleId={2}", config.Domain, request.FromUserName, item.ID);
                    break;

                case ArticleType.Url:
                    article.Url = item.Url;
                    break;

                case ArticleType.Module:
                {
                    string link = ((WeiXinModule)int.Parse(item.Url)).GetEnumDefaultValue();
                    if (!string.IsNullOrWhiteSpace(link))
                    {
                        if (link.Contains("="))
                        {
                            link = string.Format("{0}^cid={1}", link, config.CompanyID);
                        }
                        else
                        {
                            link = string.Format("{0}_cid={1}", link, config.CompanyID);
                        }
                    }
                    article.Url = string.Format("{0}{1}", config.Domain, link);
                    break;
                }

                default: continue;
                }
                response.Articles.Add(article);
            }
            return(response);
        }
Exemplo n.º 3
0
        public JsonResult GetArticleData(string companyId)
        {
            JsonResult        json   = new JsonResult();
            List <WX_Article> models = WXArticleServices.QueryAll(companyId);

            if (models.Count > 0)
            {
                List <string> groupIds = models.Select(p => p.GroupID).Distinct().ToList();
                var           result   = from p in groupIds
                                         select new
                {
                    id   = p,
                    text = models.OrderBy(o => o.Sort).First(o => o.GroupID == p).Title
                };
                json.Data = result;
            }
            return(json);
        }
Exemplo n.º 4
0
 public JsonResult GetArticle(string groupId, string companyI)
 {
     try
     {
         List <WX_Article> models = new List <WX_Article>();
         if (!string.IsNullOrWhiteSpace(groupId))
         {
             models = WXArticleServices.QueryByGroupID(groupId).OrderBy(p => p.Sort).ToList();
         }
         return(Json(MyResult.Success(string.Empty, models)));
     }
     catch (MyException ex)
     {
         return(Json(MyResult.Error(ex.Message)));
     }
     catch (Exception ex)
     {
         ExceptionsServices.AddExceptions(ex, "根据分组编号查询图文信息失败");
         return(Json(MyResult.Error("查询图文信息失败")));
     }
 }
Exemplo n.º 5
0
 public JsonResult Delete(string groupId)
 {
     try
     {
         bool result = WXArticleServices.DeleteByGroupID(groupId);
         if (!result)
         {
             throw new MyException("删除图文失败");
         }
         return(Json(MyResult.Success()));
     }
     catch (MyException ex)
     {
         return(Json(MyResult.Error(ex.Message)));
     }
     catch (Exception ex)
     {
         ExceptionsServices.AddExceptions(ex, "删除图文失败");
         return(Json(MyResult.Error("删除图文失败")));
     }
 }
Exemplo n.º 6
0
        public JsonResult GetWXArticleData(string companyId)
        {
            JsonResult json = new JsonResult();

            try
            {
                List <WX_Article> models   = WXArticleServices.QueryAll(companyId);
                List <string>     groupIds = models.Select(p => p.GroupID).Distinct().ToList();
                var result = from p in groupIds
                             select new
                {
                    GroupId = p,
                    Count   = models.Count(o => o.GroupID == p),
                    Title   = models.OrderBy(o => o.Sort).First(o => o.GroupID == p).Title
                };
                json.Data = result;
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "查询图文信息失败");
            }

            return(json);
        }
Exemplo n.º 7
0
        public JsonResult SaveArticle(string groupId, int itemnum, string jsonData)
        {
            try
            {
                string newGroupId = string.Empty;
                if (string.IsNullOrWhiteSpace(groupId))
                {
                    newGroupId = GuidGenerator.GetGuidString();
                }
                var dyArticles           = JsonHelper.Parse(jsonData);
                List <WX_Article> models = new List <WX_Article>();
                for (var i = 0; i < itemnum; i++)
                {
                    WX_Article model = new WX_Article();
                    model.ID = int.Parse(dyArticles[i].id);
                    if (string.IsNullOrWhiteSpace(dyArticles[i].title))
                    {
                        throw new MyException(string.Format("获取第{0}个图文的标题失败", i + 1));
                    }
                    model.Title     = dyArticles[i].title;
                    model.ImagePath = dyArticles[i].pic;
                    if (string.IsNullOrWhiteSpace(dyArticles[i].pic))
                    {
                        throw new MyException(string.Format("获取第{0}个图文的封面图片失败", i + 1));
                    }
                    model.Description = dyArticles[i].desc;
                    if (!string.IsNullOrWhiteSpace(groupId))
                    {
                        List <WX_Article> oldArticles = WXArticleServices.QueryByGroupID(groupId);
                        if (oldArticles.Count == 0)
                        {
                            throw new MyException("获取单位编号失败");
                        }

                        model.CompanyID = oldArticles.First().CompanyID;
                    }
                    else
                    {
                        model.CompanyID = dyArticles[i].companyid;
                    }

                    model.Text        = dyArticles[i].text;
                    model.ArticleType = (ArticleType)int.Parse(dyArticles[i].type);
                    if (model.ArticleType == ArticleType.Url && string.IsNullOrWhiteSpace(dyArticles[i].url))
                    {
                        throw new MyException(string.Format("获取第{0}个图文的链接地址失败", i + 1));
                    }
                    if (model.ArticleType == ArticleType.Module && string.IsNullOrWhiteSpace(dyArticles[i].moduleid))
                    {
                        throw new MyException(string.Format("获取第{0}个图文的模块失败", i + 1));
                    }
                    switch (model.ArticleType)
                    {
                    case ArticleType.Url:
                    {
                        model.Url = dyArticles[i].url;
                        break;
                    }

                    case ArticleType.Module:
                    {
                        model.Url = dyArticles[i].moduleid;
                        break;
                    }

                    default:
                    {
                        model.Url = string.Empty;
                        break;
                    }
                    }
                    model.Sort       = (int)dyArticles[i].sort;
                    model.GroupID    = string.IsNullOrWhiteSpace(groupId)?newGroupId:groupId;
                    model.CreateTime = DateTime.Now;
                    models.Add(model);
                }
                bool result = WXArticleServices.Create(models);
                if (!result)
                {
                    throw new MyException("保存图文失败");
                }
                return(Json(MyResult.Success()));
            }
            catch (MyException ex)
            {
                return(Json(MyResult.Error(ex.Message)));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "保存图文失败");
                return(Json(MyResult.Error("保存图文失败")));
            }
        }