////[SupportFilter] public ActionResult Index() { WC_OfficalAccounts model = account_BLL.GetCurrentAccount(); ViewBag.CurrentOfficalAcount = model.OfficalName; return(View()); }
////[SupportFilter] // GET: WC/MenuSetting public ActionResult Index() { WC_OfficalAccounts model = account_BLL.GetCurrentAccount(); ViewBag.CurrentOfficalAcount = model; GetMenuResult result = new GetMenuResult(new ButtonGroup()); //初始化 for (int i = 0; i < 3; i++) { var subButton = new SubButton(); for (int j = 0; j < 5; j++) { var singleButton = new SingleClickButton(); subButton.sub_button.Add(singleButton); } } return(View(result)); }
/// <summary> /// /// </summary> /// <param name="returnUrl">用户尝试进入的需要登录的页面</param> /// <returns></returns> public ActionResult Index(string returnUrl) { WC_OfficalAccounts model = account_BLL.GetCurrentAccount(); //获取用户保存的cookie //判断是否已经授权过 var state = "HD-" + DateTime.Now.Millisecond; //随机数,用于识别请求可靠性 Session["State"] = state; //储存随机数到Session ViewData["returnUrl"] = returnUrl; //此页面引导用户点击授权 ViewData["UrlUserInfo"] = OAuthApi.GetAuthorizeUrl(model.AppId, "http://HD.imwork.net/WC/OAuth2/UserInfoCallback?returnUrl=" + returnUrl.UrlEncode(), state, OAuthScope.snsapi_userinfo); ViewData["UrlBase"] = OAuthApi.GetAuthorizeUrl(model.AppSecret, "http://HD.imwork.net/WC/OAuth2/BaseCallback?returnUrl=" + returnUrl.UrlEncode(), state, OAuthScope.snsapi_base); return(View()); }
/// <summary> /// 订阅(关注)事件 /// </summary> /// <returns></returns> public override IResponseMessageBase OnEvent_SubscribeRequest(RequestMessageEvent_Subscribe requestMessage) { ValidationErrors errors = new ValidationErrors(); WC_OfficalAccountsBLL account_BLL = new WC_OfficalAccountsBLL(); //获得当前公众号 WC_OfficalAccounts account = account_BLL.GetCurrentAccount(); //将用户提取到本地数据库 WC_User userModel = new WC_User(); WC_UserBLL user_BLL = new WC_UserBLL(); account.AccessToken = Senparc.Weixin.MP.CommonAPIs.CommonApi.GetToken(account.AppId, account.AppSecret).access_token; UserInfoJson userJson = UserApi.Info(account.AccessToken, requestMessage.FromUserName); userModel.OpenId = userJson.openid; userModel.NickName = userJson.nickname; userModel.Sex = userJson.sex.ToString(); userModel.Language = userJson.language; userModel.City = userJson.city; userModel.Province = userJson.province; userModel.Country = userJson.country; userModel.HeadImgUrl = userJson.headimgurl; userModel.SubscribeTime = ResultHelper.GetTimeByLong(userJson.subscribe_time).ToString(); userModel.UnionId = userJson.unionid; userModel.Remark = userJson.remark; userModel.GroupId = userJson.groupid.ToString(); userModel.TagidList = string.Join(",", userJson.tagid_list.ToArray()); userModel.Subscribe = userJson.subscribe.ToString(); userModel.OfficalAccountId = account.Id.ToString(); user_BLL.m_Rep.Create(userModel); WC_MessageResponseRepository m_Rep = new WC_MessageResponseRepository(); //订阅回复 List <WC_MessageResponse> messageList = m_Rep.FindList(a => a.OfficalAccountId == account.Id.ToString() && a.MessageRule == WeChatRequestRuleEnum.Subscriber.ToString() && a.IsDefault == "true").ToList(); if (messageList.Count() > 0) { if (messageList[0].Category == WeChatReplyCategory.Text.ToString()) { var responseMessage = base.CreateResponseMessage <ResponseMessageText>(); responseMessage.CreateTime = ResultHelper.NowTime; responseMessage.ToUserName = requestMessage.FromUserName; responseMessage.FromUserName = account.OfficalId; responseMessage.Content = messageList[0].TextContent; return(responseMessage); } //图文方式 else if (messageList[0].Category == WeChatReplyCategory.Image.ToString()) { var responseMessage = CreateResponseMessage <ResponseMessageNews>(); foreach (var model in messageList) { responseMessage.Articles.Add(new Article() { Title = model.TextContent, Description = model.ImgTextContext, PicUrl = WebChatPara.SiteUrl + model.ImgTextUrl, Url = model.ImgTextLink }); } return(responseMessage); } //一般很少用到 else if (messageList[0].Category == WeChatReplyCategory.Voice.ToString()) { var responseMessage = base.CreateResponseMessage <ResponseMessageMusic>(); responseMessage.Music.MusicUrl = WebChatPara.SiteUrl + messageList[0].MeidaUrl; responseMessage.Music.Title = messageList[0].TextContent; responseMessage.Music.Description = messageList[0].Remark; return(responseMessage); } } var errorResponseMessage = requestMessage.CreateResponseMessage <ResponseMessageText>(); return(errorResponseMessage); }