怎么创建微信公众号自定义菜单栏?这里给出了权威解答

阅读 3997  ·  发布日期 2020-08-24 17:26  ·  温州雄霸网络科技有限公司|建站|APP小程序制作|做网站SEO推广优化
【摘要】 刚开始开通微信公众号的时候是抱着好奇的心态,其实我那时也不是很了解,经过查阅分析,前端是通过自定义菜单手动配置的,菜单不是通过后台生成的,后面想要获取事件信息的时候出现了点问题,所以我重新研究了下相关的文档,分享给大家其实生成菜单非常简单,直接上代码:官方文档地址:https://mp.weixin.qq.com/wi... 【做网站,网站建设公司,企业建站优化,小程序商城制作,温州小程序开发,温州微信公众号,平阳做网站,平阳网站建设公司,平阳小程序商城制作,平阳小程序开发,平阳微信公众号,昆阳做网站,昆阳网站建设公司,昆阳小程序商城制作,昆阳小程序开发,昆阳微信公众号,鳌江做网站,鳌江网站建设公司,鳌江小程序商城制作,鳌江小程序开发,鳌江微信公众号】...

怎么创建微信公众号自定义菜单栏?这里给出了权威解答

刚开始开通微信公众号的时候是抱着好奇的心态,其实我那时也不是很了解,经过查阅分析,前端是通过自定义菜单手动配置的,菜单不是通过后台生成的,后面想要获取事件信息的时候出现了点问题,所以我重新研究了下相关的文档,分享给大家其实生成菜单非常简单,直接上代码:官方文档地址:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141013创建几个实体类,用来生成创建菜单必须的json:/** * 微信公众号菜单 view 模式 * * @author cdj * @date 2018年7月26日 下午2:02:57 */ public class ViewEntity { public String type; public String name; public String url; public ViewEntity() { super(); // TODO Auto-generated constructor stub } public ViewEntity(String type, String name, String url) { super(); this.type = type; this.name = name; this.url = url; } public String getType() { return type; } public void setType(String type) { this.type = type; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } }/** * 微信公众号多级菜单按钮实体类 * * @author cdj * @date 2018年7月26日 下午2:08:40 */ public class MenuEntity { public String name; /**下级菜单按钮 集合 */ public List sub_button; public MenuEntity() { super(); // TODO Auto-generated constructor stub } public MenuEntity(String name, List sub_button) { super(); this.name = name; this.sub_button = sub_button; } public String getName() { return name; } public void setName(String name) { this.name = name; } public List getSub_button() { return sub_button; } public void setSub_button(List sub_button) { this.sub_button = sub_button; } } 写一个工具类直接获json,zlimport java.util.ArrayList; import java.util.List; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.modou.park.entity.wechat.MenuEntity; import com.modou.park.entity.wechat.ViewEntity; /** * 微信公众号获取button创建 * @author cdj * @date 2018年7月26日 下午2:22:02 */ public class WxCreateButtonUtils { /** * 获得微信公众号菜单 * @return */ public static String getWxCreateButtonJson() { JSONObject jsonObject = new JSONObject(); List lobjs = new ArrayList(); List firstvl = new ArrayList(); ViewEntity infoEntity = new ViewEntity("view", "个人信息", "http://www.xxx.com/xxxxxxxxx.html");//写自己的要跳转的url firstvl.add(infoEntity); MenuEntity thirdEntity = new MenuEntity("我的",firstvl); lobjs.add(thirdEntity); jsonObject.put("button", lobjs); System.out.println(jsonObject); return JSON.toJSONString(jsonObject); } }Controller: @ApiOperation("微信公众号创建菜单") @ApiImplicitParams({ }) @PostMapping("/WxCreateButton") public JsonResult wxCreateButton() { try { wxInfoService.createButton(); return JsonResult.success("创建成功"); } catch (Exception e) { // TODO: handle exception LOG.error(e.getMessage()); return JsonResult.failMsg(e.getMessage()); } }service: @Override public void createButton() { //String accessToken = wxPublicAccessTokenUtils.getAccessToken(); //String createButton_Url = UserInfoUtil.getCreateButton_Url(accessToken); String weixin_jssdk_acceToken_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s"; String jssdkAcceTokenUrl = String.format(weixin_jssdk_acceToken_url, WxPublicProperties.APPID, WxPublicProperties.APPSCREAT); String accesstoken = HttpsUtil.httpsRequestToString(jssdkAcceTokenUrl, "GET", null); WxToken accToken = JSONObject.parseObject(accesstoken, WxToken.class); String accessToken = accToken.getAccessToken(); String createurl = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s"; String createButton_Url = String.format(createurl, accessToken); String buttonJson = WxCreateButtonUtils.getWxCreateButtonJson(); String httpsRequestToString = HttpsUtil.httpsRequestToString(createButton_Url, "POST", buttonJson); System.out.println(httpsRequestToString); }成功反馈:{"errcode":0,"errmsg":"ok"}apache php mysqljson 里面的type 有多种情况, 例如 click 点击(可以与click事件绑定),miniprogram (小程序:需要参数appid ,pagepath, url 等) 不同的内容参数不同,效果也不同,可以看相应的文档了解一下。 测试时会出现很多的小bug , 可以通过百度错误码,网上有很多的回复 ;总结:新建菜单不难,但一定要细心,内容的格式一定要正确,json的key一定不能错,不能有的参数一定不要有,别问我怎么知道的。相关文章:微信公众平台开发二维码、创建菜单php实现微信公众平台账号自定义菜单类,公众账号相关视频:自定义菜单(1)-PHP微信公众平台开发视频教程以上就是怎么创建微信公众号自定义菜单栏?这里给出了权威解答的详细内容,更多请关注php中文网其它相关文章!微信分享相关标签:微信公众号本文原创发布php中文网,转载请注明出处,感谢您的尊重!上一篇:微信公众号开发,实现倒计时的一个功能(纯代码)下一篇:长见识了,原来微信浏览器内可以直接启动外部浏览器相关文章相关视频修改微信号有什么影响吗?微信中共享实时位置什么意思数据库设计的基本原则是什么?微信小程序调用图片安全API怎么创建微信公众号自定义菜单栏?这里给出了权威解答微信公众号接口调用频次限制说明微信公众号以及curl微信公众号前段微信公众号开发-微信公众号中url的配置 [温州做微信公众号]