public ActionResult Save_PromptLanguage(Guid id, string type, string content)
        {
            OfficialAccount_BLL bll = new OfficialAccount_BLL();
            OfficialAccount     of  = bll.Get(a => a.AccountID == id);

            try
            {
                //Regex.Replace(content, "<p>[\s]*</p>", "");
                content = Regex.Replace(content, "<p[^>]*>", "").Replace("</p>", "").Replace("<br>", "\n").Replace("<br/>", "\n");
                //content.Replace(@"<p>", "");
                //content.Replace(@"</p>", "");

                if (type == "welcome")
                {
                    of.SubscribeWelcome = content;
                    bll.Update(of);
                }
                else if (type == "rewelcome")
                {
                    of.ReSubscribeWelcome = content;
                    bll.Update(of);
                }
                else if (type == "sign")
                {
                    of.SignLanguage = content;
                    bll.Update(of);
                }

                return(Content("修改成功!"));
            }
            catch (Exception)
            {
                return(Content("修改失败!"));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 最近文章页  公众号信息
        /// </summary>
        /// <param name="htmlText"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        protected OfficialAccount _ResolveOfficialAccount(string htmlText, string url)
        {
            var officialAccount = new OfficialAccount {
                AccountPageurl = url
            };
            var doc = new HtmlDocument();

            doc.LoadHtml(htmlText);
            var profileInfoArea = doc.DocumentNode.SelectSingleNode("//div[@class='profile_info_area']");

            officialAccount.ProfilePicture =
                profileInfoArea.SelectSingleNode("div[1]/span/img").GetAttributeValue("src", "");
            officialAccount.Name = profileInfoArea.SelectSingleNode("div[1]/div/strong/text()").InnerText.Trim();
            string wechatId = profileInfoArea.SelectSingleNode("div[1]/div/p/text()").InnerText.Trim();

            wechatId = wechatId.Length > 0 ? wechatId.Replace("微信号: ", "") : "";

            officialAccount.WeChatId     = wechatId;
            officialAccount.Introduction = profileInfoArea.SelectSingleNode("ul/li[1]/div/text()").InnerText;
            string authInfo = profileInfoArea.SelectSingleNode("ul/li[2]/div/text()").InnerText;

            officialAccount.IsAuth = !string.IsNullOrEmpty(authInfo);

            string qrcode = WebUtility.HtmlDecode(doc.DocumentNode.SelectSingleNode("//*[@id='js_pc_qr_code_img']")
                                                  .GetAttributeValue("src", ""));

            qrcode = qrcode.Length > 0 ? "http://mp.weixin.qq.com" + qrcode : "";

            officialAccount.QrCode = qrcode;
            return(officialAccount);
        }
        public ActionResult Edit_Area(OfficialAccount_AreaLimit_ViewModel model)
        {
            OfficialAccount_BLL bll      = new OfficialAccount_BLL();
            OfficialAccount     newmodel = bll.Get(a => a.AccountID == model.AccountID);

            newmodel.AreaLevel = model.AreaLevel;
            newmodel.AreaLimit = model.AreaLimit;



            if (bll.Update(newmodel) > 0)
            {
                return(RedirectToAction("Edit_Area"));
            }
            else
            {
                List <object> levelList = new List <object>
                {
                    new { Value = "国家", Text = "国家" },
                    new { Value = "省份", Text = "省份" },
                    new { Value = "城市", Text = "城市" }
                };
                ViewBag.LevelList = new SelectList(levelList, "Value", "Text", false);


                ModelState.AddModelError("", "修改失败,请稍后再试!");

                return(View(model));
            }
        }
        public ActionResult Edit_YouZan(OfficialAccount_YouZan_ViewModel model)
        {
            OfficialAccount_BLL bll      = new OfficialAccount_BLL();
            OfficialAccount     newmodel = bll.Get(a => a.AccountID == model.AccountID);

            newmodel.YouZanIsConfig        = true;
            newmodel.YouZanAppID           = model.YouZanAppID;
            newmodel.YouZanAppSecret       = model.YouZanAppSecret;
            newmodel.YZIncomeFirstPercent  = model.YZIncomeFirstPercent;
            newmodel.YZIncomeSecondPercent = model.YZIncomeSecondPercent;
            newmodel.YZIncomeCashLimit     = model.YZIncomeCashLimit;
            newmodel.YouZanEnable          = model.YouZanEnable;



            if (bll.Update(newmodel) > 0)
            {
                return(RedirectToAction("Edit_YouZan"));
            }
            else
            {
                ModelState.AddModelError("", "修改失败,请稍后再试!");

                return(View(model));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取公众号微信号wechatid的信息 (实际上就是搜索公众号id,获取第一个结果)
        /// wechatid: 公众号id
        /// 因为wechatid唯一确定,所以第一个就是要搜索的公众号
        ///
        /// </summary>
        /// <param name="wechatid"></param>
        /// <returns></returns>
        public OfficialAccount GetAccountInfoById(string wechatid)
        {
            //"""
            OfficialAccount info = this.SearchOfficialAccount(wechatid, 1)[0]; //可能为空

            return(info);
            // return info[0] if info else False
        }
        /// <summary>
        /// 取消关注时间
        /// </summary>
        /// <param name="requestMessage"></param>

        public void UnSubscribe(RequestMessageEvent_Unsubscribe requestMessage)
        {
            OfficialAccount_BLL obll  = new OfficialAccount_BLL();
            OfficialAccount     model = obll.Get(a => a.OriginalID == requestMessage.ToUserName);

            Subscriber_BLL sbll = new Subscriber_BLL();

            if (sbll.GetCount(a => a.OpenID == requestMessage.FromUserName && a.AccountID == model.AccountID) > 0)
            {
                Subscriber sub = sbll.Get(a => a.OpenID == requestMessage.FromUserName && a.AccountID == model.AccountID);
                sub.IsOK            = false;
                sub.UnSubscribeTime = DateTime.Now;
                if (sub.UnSubscribeCount != null)
                {
                    sub.UnSubscribeCount += 1;
                }
                else
                {
                    sub.UnSubscribeCount = 1;
                }
                sub.Score = 0;
                sbll.Update(sub);



                if (sub.FromOpenID != null)
                {
                    //if (sub.UnSubscribeCount > 1)
                    //{


                    Subscriber sup = sbll.Get(a => a.OpenID == sub.FromOpenID && a.AccountID == model.AccountID);

                    if (sup.IsOK == true)
                    {
                        sup.Score -= model.UnSubscribeReduceScore;


                        sup.DirectScore -= model.UnSubscribeReduceScore;


                        sbll.Update(sup);

                        StringBuilder sbparent = new StringBuilder();
                        sbparent.Append("您好,你的粉丝【" + sub.NickName + "】取消关注了本公众号!\n");


                        sbparent.Append("减少积分:" + model.UnSubscribeReduceScore + "分,累计积分:" + sup.Score.ToString() +
                                        "分\n");
                        CustomApi.SendText(model.AppID, sup.OpenID, sbparent.ToString());
                    }



                    //}
                }
            }
        }
        public ActionResult _Configure(Guid AccountID)
        {
            OfficialAccount_BLL bll = new OfficialAccount_BLL();
            OfficialAccount     off = bll.Get(a => a.AccountID == AccountID);

            off.IsConfigure = true;
            bll.Update(off);
            return(PartialView(off));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 搜索公众号
        /// </summary>
        /// <param name="keyword">搜索关键字</param>
        /// <param name="page">第几页</param>
        /// <returns></returns>
        public async Task <List <OfficialAccount> > SearchOfficialAccountAsync(string keyword, int page = 1)
        {
            var accountList = new List <OfficialAccount>();

            //var text = this._SearchAccount_Html(keyword, page);
            var text = await SearchAccountHtmlAsync(keyword, page);

            var pageDoc = new HtmlDocument();

            pageDoc.LoadHtml(text);
            var targetArea = pageDoc.DocumentNode.SelectNodes("//ul[@class='news-list2']/li");

            if (targetArea == null)
            {
                return(null);
            }
            foreach (var node in targetArea)
            {
                var accountInfo = new OfficialAccount();
                try
                {
                    //链接中包含了&amp; html编码符,要用htmdecode,不是urldecode
                    accountInfo.AccountPageurl =
                        WebUtility.HtmlDecode(node.SelectSingleNode("div/div[@class='img-box']/a")
                                              .GetAttributeValue("href", ""));
                    //accountInfo.ProfilePicture = node.SelectSingleNode("div/div[1]/a/img").InnerHtml;
                    accountInfo.ProfilePicture = WebUtility.HtmlDecode(node
                                                                       .SelectSingleNode("div/div[@class='img-box']/a/img").GetAttributeValue("src", ""));

                    if (accountInfo.ProfilePicture != null && accountInfo.ProfilePicture.StartsWith("//"))
                    {
                        accountInfo.ProfilePicture = "http:" + accountInfo.ProfilePicture;
                    }


                    accountInfo.Name = node.SelectSingleNode("div/div[2]/p[1]").InnerText.Trim()
                                       .Replace("<!--red_beg-->", "").Replace("<!--red_end-->", "");
                    accountInfo.WeChatId = node.SelectSingleNode("div/div[2]/p[2]/label").InnerText.Trim();
                    accountInfo.QrCode   =
                        WebUtility.HtmlDecode(node.SelectSingleNode("div/div[3]/span/img")
                                              .GetAttributeValue("src", ""));
                    accountInfo.Introduction = node.SelectSingleNode("dl[1]/dd").InnerText.Trim()
                                               .Replace("<!--red_beg-->", "").Replace("<!--red_end-->", "");
                    //早期的账号认证和后期的认证显示不一样?,对比 bitsea 和 NUAA_1952 两个账号
                    //现在改为包含该script的即认证了
                    accountInfo.IsAuth = node.InnerText.Contains("document.write(authname('2'))");
                    accountList.Add(accountInfo);
                }
                catch (Exception e)
                {
                    _logger.Warn(e);
                }
            }

            return(accountList);
        }
Ejemplo n.º 9
0
        //
        // GET: /WeiXin/Score/

        public ActionResult MyScore(string code, string state)
        {
            //string aaa = "code:" + code + " ; state:" + state;
            //return Content(aaa);


            OfficialAccount_BLL obll = new OfficialAccount_BLL();
            Guid            id       = Guid.Parse(state);
            OfficialAccount off      = obll.Get(a => a.AccountID == id);

            //return Content(off.AppID.Trim()+";"+ off.AppSecret.Trim());

            OAuthAccessTokenResult result = OAuthApi.GetAccessToken(off.AppID.Trim(), off.AppSecret.Trim(), code);

            OAuthUserInfo info = OAuthApi.GetUserInfo(result.access_token, result.openid);
            //ViewBag.aaa = info.nickname;
            //ViewBag.bbb = info.openid;

            //return Content(info.nickname + info.openid);
            //return Content(result.openid);


            //string openid = "oqbOQs7w9UNUdksAEnd5zwIxUNCE";

            Subscriber_BLL subbll = new Subscriber_BLL();

            Subscriber mysub = subbll.Get(a => a.OpenID == info.openid);

            if (mysub != null)
            {
                //获取我的粉丝
                List <Subscriber> fans =
                    subbll.GetList(a => a.FromOpenID == info.openid).OrderBy(a => a.SubscribeTime).ToList();
                ViewBag.FansList = fans;
                //获取的我的分数

                if (mysub.Score != null)
                {
                    ViewBag.MyScore = mysub.Score;
                }
                else
                {
                    ViewBag.MyScore = 0;
                }
            }
            else
            {
                ViewBag.FansList = new List <Subscriber>();
                ViewBag.MyScore  = 0;
            }



            return(View());
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 最近文章页  公众号信息
        /// </summary>
        /// <param name="text"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public OfficialAccount _ResolveOfficialAccount(string htmlText, string url)
        {
            OfficialAccount officialAccount = new OfficialAccount();

            officialAccount.AccountPageurl = url;
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(htmlText);
            var profileInfoArea = doc.DocumentNode.SelectSingleNode("//div[@class='profile_info_area']");

            officialAccount.ProfilePicture = profileInfoArea.SelectSingleNode("div[1]/span/img").GetAttributeValue("src", "");
            officialAccount.Name           = profileInfoArea.SelectSingleNode("div[1]/div/strong/text()").InnerText.Trim();
            //name = Tools.replace_space(name);
            string wechatId = profileInfoArea.SelectSingleNode("div[1]/div/p/text()").InnerText.Trim();

            if (wechatId.Length > 0)
            {
                wechatId = wechatId.Replace("微信号: ", "");
            }
            else
            {
                wechatId = "";
            }

            officialAccount.WeChatId     = wechatId;
            officialAccount.Introduction = profileInfoArea.SelectSingleNode("ul/li[1]/div/text()").InnerText;
            string authInfo = profileInfoArea.SelectSingleNode("ul/li[2]/div/text()").InnerText;

            if (!string.IsNullOrEmpty(authInfo))
            {
                officialAccount.IsAuth = true;
            }
            else
            {
                officialAccount.IsAuth = false;
            }

            string qrcode = WebUtility.HtmlDecode(doc.DocumentNode.SelectSingleNode("//*[@id='js_pc_qr_code_img']").GetAttributeValue("src", ""));

            if (qrcode.Length > 0)
            {
                qrcode = "http://mp.weixin.qq.com" + qrcode;
            }
            else
            {
                qrcode = "";
            }

            officialAccount.QrCode = qrcode;
            return(officialAccount);
        }
Ejemplo n.º 11
0
        public ActionResult SaveMenu(FormCollection fc)
        {
            Guid   id                       = Guid.Parse(fc["accountid"].ToString());
            string menustr                  = fc["menustr"].ToString();
            JavaScriptSerializer js         = new JavaScriptSerializer();
            var                 jsonResult  = js.Deserialize <GetMenuResultFull>(menustr);
            ButtonGroup         bg          = new ButtonGroup();
            GetMenuResult       aasaas      = CommonApi.GetMenuFromJsonResult(jsonResult, bg);
            OfficialAccount_BLL bll         = new OfficialAccount_BLL();
            OfficialAccount     oa          = bll.Get(a => a.AccountID == id);
            string              accessToken = AccessTokenContainer.TryGetAccessToken(oa.AppID, oa.AppSecret);

            Senparc.Weixin.Entities.WxJsonResult rrr = CommonApi.CreateMenu(accessToken, aasaas.menu);
            return(Json(rrr.errcode.ToString(), JsonRequestBehavior.AllowGet));
        }
        public ActionResult Edit(OfficialAccount_ViewModel model)
        {
            AutoMapper.Mapper.CreateMap <OfficialAccount_ViewModel, OfficialAccount>();
            OfficialAccount newmodel = AutoMapper.Mapper.Map <OfficialAccount>(model);

            OfficialAccount_BLL bll = new OfficialAccount_BLL();

            if (bll.Update(newmodel) > 0)
            {
                return(RedirectToAction("MyList"));
            }
            else
            {
                ModelState.AddModelError("", "修改失败,请稍后再试!");

                return(View(model));
            }
        }
Ejemplo n.º 13
0
        public ActionResult GetMenuJson(Guid accountid)
        {
            OfficialAccount_BLL bll = new OfficialAccount_BLL();
            OfficialAccount     oa  = bll.Get(a => a.AccountID == accountid);

            string accessToken = AccessTokenContainer.TryGetAccessToken(oa.AppID, oa.AppSecret);

            GetMenuResult result = CommonApi.GetMenu(accessToken);

            foreach (var item in result.menu.button)
            {
                var a2a = item.GetType();
            }

            var aa = result;

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 14
0
        // GET: Admin/Menu
        public ActionResult Index()
        {
            if (Session["CurrentAccountID"] == null)
            {
                return(RedirectToAction("Select", "OfficialAccount", new { Area = "Admin" }));
            }
            Guid accountid = Guid.Parse(Session["CurrentAccountID"].ToString());

            ViewBag.AccountID = accountid;
            OfficialAccount_BLL bll = new OfficialAccount_BLL();
            OfficialAccount     oa  = bll.Get(a => a.AccountID == accountid);

            ViewBag.AppID = oa.AppID;
            string accessToken = AccessTokenContainer.TryGetAccessToken(oa.AppID, oa.AppSecret);

            GetMenuResult result = CommonApi.GetMenu(accessToken);


            return(View(result));
            //return Json(result,JsonRequestBehavior.AllowGet);
        }
        public ActionResult Edit_BaseInfo(OfficialAccount_BaseInfo_ViewModel model)
        {
            OfficialAccount_BLL bll      = new OfficialAccount_BLL();
            OfficialAccount     newmodel = bll.Get(a => a.AccountID == model.AccountID);

            newmodel.WeiXinName   = model.WeiXinName;
            newmodel.OriginalID   = model.OriginalID;
            newmodel.WeiXinNumber = model.WeiXinNumber;
            newmodel.WeiXinName   = model.AppID;
            newmodel.WeiXinName   = model.AppSecret;


            if (bll.Update(newmodel) > 0)
            {
                return(RedirectToAction("Edit_BaseInfo"));
            }
            else
            {
                ModelState.AddModelError("", "修改失败,请稍后再试!");

                return(View(model));
            }
        }
        public ActionResult Edit_Score(OfficialAccount_Score_ViewModel model)
        {
            OfficialAccount_BLL bll      = new OfficialAccount_BLL();
            OfficialAccount     newmodel = bll.Get(a => a.AccountID == model.AccountID);

            newmodel.SubscribeAddScore            = model.SubscribeAddScore;
            newmodel.UnSubscribeReduceScore       = model.UnSubscribeReduceScore;
            newmodel.SubscribeParentAddScore      = model.SubscribeParentAddScore;
            newmodel.UnSubscribeParentReduceScore = model.UnSubscribeParentReduceScore;
            newmodel.SignAddScore = model.SignAddScore;



            if (bll.Update(newmodel) > 0)
            {
                return(RedirectToAction("Edit_Score"));
            }
            else
            {
                ModelState.AddModelError("", "修改失败,请稍后再试!");

                return(View(model));
            }
        }
        public ActionResult Add(OfficialAccount_BaseInfo_ViewModel model)
        {
            AutoMapper.Mapper.CreateMap <OfficialAccount_BaseInfo_ViewModel, OfficialAccount>();
            OfficialAccount newmodel = AutoMapper.Mapper.Map <OfficialAccount>(model);

            newmodel.AccountID  = Guid.NewGuid();
            newmodel.CreateTime = DateTime.Now;
            Users user = new Users_BLL().GetCurrentUser();

            newmodel.UserID      = user.UserID;
            newmodel.IsConfigure = false;

            OfficialAccount_BLL bll = new OfficialAccount_BLL();

            if (bll.Add(newmodel) > 0)
            {
                return(RedirectToAction("Select"));
            }
            else
            {
                ModelState.AddModelError("", "添加失败,请稍后再试!");
                return(View(model));
            }
        }
        /// <summary>
        /// 关注事件
        /// </summary>
        /// <param name="requestMessage"></param>
        public void Subscribe(RequestMessageEvent_Subscribe requestMessage)
        {
            OfficialAccount_BLL obll  = new OfficialAccount_BLL();
            OfficialAccount     model = obll.Get(a => a.OriginalID == requestMessage.ToUserName);

            if (!AccessTokenContainer.CheckRegistered(model.AppID))          //检查是否已经注册
            {
                AccessTokenContainer.Register(model.AppID, model.AppSecret); //如果没有注册则进行注册
            }
            Senparc.Weixin.MP.AdvancedAPIs.User.UserInfoJson uij = UserApi.Info(model.AppID, requestMessage.FromUserName);

            bool isInArea = false;

            if (model.AreaLimit != null)
            {
                if (model.AreaLevel == "国家" && model.AreaLimit.Contains(uij.country))
                {
                    isInArea = true;
                }
                if (model.AreaLevel == "省份" && model.AreaLimit.Contains(uij.province))
                {
                    isInArea = true;
                }
                if (model.AreaLevel == "城市" && model.AreaLimit.Contains(uij.city))
                {
                    isInArea = true;
                }
            }
            else
            {
                isInArea = true;
            }
            if (!isInArea)
            {
                try
                {
                    Senparc.Weixin.MP.AdvancedAPIs.CustomApi.SendText(model.AppID, uij.openid, "对不起,该活动只限" + model.AreaLimit + "地区用户!");
                }
                catch (Exception e)
                {
                }
            }

            //判断返回体是否带有参数
            bool hasPara = !string.IsNullOrWhiteSpace(requestMessage.EventKey);


            string         popenid = hasPara ? requestMessage.EventKey.Substring(8) : null;
            Subscriber_BLL bll     = new Subscriber_BLL();

            //扫码者是否存在
            if (bll.GetCount(a => a.OpenID == uij.openid && a.AccountID == model.AccountID) > 0)
            {
                //如果存在(指的是数据库中有没有用的信息)
                Subscriber sub = bll.Get(a => a.OpenID == uij.openid && a.AccountID == model.AccountID);
                if (sub.IsOK == true)
                {
                    sub.FromOpenID = popenid;
                    bll.Update(sub);

                    //如果已关注
                    //Senparc.Weixin.MP.AdvancedAPIs.CustomApi.SendText(model.AppID, sub.OpenID, model.ReSubscribeWelcome);//吃菊
                }
                else
                {
                    //如果已取消关注
                    sub.FromOpenID = popenid;
                    sub.IsOK       = true;
                    bll.Update(sub);
                    try
                    {
                        CustomApi.SendText(model.AppID, sub.OpenID, model.ReSubscribeWelcome);
                    }
                    catch (Exception e)
                    {
                    }

                    //再次关注发送消息
                }
            }
            else
            {
                //如果不存在



                //添加扫码者信息
                Subscriber sub = new Subscriber
                {
                    SubscribeID         = Guid.NewGuid(),
                    AccountID           = model.AccountID,
                    NickName            = uij.nickname,
                    Province            = uij.province,
                    City                = uij.city,
                    Country             = uij.country,
                    OpenID              = uij.openid,
                    Sex                 = uij.sex,
                    HeadImgUrl          = uij.headimgurl,
                    FromOpenID          = popenid,
                    SubscribeTime       = DateTime.Parse("1970-01-01 08:00").AddSeconds(uij.subscribe_time),
                    Score               = 0,
                    SignScore           = 0,
                    DirectScore         = 0,
                    IndirectScore       = 0,
                    SignContinuityCount = 0,
                    UnSubscribeCount    = 0,
                    IsOK                = true
                };

                bll.Add(sub);
                //发送首次关注欢迎信息
                try
                {
                    CustomApi.SendText(model.AppID, sub.OpenID, model.SubscribeWelcome);
                }
                catch (Exception e)
                {
                }

                if (hasPara)
                {
                    //判断参数对应用户是否存在(第一级)
                    if (bll.GetCount(a => a.OpenID == popenid && a.AccountID == model.AccountID) > 0)
                    {
                        if (isInArea)
                        {
                            Subscriber psub = bll.Get(a => a.OpenID == popenid && a.AccountID == model.AccountID);
                            if (psub.DirectScore != null)
                            {
                                psub.DirectScore += model.SubscribeAddScore;
                            }
                            else
                            {
                                psub.DirectScore = model.SubscribeAddScore;
                            }
                            psub.DirectScoreUpdateTime =
                                DateTime.Parse("1970-01-01 08:00").AddSeconds(uij.subscribe_time);
                            if (psub.Score != null)
                            {
                                psub.Score += model.SubscribeAddScore;
                            }
                            else
                            {
                                psub.Score = model.SubscribeAddScore;
                            }

                            bll.Update(psub);

                            //发送第一级
                            StringBuilder msgp = new StringBuilder();
                            msgp.Append("恭喜,您有新的粉丝【" + uij.nickname + "】加入!\n");
                            msgp.Append("获得推广积分:" + model.SubscribeAddScore + "分,累计积分:" + psub.Score.ToString() + "分\n");
                            CustomApi.SendText(model.AppID, psub.OpenID, msgp.ToString());
                        }
                    }
                    else
                    {
                        if (isInArea)
                        {
                            //第一级用户不存在,需要补充信息
                            Senparc.Weixin.MP.AdvancedAPIs.User.UserInfoJson puij = UserApi.Info(model.AppID, popenid);
                            //补充上一级信息
                            Subscriber psub = new Subscriber
                            {
                                SubscribeID           = Guid.NewGuid(),
                                AccountID             = model.AccountID,
                                NickName              = puij.nickname,
                                Province              = puij.province,
                                City                  = puij.city,
                                Country               = puij.country,
                                OpenID                = puij.openid,
                                Sex                   = puij.sex,
                                HeadImgUrl            = puij.headimgurl,
                                SubscribeTime         = DateTime.Parse("1970-01-01 08:00").AddSeconds(puij.subscribe_time),
                                Score                 = model.SubscribeAddScore,
                                SignScore             = 0,
                                DirectScore           = model.SubscribeAddScore,
                                DirectScoreUpdateTime = sub.SubscribeTime,
                                IndirectScore         = 0,
                                SignContinuityCount   = 0,
                                UnSubscribeCount      = 0,
                                IsOK                  = true
                            };

                            bll.Add(psub);
                            //发送第一级
                            StringBuilder msgp = new StringBuilder();
                            msgp.Append("恭喜,您有新的粉丝【" + uij.nickname + "】加入!\n");
                            msgp.Append("获得推广积分:" + model.SubscribeAddScore + "分,累计积分:" + psub.Score.ToString() + "分\n");
                            CustomApi.SendText(model.AppID, psub.OpenID, msgp.ToString());
                        }
                        else
                        {
                            //第一级用户不存在,需要补充信息
                            Senparc.Weixin.MP.AdvancedAPIs.User.UserInfoJson puij = UserApi.Info(model.AppID, popenid);
                            //补充上一级信息
                            Subscriber psub = new Subscriber
                            {
                                SubscribeID           = Guid.NewGuid(),
                                AccountID             = model.AccountID,
                                NickName              = puij.nickname,
                                Province              = puij.province,
                                City                  = puij.city,
                                Country               = puij.country,
                                OpenID                = puij.openid,
                                Sex                   = puij.sex,
                                HeadImgUrl            = puij.headimgurl,
                                SubscribeTime         = DateTime.Parse("1970-01-01 08:00").AddSeconds(puij.subscribe_time),
                                Score                 = 0,
                                SignScore             = 0,
                                DirectScore           = 0,
                                DirectScoreUpdateTime = sub.SubscribeTime,
                                IndirectScore         = 0,
                                SignContinuityCount   = 0,
                                UnSubscribeCount      = 0,
                                IsOK                  = true
                            };

                            bll.Add(psub);
                            //发送第一级
                        }
                    }
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// GetArticleByCategoryIndex
        /// </summary>
        /// <param name="categoryIndex">从0开始,首页分类,热门0, 推荐:1,段子手:2,养生堂:3,私房话:4  范围0-20 ?</param>
        /// <param name="page">页,从0开始</param>
        /// <remarks>get_recent_article_url_by_index_single</remarks>
        /// <returns></returns>
        public async Task <List <Article> > GetArticleByCategoryIndex(int categoryIndex, int page)
        {
            string pageStr; // "pc_" + page;

            if (page == 0)
            {
                pageStr = "pc_" + categoryIndex; //分类N第0页格式为xxxx/pc/pc_N/pc_N.html
            }
            else
            {
                pageStr = page.ToString();
            }

            //http://weixin.sogou.com/pcindex/pc/pc_4/pc_4.html //分类4第0页
            //http://weixin.sogou.com/pcindex/pc/pc_2/1.html //分类2第1页
            //http://weixin.sogou.com/pcindex/pc/pc_3/2.html //分类3第2页

            string url  = "http://weixin.sogou.com/pcindex/pc/pc_" + categoryIndex + '/' + pageStr + ".html";
            string text = await _browser.GetPageAsync(url);

            var pageDoc = new HtmlDocument();

            pageDoc.LoadHtml(text);
            var targetXpath = page == 0 ? "//ul[@class='news-list']/li" : "li";

            var targetArea = pageDoc.DocumentNode.SelectNodes(targetXpath);

            var listArticle = new List <Article>();

            if (targetArea == null)
            {
                return(null);
            }

            foreach (var li in targetArea)
            {
                var article = new Article()
                {
                    Imgs = new List <string>()
                };
                var account = new OfficialAccount();
                try
                {
                    article.Title = li.SelectSingleNode("div[2]/h3/a").InnerText;
                    article.Url   = li.SelectSingleNode("div[1]/a").GetAttributeValue("href", "");
                    article.Brief =
                        WebUtility.HtmlDecode(li.SelectSingleNode("div[2]/p[@class='txt-info']").InnerText);
                    string coverImg = li.SelectSingleNode("div[1]/a/img").GetAttributeValue("src", "");
                    if (!string.IsNullOrEmpty(coverImg))
                    {
                        article.Imgs.Add(coverImg);
                    }

                    article.Time           = li.SelectSingleNode("div[2]/div/span").GetAttributeValue("t", "");
                    article.ArticleListUrl = li.SelectSingleNode("div[2]/div/a").GetAttributeValue("href", "");

                    account.AccountPageurl = li.SelectSingleNode("div[2]/div/a").GetAttributeValue("href", "");
                    account.Name           = li.SelectSingleNode("div[2]/div/a").InnerText;
                    string isV = li.SelectSingleNode("div[2]/div/a").GetAttributeValue("data-isv", "");
                    account.IsAuth         = isV == "1";
                    account.ProfilePicture =
                        li.SelectSingleNode("div[2]/div/a").GetAttributeValue("data-headimage", "");

                    article.OfficialAccount = account;
                    listArticle.Add(article);
                }
                catch (Exception e)
                {
                    _logger.Error(e);
                }
            }


            return(listArticle);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 搜索微信文章
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public async Task <List <Article> > SearchArticleAsync(string keyword, int page = 1)
        {
            var articleList = new List <Article>();
            //string text = this._SearchArticle_Html(keyword, page);
            string text = await SearchArticleHtmlAsync(keyword, page);

            var pageDoc = new HtmlDocument();

            pageDoc.LoadHtml(text);
            //todo
            var targetArea = pageDoc.DocumentNode.SelectNodes("//ul[@class='news-list']/li");

            foreach (var node in targetArea)
            {
                try
                {
                    string url =
                        WebUtility.HtmlDecode(node.SelectSingleNode("div[2]/h3/a").GetAttributeValue("href", ""));
                    string title;
                    var    imgs = new List <string>();
                    string brief;
                    string time;
                    var    account = new OfficialAccount();


                    if (!string.IsNullOrEmpty(url))
                    {
                        title = node.SelectSingleNode("div[2]/h3/a").InnerText;
                        string img =
                            WebUtility.HtmlDecode(node.SelectSingleNode("div[1]/a/img").GetAttributeValue("src", ""));
                        imgs.Add(img);
                        brief = node.SelectSingleNode("div[2]/p").InnerHtml;
                        time  = node.SelectSingleNode("div[2]/div/span/script/text()").InnerHtml;
                        if (node.SelectSingleNode("div[@class='txt-box']/div[@class='s-p']/a") != null)
                        {
                            account.IsAuth = Convert.ToBoolean(Convert.ToInt16(node
                                                                               .SelectSingleNode("div[@class='txt-box']/div[@class='s-p']/a")
                                                                               .GetAttributeValue("data-isv", "")));
                        }

                        account.AccountPageurl = WebUtility.HtmlDecode(node
                                                                       .SelectSingleNode("div[@class='txt-box']/h3/a").GetAttributeValue("href", ""));
                        if (node.SelectSingleNode("div/div[2]/a") != null)
                        {
                            account.ProfilePicture = WebUtility.HtmlDecode(node.SelectSingleNode("div/div[2]/a")
                                                                           .GetAttributeValue("data-headimage", ""));
                        }

                        if (node.SelectSingleNode("div/div[2]/a") != null)
                        {
                            account.Name = node.SelectSingleNode("div/div[2]/a").InnerText;
                        }
                    }
                    else
                    {
                        url   = WebUtility.HtmlDecode(node.SelectSingleNode("div/h3/a").GetAttributeValue("href", ""));
                        title = node.SelectSingleNode("div/h3/a").InnerText;
                        var spansNodeCollection = node.SelectNodes("div/div[1]/a");
                        foreach (var span in spansNodeCollection)
                        {
                            string img = WebUtility.HtmlDecode(span.SelectSingleNode("span/img/@src").InnerText);
                            if (!string.IsNullOrEmpty(img))
                            {
                                imgs.Add(img);
                            }
                        }

                        brief = node.SelectSingleNode("div/p").InnerText;
                        time  = node.SelectSingleNode("div/div[2]/span/script/text()").InnerText;
                        if (node.SelectSingleNode("div/div[2]/a") != null)
                        {
                            account.IsAuth = Convert.ToBoolean(node.SelectSingleNode("div/div[2]/a")
                                                               .GetAttributeValue("data-isv", ""));
                        }

                        account.AccountPageurl =
                            WebUtility.HtmlDecode(node.SelectSingleNode("div/div[2]/a").GetAttributeValue("href", ""));
                        account.ProfilePicture = WebUtility.HtmlDecode(node.SelectSingleNode("div/div[2]/a")
                                                                       .GetAttributeValue("data-headimage", ""));
                        if (node.SelectSingleNode("div/div[2]/a") != null)
                        {
                            account.Name = node.SelectSingleNode("div/div[2]/a").InnerText;
                        }
                    }


                    title = string.IsNullOrEmpty(title)
                        ? ""
                        : title.Trim().Replace("<!--red_beg-->", "").Replace("<!--red_end-->", "")
                            .Replace("<em>", "").Replace("</em>", "");

                    brief = string.IsNullOrEmpty(brief)
                        ? ""
                        : brief.Trim().Replace("<!--red_beg-->", "").Replace("<!--red_end-->", "").Replace("<em>", "")
                            .Replace("</em>", "");

                    var timeRegex = new Regex(@"timeConvert\('(?(time)<1>(\d+))'\)");
                    time = timeRegex.Match(time).Groups[1].Value;

                    var article = new Article
                    {
                        Title           = title,
                        Brief           = brief,
                        Url             = url,
                        Imgs            = imgs,
                        Time            = time,
                        OfficialAccount = account
                    };
                    articleList.Add(article);
                }
                catch (Exception e)
                {
                    _logger.Error(e);
                }
            }

            return(articleList);
        }
Ejemplo n.º 21
0
        public void CreateHaiBao(string fromUser, string toUser, string temppath)
        {
            OfficialAccount_BLL obll = new OfficialAccount_BLL();
            //OfficialAccount model = obll.Get(a => a.OriginalID == toUser);
            OfficialAccount model = obll.Get(a => a.OriginalID == "gh_9229f06559cd");



            if (!AccessTokenContainer.CheckRegistered(model.AppID))          //检查是否已经注册
            {
                AccessTokenContainer.Register(model.AppID, model.AppSecret); //如果没有注册则进行注册
            }
            try
            {
                Account_QRCode_Template aqt =
                    new Account_QRCode_Template_BLL().GetList(a => a.AccountID == model.AccountID)
                    .OrderByDescending(a => a.CreateTime)
                    .FirstOrDefault();

                QRCode_Template temp = new QRCode_Template_BLL().Get(a => a.TemplateID == aqt.TemplateID);



                DateTime now = DateTime.Now.AddMinutes(-2);
                WS.Utility.FileHelper.DeleteFilesBeforeTime(temppath, now);



                WebClient    wc = new WebClient();
                ICredentials cred;
                cred = new NetworkCredential("user-22", "user-22");

                WebProxy wp = new WebProxy("http://172.18.226.109:808/", true, null, cred);
                wc.Proxy = wp;
                //下载原图
                //string yuanfilename = Guid.NewGuid().ToString() + ".png";
                string yuanlocalfilename =
                    temppath + Guid.NewGuid().ToString() + ".jpg";
                //wc.DownloadFile(ConfigurationManager.AppSettings["QiNiuDomain"] + model.QRCodeBgImg, yuanlocalfilename);
                wc.DownloadFile("http://qiniu.weixin.hairuiit.com/" + aqt.QRCodeBgImg, yuanlocalfilename);


                Senparc.Weixin.MP.AdvancedAPIs.User.UserInfoJson uij =
                    Senparc.Weixin.MP.AdvancedAPIs.UserApi.Info(model.AppID, fromUser);
                //加入昵称
                string savename1 = temppath + Guid.NewGuid().ToString() + ".jpg";
                ImageHelper.Add_FontMark(yuanlocalfilename, savename1, uij.nickname, temp.NickName_FontFamily, (int)temp.NickName_FontSize, Color.Black, (int)temp.NickName_FontX, (int)temp.NickName_FontY);

                //下载头像
                string touxiang = temppath + Guid.NewGuid().ToString() + ".png";
                wc.DownloadFile(uij.headimgurl, touxiang);
                //下载二维码
                // Senparc.Weixin.MP.AdvancedAPIs.QrCode.CreateQrCodeResult createQrCodeResult =QrCodeApi.CreateByStr(model.AppID, fromUser);
                Senparc.Weixin.MP.AdvancedAPIs.QrCode.CreateQrCodeResult createQrCodeResult = QrCodeApi.Create(model.AppID, 0, 0, Senparc.Weixin.MP.QrCode_ActionName.QR_LIMIT_STR_SCENE, fromUser);
                string localcodefile =
                    temppath + Guid.NewGuid().ToString() + ".png";
                wc.DownloadFile(QrCodeApi.GetShowQrCodeUrl(createQrCodeResult.ticket), localcodefile);
                wc.Dispose();

                ///加头像

                string savename2 = temppath + Guid.NewGuid().ToString() + ".jpg";

                ImageHelper.Add_ImageMark(savename1, touxiang, savename2, (int)temp.HeadImg_X, (int)temp.HeadImg_Y, (int)temp.HeadImg_Width, (int)temp.HeadImg_Height);



                string savename3 = temppath + Guid.NewGuid().ToString() + ".jpg";

                ImageHelper.Add_ImageMark(savename2, localcodefile, savename3, (int)temp.QRCode_X, (int)temp.QRCode_Y, (int)temp.QRCode_Width, (int)temp.QRCode_Height);

                Senparc.Weixin.MP.AdvancedAPIs.Media.UploadTemporaryMediaResult media =
                    Senparc.Weixin.MP.AdvancedAPIs.MediaApi.UploadTemporaryMedia(model.AppID,
                                                                                 Senparc.Weixin.MP.UploadMediaFileType.image, savename3);

                Senparc.Weixin.MP.AdvancedAPIs.CustomApi.SendText(model.AppID, fromUser,
                                                                  "专属海报已经接收成功,请保存到手机相册,分享海报兑换奖品哦!");
                Senparc.Weixin.MP.AdvancedAPIs.CustomApi.SendImage(model.AppID, fromUser,
                                                                   media.media_id);


                Thread.Sleep(6000);
                WS.Utility.FileHelper.Delete(yuanlocalfilename);
                WS.Utility.FileHelper.Delete(savename1);
                WS.Utility.FileHelper.Delete(savename2);
                WS.Utility.FileHelper.Delete(savename3);
                WS.Utility.FileHelper.Delete(touxiang);
                WS.Utility.FileHelper.Delete(localcodefile);


                //var responseMessage = this.CreateResponseMessage<ResponseMessageText>();
                //responseMessage.Content = "生成成功";
                //return responseMessage;

                //return null;
            }
            catch (Exception ex)
            {
                //LogHelper.ErrorInfo(ex);
                //Senparc.Weixin.MP.AdvancedAPIs.CustomApi.SendText(model.AppID, requestMessage.FromUserName,
                //    ex.Message.ToString());
                Senparc.Weixin.MP.AdvancedAPIs.CustomApi.SendText(model.AppID, fromUser,
                                                                  ex.ToString());
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// GetArticleByCategoryIndex
        /// </summary>
        /// <param name="categoryIndex">从0开始,首页分类,热门0, 推荐:1,段子手:2,养生堂:3,私房话:4  范围0-20 ?</param>
        /// <param name="page">页,从0开始</param>
        /// <remarks>get_recent_article_url_by_index_single</remarks>
        /// <returns></returns>
        public List <Article> GetArticleByCategoryIndex(int categoryIndex, int page)
        {
            string pageStr = "";// "pc_" + page;

            if (page == 0)
            {
                pageStr = "pc_" + categoryIndex; //分类N第0页格式为xxxx/pc/pc_N/pc_N.html
            }
            else
            {
                pageStr = page.ToString();
            }

            //http://weixin.sogou.com/pcindex/pc/pc_4/pc_4.html //分类4第0页
            //http://weixin.sogou.com/pcindex/pc/pc_2/1.html //分类2第1页
            //http://weixin.sogou.com/pcindex/pc/pc_3/2.html //分类3第2页

            string url = "http://weixin.sogou.com/pcindex/pc/pc_" + categoryIndex + '/' + pageStr + ".html";
            WebHeaderCollection headers = new WebHeaderCollection();

            headers.Add("Host", "weixin.sogou.com");
            headers.Add("Referer", "http://weixin.sogou.com/");
            headers.Add("Accept", "*/*");
            HttpHelper NetHelper = new HttpHelper();
            string     text      = NetHelper.Get(headers, url, "UTF-8");

            HtmlDocument pageDoc = new HtmlDocument();

            pageDoc.LoadHtml(text);
            string targetXpath = "";

            if (page == 0)
            {
                targetXpath = "//ul[@class='news-list']/li";
            }
            else
            {
                targetXpath = "li";
            }
            var targetArea = pageDoc.DocumentNode.SelectNodes(targetXpath);

            List <Article> ListArticle = new List <Article>();

            if (targetArea != null)
            {
                foreach (var li in targetArea)
                {
                    try
                    {
                        Article article = new Article()
                        {
                            Imgs = new List <string>()
                        };
                        OfficialAccount account = new OfficialAccount();
                        article.Title = li.SelectSingleNode("div[2]/h3/a").InnerText;
                        article.Url   = li.SelectSingleNode("div[1]/a").GetAttributeValue("href", "");
                        article.Brief = WebUtility.HtmlDecode(li.SelectSingleNode("div[2]/p[@class='txt-info']").InnerText);
                        string coverImg = li.SelectSingleNode("div[1]/a/img").GetAttributeValue("src", "");
                        if (!string.IsNullOrEmpty(coverImg))
                        {
                            article.Imgs.Add(coverImg);
                        }

                        article.Time           = li.SelectSingleNode("div[2]/div/span").GetAttributeValue("t", "");
                        article.ArticleListUrl = li.SelectSingleNode("div[2]/div/a").GetAttributeValue("href", "");

                        account.AccountPageurl = li.SelectSingleNode("div[2]/div/a").GetAttributeValue("href", "");
                        account.Name           = li.SelectSingleNode("div[2]/div/a").InnerText;
                        string isV = li.SelectSingleNode("div[2]/div/a").GetAttributeValue("data-isv", "");
                        if (isV == "1")
                        {
                            account.IsAuth = true;
                        }
                        else
                        {
                            account.IsAuth = false;
                        }
                        account.ProfilePicture = li.SelectSingleNode("div[2]/div/a").GetAttributeValue("data-headimage", "");


                        article.officialAccount = account;
                        ListArticle.Add(article);
                    }
                    catch (Exception e)
                    {
                        logger.Error(e);
                    }
                }
            }



            return(ListArticle);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 获取公众号微信号wechatid的信息 (实际上就是搜索公众号id,获取第一个结果)
        /// wechatid: 公众号id
        /// 因为wechatid唯一确定,所以第一个就是要搜索的公众号
        ///
        /// </summary>
        /// <param name="wechatid"></param>
        /// <returns></returns>
        public OfficialAccount GetAccountInfoById(string wechatid)
        {
            OfficialAccount info = this.SearchOfficialAccount(wechatid, 1).FirstOrDefault(); //可能为空

            return(info);
        }