Beispiel #1
0
        public WxJsonResult UploadNews(Wx_App app, string newsIds, int openComment = 1)
        {
            DateTime now  = DateTime.Now;
            var      news = GetNews(newsIds).Select(n =>
            {
                GetThumbMedia(app, n);

                return(new NewsModel
                {
                    title = n.Title,
                    author = n.Author,
                    content = GetWxHtml(app, n),
                    content_source_url = App.GetWebPath(n.SourceUrl, true),
                    digest = n.Digest,
                    show_cover_pic = "0",
                    thumb_media_id = n.ThumbMediaId,
                    need_open_comment = openComment
                });
            }).ToArray();

            var result = MediaApi.UploadNews(app.AppId, 300000, news);

            if (result.ErrorCodeValue == 0)
            {
                UploadNews(app.Id, newsIds, news.Length, result.media_id, result.url);
            }
            return(result);
        }
Beispiel #2
0
 public WeChatController(
     ILogger <WeChatController> logger,
     IWeChatContainer container,
     IAppService appService,
     IMenuService menuService,
     IMediaService mediaService,
     INewsService newsService,
     IActivityService activityService,
     IVoteService voteService,
     IUserService userService,
     IScaleService scaleService,
     IUAService uAService,
     IRoleService roleService,
     IPAService pAService,
     IObjectService objectService)
     : base(logger, userService, scaleService, uAService, roleService, pAService, objectService)
 {
     this.logger          = logger;
     this.app             = container.GetApp();
     this.appService      = appService;
     this.menuService     = menuService;
     this.mediaService    = mediaService;
     this.newsService     = newsService;
     this.activityService = activityService;
     this.voteService     = voteService;
 }
Beispiel #3
0
        public WxJsonResult CreateMenu(Wx_App app)
        {
            var menu    = new ButtonGroup();
            var buttons = GetMenus(app.Id);

            var tops = from b in buttons
                       where !b.ParentId.HasValue
                       orderby b.OrderNo
                       select b;

            tops.Each(btn =>
            {
                if (btn.Type == WxButton.sub_button)
                {
                    var btns   = new SubButton(btn.Name);
                    var childs = from b in buttons
                                 where b.ParentId == btn.Id
                                 orderby b.OrderNo
                                 select b;
                    childs.Each(btnc =>
                    {
                        btns.sub_button.Add(GetButton(btnc));
                    });
                    menu.button.Add(btns);
                }
                else
                {
                    menu.button.Add(GetButton(btn));
                }
            });

            return(CommonApi.CreateMenu(app.AppId, menu));
        }
Beispiel #4
0
 public WeAppController(ILogger <WeAppController> logger,
                        IWeChatContainer container,
                        IAppService appService)
 {
     this.logger     = logger;
     this.app        = container.GetApp();
     this.appService = appService;
 }
Beispiel #5
0
 public UploadForeverMediaResult UploadMedia(Wx_App app, string mediaUrl)
 {
     if (!mediaUrl.HasValue())
     {
         throw new AceException("上传的素材不存在!");
     }
     return(WeChatApi.UploadForeverMedia(app.AppId, mediaUrl));
 }
Beispiel #6
0
        public WxJsonResult SendMedia(Wx_App app, long mediaId, bool isToAll = true)
        {
            var media  = Get(mediaId);
            var result = GroupMessageApi.SendGroupMessageByGroupId(app.AppId, null, media.MediaId, GetMessageType(media.Type), isToAll);

            WriteSendLog(mediaId, result);
            return(result);
        }
Beispiel #7
0
        private string GetWxHtml(Wx_App app, Wx_News news)
        {
            var html   = new HtmlDocument();
            var sysCfg = configService.GetConfig(app.Id);

            var content = news.Content.Replace(vars);
            var header  = sysCfg["header_html"];
            var footer  = sysCfg["footer_html"];
            var cover   = "<p><img src=\"" + news.ThumbWxUrl + "\" /></p>";

            html.LoadHtml("<div>" + header + cover + content + footer + "</div>");

            var nodes = html.DocumentNode.SelectNodes("./div/p | ./div/div");

            if (nodes != null)
            {
                foreach (HtmlNode item in nodes)
                {
                    item.InnerHtml = item.InnerHtml.Trim();
                    SetStyle(item, "padding:0.25em 0");

                    var subImgs = item.SelectNodes(".//img");
                    if (subImgs == null || subImgs.Count <= 0)
                    {
                        var attr = item.Attributes["style"];
                        if (attr == null || attr.Value.IndexOf("text-align:center") < 0)
                        {
                            SetStyle(item, "text-indent:2em");
                        }
                    }
                    if (!item.HasChildNodes)
                    {
                        item.Remove();
                    }
                }
            }

            var imgs = html.DocumentNode.SelectNodes("//img");

            if (imgs != null)
            {
                foreach (HtmlNode img in imgs)
                {
                    var src    = img.Attributes["src"].Value;
                    var result = WeChatApi.UploadImg(app.AppId, src);
                    if (result != null)
                    {
                        img.Attributes["src"].Value = result.url;
                    }
                    img.Attributes.Remove("width");
                    img.Attributes.Remove("height");

                    SetStyle(img, "width:100%!important;height:auto!important");
                }
            }
            return(html.DocumentNode.InnerHtml);
        }
