public ActionResult CreateMenu(string token, GetMenuResultFull resultFull, MenuMatchRule menuMatchRule) { if (String.IsNullOrWhiteSpace(token)) { token = GetToken(); } var useAddCondidionalApi = menuMatchRule != null && !menuMatchRule.CheckAllNull(); var apiName = string.Format("使用接口:{0}。", (useAddCondidionalApi ? "个性化菜单接口" : "普通自定义菜单接口")); try { if (token.IsNullOrEmpty()) { throw new WeixinException("Token不能为空!"); } //重新整理按钮信息 WxJsonResult result = null; IButtonGroupBase buttonGroup = null; if (useAddCondidionalApi) { //个性化接口 buttonGroup = CommonApi.GetMenuFromJsonResult(resultFull, new ConditionalButtonGroup()).menu; var addConditionalButtonGroup = buttonGroup as ConditionalButtonGroup; addConditionalButtonGroup.matchrule = menuMatchRule; result = CommonApi.CreateMenuConditional(token, addConditionalButtonGroup); apiName += string.Format("menuid:{0}。", (result as CreateMenuConditionalResult).menuid); } else { //普通接口 buttonGroup = CommonApi.GetMenuFromJsonResult(resultFull, new ButtonGroup()).menu; result = CommonApi.CreateMenu(token, buttonGroup); } var json = new { Success = result.errmsg == "ok", Message = "菜单更新成功。" + apiName }; return(Json(json, new JsonSerializerSettings() { ContractResolver = new DefaultContractResolver() })); } catch (Exception ex) { var json = new { Success = false, Message = string.Format("更新失败:{0}。{1}", ex.Message, apiName) }; return(Json(json, new JsonSerializerSettings() { ContractResolver = new DefaultContractResolver() })); } }
public ActionResult CreateMenu(MPMenuViewModel request) { string token = GetToken(); // request.token; GetMenuResultFull resultFull = request.ResultFull; MenuMatchRule menuMatchRule = request.MenuMatchRule; var useAddCondidionalApi = menuMatchRule != null && !menuMatchRule.CheckAllNull(); var apiName = string.Format("使用接口:{0}。", (useAddCondidionalApi ? "个性化菜单接口" : "普通自定义菜单接口")); try { //重新整理按钮信息 WxJsonResult result = null; IButtonGroupBase buttonGroup = null; if (useAddCondidionalApi) { //个性化接口 buttonGroup = Senparc.Weixin.MP.CommonAPIs.CommonApi.GetMenuFromJsonResult(resultFull, new ConditionalButtonGroup()).menu; var addConditionalButtonGroup = buttonGroup as ConditionalButtonGroup; addConditionalButtonGroup.matchrule = menuMatchRule; result = Senparc.Weixin.MP.CommonAPIs.CommonApi.CreateMenuConditional(token, addConditionalButtonGroup); apiName += string.Format("menuid:{0}。", (result as CreateMenuConditionalResult).menuid); } else { //普通接口 buttonGroup = Senparc.Weixin.MP.CommonAPIs.CommonApi.GetMenuFromJsonResult(resultFull, new ButtonGroup()).menu; result = Senparc.Weixin.MP.CommonAPIs.CommonApi.CreateMenu(token, buttonGroup); } var json = new { Success = result.errmsg == "ok", Message = "菜单更新成功。" + apiName }; return(Json(json)); } catch (Exception ex) { var json = new { Success = false, Message = string.Format("更新失败:{0}。{1}", ex.Message, apiName) }; return(Json(json)); } }
public ActionResult CreateMenu(GetMenuResultFull resultFull, MenuMatchRule menuMatchRule) { if (string.IsNullOrEmpty(_wxAccount.AppId) || string.IsNullOrEmpty(_wxAccount.Secret)) { return(Json(new { error = "AppId或AppSecret为空" }, JsonRequestBehavior.AllowGet)); } var token = AccessTokenContainer.TryGetAccessToken(_wxAccount.AppId, _wxAccount.Secret); var useAddCondidionalApi = menuMatchRule != null && !menuMatchRule.CheckAllNull(); var apiName = string.Format("使用接口:{0}。", (useAddCondidionalApi ? "个性化菜单接口" : "普通自定义菜单接口")); try { //重新整理按钮信息 WxJsonResult result = null; IButtonGroupBase buttonGroup = null; if (useAddCondidionalApi) { //个性化接口 buttonGroup = CommonApi.GetMenuFromJsonResult(resultFull, new ConditionalButtonGroup()).menu; var addConditionalButtonGroup = buttonGroup as ConditionalButtonGroup; addConditionalButtonGroup.matchrule = menuMatchRule; result = CommonApi.CreateMenuConditional(token, addConditionalButtonGroup); apiName += string.Format("menuid:{0}。", (result as CreateMenuConditionalResult).menuid); } else { //普通接口 buttonGroup = CommonApi.GetMenuFromJsonResult(resultFull, new ButtonGroup()).menu; result = CommonApi.CreateMenu(token, buttonGroup); } return(Json(new { success = result.errmsg == "ok", message = "菜单更新成功。" + apiName })); } catch (Exception ex) { return(Json(new { success = false, message = string.Format("更新失败:{0}。{1}", ex.Message, apiName) })); } }
public ActionResult CreateMenu(string token, GetMenuResultFull resultFull, MenuMatchRule menuMatchRule) { bool flag = (menuMatchRule != null) && !menuMatchRule.CheckAllNull(); string str = "使用接口:" + (flag ? "个性化菜单接口" : "普通自定义菜单接口") + "。"; try { WxJsonResult result = null; IButtonGroupBase buttonData = null; if (flag) { ConditionalButtonGroup menu = CommonApi.GetMenuFromJsonResult(resultFull, new ConditionalButtonGroup()).menu as ConditionalButtonGroup; menu.matchrule = menuMatchRule; result = CommonApi.CreateMenuConditional(token, menu, 0x2710); str = str + "menuid:" + (result as CreateMenuConditionalResult).menuid + "。"; } else { buttonData = CommonApi.GetMenuFromJsonResult(resultFull, new ButtonGroup()).menu; result = CommonApi.CreateMenu(token, buttonData, 0x2710); } var data = new { Success = result.errmsg == "ok", Message = "菜单更新成功。" + str }; return(base.Json(data)); } catch (Exception exception) { var type2 = new { Success = false, Message = "更新失败:" + exception.Message + "。" + str }; return(base.Json(type2)); } }