当前位置: 首页 > news >正文

微信公众平台接口 html,微信公众号平台接口开发 菜单管理的实现

官方菜单功能介绍

eac00f98412fc0b6aa2198546f3d8786.png

adf31f64d47a5ef3fb41659e6dc78f60.png

9c929b06cd12b306bf82ee1e00c51163.png

3d537c204727f4b753b3173aa8f78657.png

新增菜单管理类

public class MenuFirstLayerModel

{

public string name { get; set; }

public List sub_button { get; set; }

}

public class MenuTwoLayerModel

{

public string type { get; set; }

public string name { get; set; }

public string key { get; set; }

public string url { get; set; }

}

public class WXMenu

{

public List button { get; set; }

public string Create()

{

try

{

var requestUri = string.Format(@"https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}", WeCharBase.AccessToken);

return WeCharBase.Post(requestUri, new StringContent(JsonConvert.SerializeObject(new

{

button = button

})));

}

catch (Exception ex)

{

return ex.Message;

}

}

}

新增控制器MenuController.cs

public ActionResult ViewMenu()

{

return View();

}

public ActionResult CreateMenu()

{

var wxMenu = new WXMenu()

{

button = new List()

{

new MenuFirstLayerModel()

{

name="扫码",

sub_button = new List()

{

new MenuTwoLayerModel()

{

type = "scancode_waitmsg",

name = "扫码带提示",

key = "rselfmenu_0_0"

},

new MenuTwoLayerModel()

{

type = "scancode_push",

name = "扫码推事件",

key = "rselfmenu_0_1"

}

},

},

new MenuFirstLayerModel()

{

name = "发图",

sub_button = new List()

{

new MenuTwoLayerModel()

{

type = "pic_sysphoto",

name = "系统拍照发图",

key = "rselfmenu_1_0"

},

new MenuTwoLayerModel()

{

type = "pic_photo_or_album",

name = "拍照或者相册发图",

key = "rselfmenu_1_1"

},

new MenuTwoLayerModel()

{

type = "pic_weixin",

name = "微信相册发图",

key = "rselfmenu_1_2"

}

}

},

new MenuFirstLayerModel()

{

name = "其他",

sub_button = new List()

{

new MenuTwoLayerModel()

{

type = "location_select",

name = "发送位置",

key = "rselfmenu_2_0"

},

new MenuTwoLayerModel()

{

type = "click",

name = "今日歌曲",

key = "V1001_TODAY_MUSIC"

},

new MenuTwoLayerModel()

{

type = "view",

name = "百度",

url = "http://www.baidu.com"

}

}

}

}

};

return Content(wxMenu.Create());

}

新增视图ViewMenu.cshtml

$(document).ready(function () {

$("#btnCreate").click(function () {

$.ajax({

type: "POST",

url: "/Menu/CreateMenu",

data: { id: $("#textContent").val() },

success: function (responseTest) {

$("#resultMesage").text(responseTest);

}

});

});

});

菜单创建

button = new[]

{

new

{

name="扫码",

sub_button = new[]

{

new

{

type = "scancode_waitmsg",

name = "扫码带提示",

key = "rselfmenu_0_0"

},

new

{

type = "scancode_push",

name = "扫码推事件",

key = "rselfmenu_0_1"

}

}

},

new

{

name = "发图",

sub_button = new[]

{

new

{

type = "pic_sysphoto",

name = "系统拍照发图",

key = "rselfmenu_1_0"

},

new

{

type = "pic_photo_or_album",

name = "拍照或者相册发图",

key = "rselfmenu_1_1"

},

new

{

type = "pic_weixin",

name = "微信相册发图",

key = "rselfmenu_1_2"

}

}

},

new

{

name = "其他",

sub_button = new[]

{

new

{

type = "location_select",

name = "发送位置",

key = "rselfmenu_2_0"

},

new

{

type = "click",

name = "今日歌曲",

key = "V1001_TODAY_MUSIC"

},

new

{

type = "view",

name = "百度",

url = "http://www.baidu.com"

}

}

}

}

有效代码写完了,看看效果

d6b00fcbd2f421d1c34ecdda23b9400c.png

639c88a1005b16728d2a28e51899665b.png

成功了哦。

相关文章:

  • 怎么把html改成迅雷bt种子文件格式,BT种子怎么制作?教你如何制作BT种子
  • html loading插件,推荐一款我自己开发的jquery loading插件
  • struts2 html post large data,十一、Struts2 文件上传
  • HTML表格上边境不显示,如何显示的iframe边界之外HTML元素
  • xhtml1.0与html5,将Doctype从XHTML 1.0升级到HTML5会导致简单html页面中的布局差异
  • 纽约州立计算机科学,纽约州立大学宾汉姆顿分校计算机科学申请条件有哪些?...
  • 计算机中互交式用户在哪找,如何在Windows中获取当前数量的交互式用户会话?...
  • web浏览不支持html5,mui适用场景说明,能不能在普通浏览器里使用,能否用于wap网站...
  • 计算机网络信息安全管理办法,计算机网络信息安全管理实施细则.doc
  • html5 全屏样式,HTML5 全屏特性
  • 计算机软考网络工程师历年真题,2019上半年软考网络工程师考试下午真题
  • plc是一台专用计算机对,PLC其实质上是一台工业控制用的专用计算机,它由硬件系统和软件系统两大部分组成...
  • 南航计算机英语面试自我介绍,南航应聘英语自我介绍4篇
  • 计算机系统 理论知识试卷,计算机理论期中考试题
  • 2000的笔记本能HTML,我想买一个笔记本,最好是2000--3000元,请高人给个配置单。谢谢,家用的。...