private void ComposeMenu() { _group = new ButtonGroup(); //报表 SubButton subBtn1 = new SubButton(); subBtn1.name = "管理"; //SingleViewButton btn11 = new SingleViewButton(); //btn11.url = "http://180.169.11.53/senlan2.weixin/pages/inventory.html"; SingleClickButton btn11 = new SingleClickButton(); btn11.key = "btnReport"; btn11.name = "报表"; SingleClickButton btn12 = new SingleClickButton(); btn12.name = "账号绑定"; btn12.key = "btnBind"; subBtn1.sub_button.Add(btn11); subBtn1.sub_button.Add(btn12); _group.button.Add(subBtn1); //审批中心 SubButton subBtn2 = new SubButton(); subBtn2.name = "审批中心"; //SingleViewButton btn21 = new SingleViewButton(); //btn21.url = "http://180.169.11.53/senlan2.weixin/pages/approval_contract.html"; SingleClickButton btn21 = new SingleClickButton(); btn21.name = "待审合同"; btn21.key = "btn_approval_contract"; //SingleViewButton btn22 = new SingleViewButton(); //btn22.url = "http://180.169.11.53/senlan2.weixin/pages/approval_paymentrequest.html"; SingleClickButton btn22 = new SingleClickButton(); btn22.name = "待审付款申请"; btn22.key = "btn_approval_paymentrequest"; SingleClickButton btn23 = new SingleClickButton(); btn23.name = "审批推送订阅"; btn23.key = "btn_customer_service"; subBtn2.sub_button.Add(btn21); subBtn2.sub_button.Add(btn22); subBtn2.sub_button.Add(btn23); _group.button.Add(subBtn2); //交易下单 //SingleViewButton btn31 = new SingleViewButton(); //btn31.url = "http://180.169.11.53/senlan2.weixin/pages/add_contract.html"; SubButton subBtn3 = new SubButton(); subBtn3.name = "业务单据"; SingleClickButton btn31 = new SingleClickButton(); btn31.name = "合同"; btn31.key = "btn_Contract"; subBtn3.sub_button.Add(btn31); _group.button.Add(subBtn3); }
private static SingleClickButton GetSingleButtonFromJsonObject(Dictionary<string, object> objs) { var sb = new SingleClickButton() { key = objs["key"] as string, name = objs["name"] as string, type = objs["type"] as string }; return sb; }
public void CreateMenuFesco() { //Console.WriteLine("************************************开始创建微信菜单*******************************************************\n"); string appid = "wx82315287d9fc52ae"; string secret = "00dbe4ae7304f61ef9f77c7bd8fc0f48"; string PROJECT_NAME = "FESCOAsecco"; string PROJECT_URL = "weixin.hrone.cn"; var accessToken = AccessTokenContainer.TryGetAccessToken(appid, secret); Console.WriteLine(" accessToken:" + accessToken + "\n"); ButtonGroup bg = new ButtonGroup(); //首页 var About = new SingleClickButton() { name = "账户绑定", key = "bind_account", type = ButtonType.click.ToString(), }; bg.button.Add(About); //我的 var AboutMe = new SubButton() { name = "我的信息" }; AboutMe.sub_button.Add(new SingleViewButton() { url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME + "%2FView%2FCommUtil%2FLoading.html?pageType=10009&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", name = "个人信息" }); AboutMe.sub_button.Add(new SingleViewButton() { url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME + "%2FView%2FCommUtil%2FLoading.html?pageType=10011&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", name = "银行信息" }); bg.button.Add(AboutMe); //申请&签核 var ApplyAndApprove = new SingleViewButton() { name = "进入系统", type = ButtonType.view.ToString(), url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME + "%2FView%2FCommUtil%2FMenuLoading.html&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect" }; bg.button.Add(ApplyAndApprove); var result = CommonApi.CreateMenu(accessToken, bg); Console.WriteLine(" Errcode: " + result.errcode + "\n\n Errmsg: " + result.errmsg + "\n\n P2PData: " + result.P2PData + "\n"); Console.WriteLine("************************************创建微信菜单结束*******************************************************\n"); Console.ReadKey(); }
// // GET: /Menu/ public ActionResult Index() { 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); }
MenuMgr mMrg = new MenuMgr(); //创建菜单类 #endregion Fields #region Methods //保存 protected void btnSubmit_Click(object sender, EventArgs e) { try { string error = string.Empty; string accessToken = cpp.GetAccessToken(this.id, out error); if (!string.IsNullOrEmpty(error)) { JscriptMsg(error, string.Empty); return; } //重新整理按钮信息 ButtonGroup bg = new ButtonGroup(); TextBox txtName = new TextBox(); TextBox txtKey = new TextBox(); TextBox txtUrl = new TextBox(); IList<BaseButton> topList = new List<BaseButton>(); IList<SingleButton> subList = new List<SingleButton>(); //菜单设置 for (int i = 0; i < 3; i++) { txtName = this.FindControl("txtTop" + (i + 1) + "Name") as TextBox; txtKey = this.FindControl("txtTop" + (i + 1) + "Key") as TextBox; txtUrl = this.FindControl("txtTop" + (i + 1) + "Url") as TextBox; if (txtName.Text.Trim() == "") { // 如果名称为空,则忽略该菜单,以及下面的子菜单 continue; } subList = new List<SingleButton>(); TextBox txtSubName = new TextBox(); TextBox txtSubKey = new TextBox(); TextBox txtSubUrl = new TextBox(); for (int j = 0; j < 5; j++) { //子菜单的设置 txtSubName = this.FindControl("txtMenu" + (i + 1) + (j + 1) + "Name") as TextBox; txtSubKey = this.FindControl("txtMenu" + (i + 1) + (j + 1) + "Key") as TextBox; txtSubUrl = this.FindControl("txtMenu" + (i + 1) + (j + 1) + "Url") as TextBox; if (txtSubName.Text.Trim() == "") { continue; } if (txtSubUrl.Text.Trim() != "") { SingleViewButton sub = new SingleViewButton(); sub.name = txtSubName.Text.Trim(); sub.url = txtSubUrl.Text.Trim(); subList.Add(sub); } else if (txtSubKey.Text.Trim() != "") { SingleClickButton sub = new SingleClickButton(); sub.name = txtSubName.Text.Trim(); sub.key = txtSubKey.Text.Trim(); subList.Add(sub); } else { //报错 :子菜单必须有key和name JscriptMsg("二级菜单的名称和key或者url必填!", string.Empty); return; } } if (subList != null && subList.Count > 0) { //有子菜单, 该一级菜单是SubButton if (subList.Count < 1) { JscriptMsg("子菜单个数必须为2至5个!", string.Empty); return; } SubButton topButton = new SubButton(Utils.CutString(txtName.Text.Trim(), 16)); topButton.sub_button.AddRange(subList); topList.Add(topButton); } else { // 无子菜单 if (txtKey.Text.Trim() == "" && txtUrl.Text.Trim() == "") { JscriptMsg("如无子菜单,必须填写Key或者URL值!", string.Empty); return; } if (txtUrl.Text.Trim() != "") { //view 页面跳转 SingleViewButton topSingleButton = new SingleViewButton(); topSingleButton.name = txtName.Text.Trim(); topSingleButton.url = txtUrl.Text.Trim(); topList.Add(topSingleButton); } else if (txtKey.Text.Trim() != "") { SingleClickButton topSingleButton = new SingleClickButton(); topSingleButton.name = txtName.Text.Trim(); topSingleButton.key = txtKey.Text.Trim(); topList.Add(topSingleButton); } } } bg.button.AddRange(topList); var result = mMrg.CreateMenu(accessToken, bg); JscriptMsg("自定义菜单保存成功!", "menu_list.aspx"); } catch (Exception ex) { JscriptMsg("出错了:" + ex.Message, string.Empty); } }
/// <summary> /// 更新菜单 /// </summary> protected void btnSubmit_Click(object sender, EventArgs e) { try { Model.wx_userweixin weixin = GetWeiXinCode(); string error = ""; string accessToken = cpp.getAccessToken(weixin.id, out error); if (error != "") { JscriptMsg(error, "", "Error"); return; } //重新整理按钮信息 ButtonGroup bg = new ButtonGroup(); TextBox txtName = new TextBox(); TextBox txtKey = new TextBox(); TextBox txtUrl = new TextBox(); IList<BaseButton> topList = new List<BaseButton>(); IList<SingleButton> subList = new List<SingleButton>(); #region 菜单设置 for (int i = 0; i < 3; i++) { txtName = this.FindControl("txtTop" + (i + 1)) as TextBox; txtKey = this.FindControl("txtTop" + (i + 1) + "Key") as TextBox; txtUrl = this.FindControl("txtTop" + (i + 1) + "Url") as TextBox; if (txtName.Text.Trim() == "") { // 如果名称为空,则忽略该菜单,以及下面的子菜单 continue; } subList = new List<SingleButton>(); TextBox txtSubName = new TextBox(); TextBox txtSubKey = new TextBox(); TextBox txtSubUrl = new TextBox(); for (int j = 0; j < 5; j++) { #region 子菜单的设置 txtSubName = this.FindControl("txtMenu" + (i + 1) + (j + 1)) as TextBox; txtSubKey = this.FindControl("txtMenu" + (i + 1) + (j + 1) + "Key") as TextBox; txtSubUrl = this.FindControl("txtMenu" + (i + 1) + (j + 1) + "Url") as TextBox; if (txtSubName.Text.Trim() == "") { continue; } if (txtSubUrl.Text.Trim() != "") { SingleViewButton sub = new SingleViewButton(); sub.name = txtSubName.Text.Trim(); sub.url = txtSubUrl.Text.Trim(); subList.Add(sub); } else if (txtSubKey.Text.Trim() != "") { SingleClickButton sub = new SingleClickButton(); sub.name = txtSubName.Text.Trim(); sub.key = txtSubKey.Text.Trim(); subList.Add(sub); } else { //报错 :子菜单必须有key和name JscriptMsg("二级菜单的名称和key或者url必填!", "", "Error"); return; } #endregion } //子菜单循环结束 if (subList != null && subList.Count > 0) { //有子菜单, 该一级菜单是SubButton if (subList.Count < 1) { JscriptMsg("子菜单个数为2~5个!", "", "Error"); return; } SubButton topButton = new SubButton(Utils.CutString(txtName.Text.Trim(), 16)); topButton.sub_button.AddRange(subList); topList.Add(topButton); } else { // 无子菜单 if (txtKey.Text.Trim() == "" && txtUrl.Text.Trim() == "") { JscriptMsg("若无子菜单,必须填写key或者url值!", "", "Error"); return; } if (txtUrl.Text.Trim() != "") { //view 页面跳转 SingleViewButton topSingleButton = new SingleViewButton(); topSingleButton.name = txtName.Text.Trim(); topSingleButton.url = txtUrl.Text.Trim(); topList.Add(topSingleButton); } else if (txtKey.Text.Trim() != "") { SingleClickButton topSingleButton = new SingleClickButton(); topSingleButton.name = txtName.Text.Trim(); topSingleButton.key = txtKey.Text.Trim(); topList.Add(topSingleButton); } } } #endregion bg.button.AddRange(topList); var result = mMrg.CreateMenu(accessToken, bg); JscriptMsg("菜单提交成功!", "wxMenu.aspx", "Success"); } catch (Exception ex) { JscriptMsg("报错:" + ex.Message, "", "Error"); } }
public void CreateMenuGaiaWX() { //Console.WriteLine("************************************开始创建微信菜单*******************************************************\n"); string appid = "wxe7c51862f6de2f3e"; string secret = "bb66c368c6c6462dc62b9118e8058ff5"; string PROJECT_NAME = "FESCOAsecco"; string PROJECT_URL = "weixin.hrone.cn"; var accessToken = AccessTokenContainer.TryGetAccessToken(appid, secret); Console.WriteLine(" accessToken:" + accessToken + "\n"); ButtonGroup bg = new ButtonGroup(); //首页 var About = new SingleClickButton() { name = "账户绑定", key = "bind_account", type = ButtonType.click.ToString(), }; //var About = new SubButton() //{ // name = "首页" //}; //About.sub_button.Add(new SingleClickButton() //{ // name = "账户绑定", // key = "bind_account", // type = ButtonType.click.ToString(),//默认已经设为此类型,这里只作为演示 //}); //About.sub_button.Add(new SingleViewButton() //{ // url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME // + "%2FView%2FCommUtil%2FLoading.html?pageType=10011&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", // name = "银行信息" //}); bg.button.Add(About); //我的 var AboutMe = new SubButton() { name = "我的信息" }; AboutMe.sub_button.Add(new SingleViewButton() { url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME + "%2FView%2FCommUtil%2FLoading.html?pageType=10009&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", name = "个人信息" }); //AboutMe.sub_button.Add(new SingleViewButton() //{ // url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME // + "%2FView%2FCommUtil%2FLoading.html?pageType=10011&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", // name = "银行信息" //}); AboutMe.sub_button.Add(new SingleViewButton() { url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME + "%2FView%2FCommUtil%2FLoading.html?pageType=10008&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", name = "我的薪资" }); AboutMe.sub_button.Add(new SingleViewButton() { url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME + "%2FView%2FCommUtil%2FLoading.html?pageType=10007&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", name = "我的店铺" }); AboutMe.sub_button.Add(new SingleViewButton() { url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME + "%2FView%2FCommUtil%2FLoading.html?pageType=10001&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", name = "我的排班" }); AboutMe.sub_button.Add(new SingleViewButton() { url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME + "%2FView%2FCommUtil%2FLoading.html?pageType=10010&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", name = "员工可用性" }); bg.button.Add(AboutMe); //申请&签核 var ApplyAndApprove = new SubButton() { name = "申请&签核" }; ApplyAndApprove.sub_button.Add(new SingleViewButton() { url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME + "%2FView%2FCommUtil%2FLoading.html?pageType=10003&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", name = "请假申请" }); ApplyAndApprove.sub_button.Add(new SingleViewButton() { url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME + "%2FView%2FCommUtil%2FLoading.html?pageType=10004&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", name = "加班申请" }); ApplyAndApprove.sub_button.Add(new SingleViewButton() { url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME + "%2FView%2FCommUtil%2FLoading.html?pageType=10005&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", name = "异常申诉" }); ApplyAndApprove.sub_button.Add(new SingleViewButton() { url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME + "%2FView%2FCommUtil%2FLoading.html?pageType=10006&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", name = "主管审批" }); ApplyAndApprove.sub_button.Add(new SingleViewButton() { url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=http%3A%2F%2F" + PROJECT_URL + "%2F" + PROJECT_NAME + "%2FView%2FCommUtil%2FLoading.html?pageType=10002&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", name = "考勤打卡" }); bg.button.Add(ApplyAndApprove); var result = CommonApi.CreateMenu(accessToken, bg); Console.WriteLine(" Errcode: " + result.errcode + "\n\n Errmsg: " + result.errmsg + "\n\n P2PData: " + result.P2PData + "\n"); Console.WriteLine("************************************创建微信菜单结束*******************************************************\n"); Console.ReadKey(); }
protected void Page_Load(object sender, EventArgs e) { string signature = Request["signature"]; string timestamp = Request["timestamp"]; string nonce = Request["nonce"]; string echostr = Request["echostr"]; string inputXml = string.Empty; using (StreamReader sr = new StreamReader(Request.InputStream)) { inputXml = sr.ReadToEnd(); inputXml = HttpUtility.UrlDecode(inputXml); } string updateMenu = Request["updatemenu"]; if (!string.IsNullOrWhiteSpace(updateMenu)) { foreach (var menu in Activator.WeChatMenuContainer.WeChatMenus) { try { if (!AccessTokenContainer.CheckRegistered(menu.AppId)) { AccessTokenContainer.Register(menu.AppId, menu.Secret); } AccessTokenResult tokenRes = null; try { tokenRes = AccessTokenContainer.GetTokenResult(menu.AppId); //CommonAPIs.CommonApi.GetToken(appId, appSecret); WriteContent(string.Format("获取到 token 为:{0}, 有效时间为 {1} 秒。", tokenRes.access_token, tokenRes.expires_in)); //var menuRes = CommonApi.GetMenu(tokenRes.access_token); } catch { WriteContent(string.Format("获取到 token 失败, appid: {0},secret: {1}。", menu.AppId, menu.Secret)); } try { if (tokenRes != null) { //重新整理按钮信息 ButtonGroup bg = new ButtonGroup(); foreach (var menuButton in menu.MenuButtons) { BaseButton but = null; switch (menuButton.Type) { case ButtonType.Click: but = new SingleClickButton() { name = menuButton.Name, key = menuButton.Key, type = "click" }; break; case ButtonType.View: but = new SingleViewButton() { name = menuButton.Name, url = menuButton.Url, type = "view" }; break; case ButtonType.SubButton: List<SingleButton> subButtons = new List<SingleButton>(); foreach (var subBut in menuButton.MenuSubButtons) { SingleButton singleBut = null; switch (subBut.Type) { case ButtonType.Click: singleBut = new SingleClickButton() { name = subBut.Name, key = subBut.Key, type = "click" }; break; case ButtonType.View: singleBut = new SingleViewButton() { name = subBut.Name, url = subBut.Url, type = "view" }; break; } if (singleBut != null) subButtons.Add(singleBut); } but = new SubButton() { name = menuButton.Name, sub_button = subButtons }; break; } if (but != null) bg.button.Add(but); } var result = CommonApi.CreateMenu(tokenRes.access_token, bg); WriteContent(string.Format("创建结果信息:{0}, 返回值 {1} ({2})。", result.errmsg, (int)result.errcode, result.errcode.ToString())); } } catch { WriteContent("创建菜单失败!"); } } catch (Exception) { //TODO:为简化代码,这里不处理异常(如Token过期) WriteContent("执行过程发生错误!"); } } } foreach (var proxy in Activator.WeChatProxyContainer.WeChatProxies) { string token = proxy.Token; if (Request.HttpMethod == "GET") { //get method - 仅在微信后台填写URL验证时触发 if (CheckSignature.Check(signature, timestamp, nonce, token)) { WriteContent(echostr); //返回随机字符串则表示验证通过 //如果有多个相同的Token,则第一个验证通过就返回 break; } else { //WriteContent("failed:" + signature + "," + CheckSignature.GetSignature(timestamp, nonce, token) + "。" + // "如果你在浏览器中看到这句话,说明此地址可以被作为微信公众账号后台的Url,请注意保持Token一致。"); //如果失败应该不返回任何东西,以便循环校验下一个Token continue; } } else { //post method - 当有用户想公众账号发送消息时触发 if (!CheckSignature.Check(signature, timestamp, nonce, token)) { WriteContent("参数错误!"); continue; } //v4.2.2之后的版本,可以设置每个人上下文消息储存的最大数量,防止内存占用过多,如果该参数小于等于0,则不限制 var maxRecordCount = 10; //自定义MessageHandler,对微信请求的详细判断操作都在这里面。 //var messageHandler = new CustomMessageHandler(Request.InputStream, maxRecordCount); IMessageHandler messageHandler = null; using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(inputXml))) { Type type = proxy.Bundle.LoadClass(proxy.Handler); var parameters = new object[] { stream, token, proxy.AppID, proxy.Secret, maxRecordCount }; messageHandler = System.Activator.CreateInstance(type, parameters) as IMessageHandler; } try { if (messageHandler != null) { //测试时可开启此记录,帮助跟踪数据,使用前请确保App_Data文件夹存在,且有读写权限。 messageHandler.RequestDocument.Save( Server.MapPath("~/App_Data/" + DateTime.Now.Ticks + "_Request_" + messageHandler.RequestMessage.FromUserName + ".txt")); //执行微信处理过程 messageHandler.Execute(); //测试时可开启,帮助跟踪数据 messageHandler.ResponseDocument.Save( Server.MapPath("~/App_Data/" + DateTime.Now.Ticks + "_Response_" + messageHandler.ResponseMessage.ToUserName + ".txt")); WriteContent(messageHandler.ResponseDocument.ToString()); continue; } } catch (Exception ex) { using (TextWriter tw = new StreamWriter(Server.MapPath("~/App_Data/Error_" + DateTime.Now.Ticks + ".txt"))) { tw.WriteLine(ex.Message); tw.WriteLine(ex.InnerException.Message); if (messageHandler.ResponseDocument != null) { tw.WriteLine(messageHandler.ResponseDocument.ToString()); } tw.Flush(); tw.Close(); } WriteContent(""); } } } Response.End(); }
private void GetMenu() { BuysingooShop.Web.AppCode.MenuMgr mMrg = new BuysingooShop.Web.AppCode.MenuMgr(); try { string error = ""; string accessToken = BuysingooShop.Web.AppCode.CWeixinService.IsExistAccess_Token(); //检测access_token是否失效; if (error != "") { JscriptMsg(error, "", "Error"); return; } Senparc.Weixin.MP.Entities.GetMenuResult result = mMrg.GetMenu(accessToken); if (result == null) { //JscriptMsg("未获得到菜单,请参考【使用规则】,自行排查问题!", "", "Error"); return; //强制刷新 //accessToken = cpp.FlushAccessToken(weixin.id, out error); //result = CommonApi.GetMenu(accessToken); } var topButtonList = result.menu.button; int topNum = topButtonList.Count; TextBox txtName = new TextBox(); TextBox txtKey = new TextBox(); TextBox txtUrl = new TextBox(); for (int i = 0; i < topNum; i++) { var topButton = topButtonList[i]; if (topButton != null) { txtName = this.FindControl("txtTop" + (i + 1)) as TextBox; txtKey = this.FindControl("txtTop" + (i + 1) + "Key") as TextBox; txtUrl = this.FindControl("txtTop" + (i + 1) + "Url") as TextBox; txtName.Text = topButton.name; if (topButton.GetType() != typeof(Senparc.Weixin.MP.Entities.Menu.SubButton)) { //下面无子菜单 if (topButton.GetType() == typeof(Senparc.Weixin.MP.Entities.Menu.SingleViewButton)) { //view 页面跳转 txtUrl.Text = ((Senparc.Weixin.MP.Entities.Menu.SingleViewButton)topButton).url; } else { txtKey.Text = ((Senparc.Weixin.MP.Entities.Menu.SingleClickButton)topButton).key; } } else { //下面有子菜单 IList <Senparc.Weixin.MP.Entities.Menu.SingleButton> subButtonList = ((Senparc.Weixin.MP.Entities.Menu.SubButton)topButton).sub_button; if (subButtonList != null && subButtonList.Count > 0) { TextBox txtSubName = new TextBox(); TextBox txtSubKey = new TextBox(); TextBox txtSubUrl = new TextBox(); for (int j = 0; j < subButtonList.Count; j++) { txtSubName = this.FindControl("txtMenu" + (i + 1) + (j + 1)) as TextBox; txtSubKey = this.FindControl("txtMenu" + (i + 1) + (j + 1) + "Key") as TextBox; txtSubUrl = this.FindControl("txtMenu" + (i + 1) + (j + 1) + "Url") as TextBox; if (subButtonList[j].GetType() == typeof(Senparc.Weixin.MP.Entities.Menu.SingleViewButton)) { Senparc.Weixin.MP.Entities.Menu.SingleViewButton sub = (Senparc.Weixin.MP.Entities.Menu.SingleViewButton)subButtonList[j]; txtSubName.Text = sub.name; txtSubUrl.Text = sub.url; } else { Senparc.Weixin.MP.Entities.Menu.SingleClickButton sub = (Senparc.Weixin.MP.Entities.Menu.SingleClickButton)subButtonList[j]; txtSubName.Text = sub.name; txtSubKey.Text = sub.key; } } } } } } } catch (Exception ex) { } }