Example #1
0
        public ActionResult Menu()
        {
            Common.WxHelper.JsApi_Ticket tickek = HttpContext.Application["jsapi_ticket"] as Common.WxHelper.JsApi_Ticket;
            //无票据或票据过期
            if (tickek == null || tickek.Ticket == null || tickek.Ticket.Length == 0 || tickek.Expires < DateTime.Now)
            {
                tickek = helper.GetJsApi_Ticket();
                if (string.IsNullOrEmpty(tickek.Ticket) || tickek.Expires < DateTime.Now)
                {
                    return(RedirectToAction("Error", new { msg = "接口凭证不存在或已过期" }));
                }
                HttpContext.Application.Add("jsapi_ticket", tickek);
            }
            string json = helper.GetMenu(tickek.Access_token);

            wxtest.Common.WxHelper.wxmenu  wxmenu  = jss.Deserialize <wxtest.Common.WxHelper.wxmenu>(json);
            wxtest.Common.WxHelper.wx_menu wx_menu = helper.ConverTowx_menu(wxmenu);
            ViewBag.wx_menu = wx_menu;
            return(View());
        }
Example #2
0
        public ActionResult MenuCreate(Common.WxHelper.wx_menu m)
        {
            Common.WxHelper.JsApi_Ticket tickek = HttpContext.Application["jsapi_ticket"] as Common.WxHelper.JsApi_Ticket;
            //无票据或票据过期
            if (tickek == null || tickek.Ticket == null || tickek.Ticket.Length == 0 || tickek.Expires < DateTime.Now)
            {
                tickek = helper.GetJsApi_Ticket();
                if (string.IsNullOrEmpty(tickek.Ticket) || tickek.Expires < DateTime.Now)
                {
                    return(RedirectToAction("Error", new { msg = "接口凭证不存在或已过期" }));
                }
                HttpContext.Application.Add("jsapi_ticket", tickek);
            }
            wxtest.Common.WxHelper.wxmenu wxmenu = helper.ConverTowxmenu(m);
            //var menu = GetMenu(wxmenu);
            //string json = jss.Serialize(menu);
            string json   = jss.Serialize(wxmenu.menu);
            bool   result = helper.CreateMenu(tickek.Access_token, json);

            ViewBag.result = result ? "操作成功" : "操作失败";
            return(View());
        }