侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

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

微信(小程序)  /  管理员 发布于 3年前   163

官方菜单功能介绍

请求接口:https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN

新增菜单管理类

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

菜单创建

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

成功了哦。

您可能感兴趣的文章:

  • 微信小程序实现弹出菜单动画
  • 微信小程序实现炫酷的弹出式菜单特效
  • 微信小程序MUI侧滑导航菜单示例(Popup弹出式,左侧滑动,右侧不动)
  • 微信小程序实现的点击按钮 弹出底部上拉菜单功能示例
  • 微信小程序 下拉菜单简单实例
  • 微信公众号菜单配置微信小程序实例详解
  • 微信公众号点击菜单即可打开并登录微站的实现方法


  • 上一条:
    微信公众号平台接口开发 获取微信服务器IP地址方法解析
    下一条:
    微信小程序之数据绑定原理解析
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 小程序开发之跳转微信直播示例api(0个评论)
    • 在uni_app中开发小程序之常用功能示例代码汇总(0个评论)
    • 小程序开发之多端框架:taro(0个评论)
    • 微信小程序前端使用七牛云官方SDK上传七牛云代码示例(0个评论)
    • 百度小程序审核未通过,真机审核存在点击返回键退出小程序...解决方式之一tabBar(0个评论)
    • 近期文章
    • 在laravel框架中的5个HTTP客户端技巧分享(0个评论)
    • 在go语言中使用FFmpeg库实现PCM音频文件编码为mp3格式文件流程步骤(0个评论)
    • gopacket免安装Pcap实现驱动层流量抓包流程步骤(0个评论)
    • 在laravel项目中实现密码强度验证功能推荐扩展包:password-strength(0个评论)
    • 在go语言中用filepath.Match()函数以通配符模式匹配字符串示例(0个评论)
    • Laravel Response Classes 响应类使用优化浅析(0个评论)
    • mysql中sql_mode的各模式浅析(0个评论)
    • 百度文心一言今天发布,个人第一批内测体验记录,不好别打我(0个评论)
    • 嘿加密世界让我们谈谈在共识中将中本聪主流化(0个评论)
    • 在go语言中寻找两个切片或数组中的相同元素/共同点/交集并集示例代码(0个评论)
    • 近期评论
    • 博主 在

      2023年国务院办公厅春节放假通知:1月21日起休7天中评论 @ xiaoB 你只管努力,剩下的叫给天意;天若有情天亦老,..
    • xiaoB 在

      2023年国务院办公厅春节放假通知:1月21日起休7天中评论 会不会春节放假后又阳一次?..
    • BUG4 在

      你翻墙过吗?国内使用vpn翻墙可能会被网警抓,你需了解的事中评论 不是吧?..
    • 博主 在

      go语言+beego框架中获取get,post请求的所有参数中评论 @ t1  直接在router.go文件中配就ok..
    • Jade 在

      如何在MySQL查询中获得当月记录中评论 Dear zongscan.com team, We can skyroc..
    • 2017-10
    • 2018-01
    • 2020-03
    • 2021-06
    • 2021-10
    • 2022-03
    • 2023-02
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客