private void LoadFromServer() { AccessTokenResult token = CommonApi.GetToken(SinGooCMS.Weixin.Config.AppID, SinGooCMS.Weixin.Config.AppSecret, "client_credential"); string strUrl = string.Format("https://api.weixin.qq.com/cgi-bin/menu/get?access_token={0}", token.access_token); string strValue = NetWorkUtils.HttpGet(strUrl); GetMenuResultFull getMenuResultFull = JsonUtils.JsonToObject <GetMenuResultFull>(strValue); if (getMenuResultFull != null && getMenuResultFull.menu != null && getMenuResultFull.menu.button.Count > 0) { WxMenu.EmptyLocal(); int num = 1; foreach (MenuFull_RootButton current in getMenuResultFull.menu.button) { WxMenuInfo wxMenuInfo = new WxMenuInfo { RootID = 0, ParentID = 0, Type = (current.type ?? string.Empty), Name = current.name, EventKey = (current.key ?? string.Empty), Url = (current.url ?? string.Empty), ChildCount = 0, ChildIDs = string.Empty, Sort = num, AutoTimeStamp = System.DateTime.Now }; int num2 = WxMenu.Add(wxMenuInfo); if (num2 > 0) { wxMenuInfo.AutoID = num2; wxMenuInfo.RootID = num2; num++; if (current.sub_button != null && current.sub_button.Count > 0) { wxMenuInfo.ChildCount = current.sub_button.Count; int num3 = 1; foreach (MenuFull_RootButton current2 in current.sub_button) { WxMenuInfo entity = new WxMenuInfo { RootID = num2, ParentID = num2, Type = (current2.type ?? string.Empty), Name = current2.name, EventKey = (current2.key ?? string.Empty), Url = (current2.url ?? string.Empty), ChildCount = 0, ChildIDs = string.Empty, Sort = num3, AutoTimeStamp = System.DateTime.Now }; int num4 = WxMenu.Add(entity); if (num4 > 0) { WxMenuInfo expr_27E = wxMenuInfo; expr_27E.ChildIDs = expr_27E.ChildIDs + num4 + ","; num3++; } } } if (wxMenuInfo.ChildIDs.EndsWith(",")) { wxMenuInfo.ChildIDs = wxMenuInfo.ChildIDs.TrimEnd(new char[] { ',' }); } WxMenu.Update(wxMenuInfo); } } } this.BindData(); }
protected void btnok_Click(object sender, System.EventArgs e) { if (base.Action.Equals(ActionType.Add.ToString()) && !base.IsAuthorizedOp(ActionType.Add.ToString())) { base.ShowMsg("Không có thẩm quyền"); } else if (base.Action.Equals(ActionType.Modify.ToString()) && !base.IsAuthorizedOp(ActionType.Modify.ToString())) { base.ShowMsg("Không có thẩm quyền"); } else { WxMenuInfo wxMenuInfo = new WxMenuInfo(); if (base.IsEdit) { wxMenuInfo = WxMenu.GetDataById(base.OpID); } wxMenuInfo.ParentID = WebUtils.GetInt(this.parentmenu.SelectedValue); wxMenuInfo.Name = WebUtils.GetString(this.menuname.Text); wxMenuInfo.Type = this.menutype.SelectedValue; wxMenuInfo.Url = WebUtils.GetString(this.TextBox4.Text); wxMenuInfo.EventKey = string.Empty; AutoRlyInfo autoRlyInfo = new AutoRlyInfo { RlyType = "事件回复", MsgKey = StringUtils.GetRandomNumber(), MsgText = WebUtils.GetString(this.TextBox1.Text), MediaPath = WebUtils.GetString(this.TextBox2.Text), Description = WebUtils.GetString(this.TextBox3.Text), LinkUrl = WebUtils.GetString(this.TextBox4.Text) }; if (string.IsNullOrEmpty(wxMenuInfo.Name)) { base.ShowMsg("菜单名称不能为空"); } else if (wxMenuInfo.ParentID == 0 && wxMenuInfo.Name.Length > 4) { base.ShowMsg("一级菜单文字长度不超过4个汉字"); } else if (wxMenuInfo.ParentID > 0 && wxMenuInfo.Name.Length > 8) { base.ShowMsg("二级菜单文字长度不超过8个汉字"); } else if (wxMenuInfo.Type == "click" && string.IsNullOrEmpty(autoRlyInfo.MsgText)) { base.ShowMsg("图文推送文本不能为空"); } else if (wxMenuInfo.Type == "click" && (autoRlyInfo.MsgText.Length > 600 || autoRlyInfo.Description.Length > 600)) { base.ShowMsg("推送图文中的文本不能超过600汉字"); } else if (wxMenuInfo.Type == "view" && string.IsNullOrEmpty(autoRlyInfo.LinkUrl)) { base.ShowMsg("地址跳转的地址不能为空"); } else { if (base.Action.Equals(ActionType.Add.ToString())) { wxMenuInfo.Sort = WxMenu.MaxSort + 1; wxMenuInfo.AutoTimeStamp = System.DateTime.Now; WxStatus wxStatus = WxMenu.Add(wxMenuInfo, autoRlyInfo); if (wxStatus == WxStatus.增加成功) { PageBase.log.AddEvent(base.LoginAccount.AccountName, "添加微信菜单[" + wxMenuInfo.Name + "] thành công"); MessageUtils.DialogCloseAndParentReload(this); } else { base.ShowMsg(wxStatus.ToString()); } } if (base.Action.Equals(ActionType.Modify.ToString())) { WxStatus wxStatus2 = WxMenu.Update(wxMenuInfo, autoRlyInfo); if (wxStatus2 == WxStatus.修改成功) { PageBase.log.AddEvent(base.LoginAccount.AccountName, "修改微信菜单[" + wxMenuInfo.Name + "] thành công"); MessageUtils.DialogCloseAndParentReload(this); } else { base.ShowMsg(wxStatus2.ToString()); } } } } }