Beispiel #8
0
        public void PreviewMedia(Wx_App app, long mediaId, string wxNames)
        {
            var media = Get(mediaId);

            wxNames.Split(',').Each(wxName =>
            {
                GroupMessageApi.SendGroupMessagePreview(app.AppId, GetMessageType(media.Type), media.MediaId, null, wxName);
            });
        }
Beispiel #9
0
 public WeChatHandler(IServiceProvider services, Wx_App app,
                      Stream inputStream, PostModel postModel, int maxRecordCount)
     : base(inputStream, postModel, maxRecordCount)
 {
     this.services        = services;
     this.app             = app;
     this.configService   = services.GetService <IConfigService>();
     this.activityService = services.GetService <IActivityService>();
     this.logger          = services.GetService <ILogger <WeChatHandler> >();
 }
Beispiel #10
0
 public void DeleteMedias(Wx_App app, string mediaIds)
 {
     foreach (var remoteMedia in GetRemoteMedias(app.Id, mediaIds))
     {
         var result = MediaApi.DeleteForeverMedia(app.AppId, remoteMedia.MediaId);
         if (result.ErrorCodeValue != 0)
         {
             throw new AceException(result.errcode.ToString());
         }
     }
 }
Beispiel #11
0
 public void UploadMedias(Wx_App app, string mediaIds)
 {
     foreach (Wx_Media localMedia in GetLocalMedias(app.Id, mediaIds))
     {
         var result = UploadMedia(app, localMedia.Url);
         if (result.ErrorCodeValue != 0)
         {
             throw new AceException(result.errcode.ToString());
         }
         UpdateMedia(localMedia.Id, result.media_id, result.url);
     }
 }
Beispiel #12
0
 public WeAppController(
     ILogger <WeAppController> logger,
     IWeChatContainer container,
     IAppService appService,
     IWechatService wechatService)
     : base(logger)
 {
     this.logger        = logger;
     this.app           = container.GetApp();
     this.appService    = appService;
     this.wechatService = wechatService;
 }
Beispiel #13
0
 public void CreateQrCode(Wx_App app, string activityIds)
 {
     activityIds.Split <long>().Each(activityId =>
     {
         var activity = Get(activityId);
         if (activity != null)
         {
             var result       = QrCodeApi.Create(app.AppId, 2592000, 1, QrCode_ActionName.QR_LIMIT_STR_SCENE, $"{activityId}");
             activity.QrCode  = result.url;
             activity.DUpdate = DateTime.Now;
             UpdateQrCode(activity);
         }
     });
 }
Beispiel #14
0
        public void SendActivity(Wx_App app, Wx_Activity activity, string openId)
        {
            var articles = new List <Article>();

            articles.Add(new Article
            {
                Title       = activity.Name,
                Description = activity.Remark,
                PicUrl      = activity.Poster,
                Url         = activity.Url
            });

            CustomApi.SendNews(app.AppId, openId, articles);
        }
Beispiel #15
0
 private void GetThumbMedia(Wx_App app, Wx_News news)
 {
     if (!news.ThumbMediaId.HasValue())
     {
         var result = mediaService.UploadMedia(app, news.ThumbUrl.TrimStart(','));
         if (result.ErrorCodeValue != 0)
         {
             throw new AceException(result.errcode.ToString());
         }
         news.ThumbMediaId = result.media_id;
         news.ThumbWxUrl   = result.url;
         UpdateThumbMedia(news);
     }
 }
Beispiel #16
0
 public WeChatController(
     ILogger <WeChatController> logger,
     IWeChatContainer container,
     IAppService appService,
     IMenuService menuService,
     IMediaService mediaService,
     INewsService newsService,
     IActivityService activityService,
     IVoteService voteService)
     : base(logger)
 {
     this.logger          = logger;
     this.app             = container.GetApp();
     this.appService      = appService;
     this.menuService     = menuService;
     this.mediaService    = mediaService;
     this.newsService     = newsService;
     this.activityService = activityService;
     this.voteService     = voteService;
 }
Beispiel #17
0
 public Rbac_User WeopenRegist(Wx_App app, UserInfoJson userInfo, string mobile = null)
 {
     return(Session.QueryFirst <Rbac_User>(
                new RequestContext("wx", "exec_wx_regist")
                .SetParam(new
     {
         newid = App.IdWorker.NextId(),
         mobile = mobile,
         nickname = userInfo.nickname,
         photo = userInfo.headimgurl,
         province = userInfo.province,
         city = userInfo.city,
         country = userInfo.country,
         appid = app.Id,
         authtype = "wechat",
         authid = userInfo.openid,
         unionid = userInfo.unionid
     })
                ));
 }
Beispiel #18
0
 public static JsCode2JsonResult WxLogin(Wx_App app, string code)
 {
     return(SnsApi.JsCode2Json(app.AppId, app.AppSecret, code));
 }
Beispiel #19
0
 public GetMenuResult GetMenu(Wx_App app)
 {
     return(CommonApi.GetMenu(app.AppId));
 }
Beispiel #20
0
 public WxJsonResult DeleteMenu(Wx_App app)
 {
     return(CommonApi.DeleteMenu(app.AppId));
 }