


Welcome to leave a message, forward,
Click me for the project source code reference address - Welcome to Start
The previous articles have already talked about how to import the project, how to start the configuration project, how to become a developer, and what is the source code analysis news? Interaction (If the first four items are not very clear, you can read here to quickly develop WeChat public accounts. This article will talk about how to implement a custom menu
There are two ways to implement a custom menu
1. Edit mode
2. Development Mode
The editing mode is very simple and I won’t go into details...
Development mode to implement custom menu
1. Use the WeChat public platform interface debugging tool to implement it
2. Use the official interface to implement it
Early preparation
Add plug-inNote:
1. Currently,subscription accounts
can only use editing mode and cannot add hyperlinks. Development mode can only be used after WeChat authentication.
2. Editing mode and development mode cannot be turned on at the same time. 3. Generate. The menu will not be displayed immediately (the next day). If you want to see the effect immediately, you can unfollow and follow again
access_token
body
body is actually a
JSON object that needs to be generated for the menu. The official provides a chestnut for reference.
{ "button":[ { "type":"click", "name":"今日歌曲", "key":"V1001_TODAY_MUSIC" }, { "name":"菜单", "sub_button":[ { "type":"view", "name":"搜索", "url":"http://www.soso.com/" }, { "type":"view", "name":"视频", "url":"http://v.qq.com/" }, { "type":"click", "name":"赞一下我们", "key":"V1001_GOOD" }] }] }
access_token is obtained as shown below
Students who are learning about WeChat custom menus for the first time are advised to read the official documents three times firstIn
Jfinal-weixin, there are encapsulated menu creation, query, deletion, and personalized menus Create, query, delete,
test personalized menu matching results
The following is the package provided? The interface
//查询自定义菜单 public static ApiResult getMenu() { String jsonResult = HttpUtils.get(getMenu + AccessTokenApi.getAccessTokenStr()); return new ApiResult(jsonResult); } //创建自定义菜单 public static ApiResult createMenu(String jsonStr) { String jsonResult = HttpUtils.post(createMenu + AccessTokenApi.getAccessTokenStr(), jsonStr); return new ApiResult(jsonResult); } //删除自定义菜单 public static ApiResult deleteMenu() { String jsonResult = HttpUtils.get(deleteMenuUrl + AccessTokenApi.getAccessTokenStr()); return new ApiResult(jsonResult); } //创建个性化自定义菜单 public static ApiResult addConditional(String jsonStr) { String jsonResult = HttpUtils.post(addConditionalUrl + AccessTokenApi.getAccessTokenStr(), jsonStr); return new ApiResult(jsonResult); } //删除个性化自定义菜单 public static ApiResult delConditional(String menuid) { HashMap params = new HashMap(); params.put("menuid", menuid); String url = delConditionalUrl + AccessTokenApi.getAccessTokenStr(); String jsonResult = HttpUtils.post(url, JsonUtils.toJson(params)); return new ApiResult(jsonResult); } //测试个性化菜单匹配结果 public static ApiResult tryMatch(String userId) { HashMap params = new HashMap(); params.put("user_id", userId); String url = tryMatchUrl + AccessTokenApi.getAccessTokenStr(); String jsonResult = HttpUtils.post(url, JsonUtils.toJson(params)); return new ApiResult(jsonResult); } public static ApiResult getCurrentSelfMenuInfo() { String jsonResult = HttpUtils.get(getCurrentSelfMenuInfoUrl + AccessTokenApi.getAccessTokenStr()); return new ApiResult(jsonResult); }provides a detailed usage demo in the open source project weixin_guide
com.javen.weixin.menu.MenuManager class
public static void main(String[] args) { // 将菜单对象转换成json字符串 String jsonMenu = JsonKit.toJson(getTestMenu()).toString(); System.out.println(jsonMenu); ApiConfig ac = new ApiConfig(); // 配置微信 API 相关常量 请使用你自己公众号的 ac.setAppId("wx614c453e0d1dcd12"); ac.setAppSecret("19a02e4927d346484fc70327970457f9"); // ac.setAppId(PropKit.get("appId")); // ac.setAppSecret(PropKit.get("appSecret")); ApiConfigKit.setThreadLocalApiConfig(ac); //创建菜单 ApiResult apiResult=MenuApi.createMenu(jsonMenu); System.out.println(apiResult.getJson()); }You can see that the main method calls
MenuApi.createMenu(jsonMenu)that
Where does jsonMenu come from?
String jsonMenu = JsonKit.toJson(getTestMenu()).toString();
Executing the main method will output the JSON of the generated menu and the status of the response
/** * 组装菜单数据 * * @return */ private static Menu getTestMenu() { ClickButton btn11 = new ClickButton(); btn11.setName("微信相册发图"); btn11.setType("pic_weixin"); btn11.setKey("rselfmenu_1_1"); ClickButton btn12 = new ClickButton(); btn12.setName("拍照或者相册发图"); btn12.setType("pic_photo_or_album"); btn12.setKey("rselfmenu_1_2");; ClickButton btn13 = new ClickButton(); btn13.setName("系统拍照发图"); btn13.setType("pic_sysphoto"); btn13.setKey("rselfmenu_1_3"); ClickButton btn21 = new ClickButton(); btn21.setName("扫码带提示"); btn21.setType("scancode_waitmsg"); btn21.setKey("rselfmenu_2_1");; ClickButton btn22 = new ClickButton(); btn22.setName("扫码推事件"); btn22.setType("scancode_push"); btn22.setKey("rselfmenu_2_2");; ViewButton btn23 = new ViewButton(); btn23.setName("我的设备"); btn23.setType("view"); btn23.setUrl("https://hw.weixin.qq.com/devicectrl/panel/device-list.html?appid=wx614c453e0d1dcd12"); ViewButton btn31 = new ViewButton(); btn31.setName("微社区"); btn31.setType("view"); btn31.setUrl("http://whsf.tunnel.mobi/whsf/msg/wsq"); ClickButton btn32 = new ClickButton(); btn32.setName("发送位置"); btn32.setType("location_select"); btn32.setKey("rselfmenu_3_2"); //http://tencent://message/?uin=572839485&Site=在线咨询&Menu=yes //http://wpa.qq.com/msgrd?v=3&uin=572839485&site=qq&menu=yes ViewButton btn33 = new ViewButton(); btn33.setName("在线咨询"); btn33.setType("view"); btn33.setUrl("http://wpa.qq.com/msgrd?v=3&uin=572839485&site=qq&menu=yes"); ViewButton btn34 = new ViewButton(); btn34.setName("我的博客"); btn34.setType("view"); btn34.setUrl("http://www.cnblogs.com/zyw-205520"); ClickButton btn35 = new ClickButton(); btn35.setName("点击事件"); btn35.setType("click"); btn35.setKey("rselfmenu_3_5"); ComButton mainBtn1 = new ComButton(); mainBtn1.setName("发图"); mainBtn1.setSub_button(new Button[] { btn11, btn12, btn13}); ComButton mainBtn2 = new ComButton(); mainBtn2.setName("扫码"); mainBtn2.setSub_button(new Button[] { btn21, btn22 ,btn23}); ComButton mainBtn3 = new ComButton(); mainBtn3.setName("个人中心"); mainBtn3.setSub_button(new Button[] { btn31, btn32, btn33, btn34 ,btn35 }); /** * 这是公众号xiaoqrobot目前的菜单结构,每个一级菜单都有二级菜单项<br> * * 在某个一级菜单下没有二级菜单的情况,menu该如何定义呢?<br> * 比如,第三个一级菜单项不是“更多体验”,而直接是“幽默笑话”,那么menu应该这样定义:<br> * menu.setButton(new Button[] { mainBtn1, mainBtn2, btn33 }); */ Menu menu = new Menu(); menu.setButton(new Button[] { mainBtn1, mainBtn2, mainBtn3 }); return menu; }
The above is the whole process of generating a custom menu.
【Related recommendations】
1.
WeChat public account platform source code downloadWeizhichuang T+ WeChat robot source codeWeChat Network King v3.4.5 Advanced Business Edition WeChat Rubik’s Cube source codeThe above is the detailed content of Share an example tutorial on developing custom menus for WeChat public accounts. For more information, please follow other related articles on the PHP Chinese website!

PHP是一种开源的脚本语言,广泛应用于Web开发和服务器端编程,尤其在微信开发中得到了广泛的应用。如今,越来越多的企业和开发者开始使用PHP进行微信开发,因为它成为了一款真正的易学易用的开发语言。在微信开发中,消息的加密和解密是一个非常重要的问题,因为它们涉及到数据的安全性。对于没有加密和解密方式的消息,黑客可以轻松获取到其中的数据,对用户造成威胁

微信是目前全球用户规模最大的社交平台之一,随着移动互联网的普及,越来越多的企业开始意识到微信营销的重要性。在进行微信营销时,客服服务是至关重要的一环。为了更好地管理客服聊天窗口,我们可以借助PHP语言进行微信开发。一、PHP微信开发简介PHP是一种开源的服务器端脚本语言,广泛运用于Web开发领域。结合微信公众平台提供的开发接口,我们可以使用PHP语言进行微信

在微信公众号开发中,用户标签管理是一个非常重要的功能,可以让开发者更好地了解和管理自己的用户。本篇文章将介绍如何使用PHP实现微信用户标签管理功能。一、获取微信用户openid在使用微信用户标签管理功能之前,我们首先需要获取用户的openid。在微信公众号开发中,通过用户授权的方式获取openid是比较常见的做法。在用户授权完成后,我们可以通过以下代码获取用

如何在微信公众号上使用PHP开发自定义菜单微信公众号是一个非常重要的媒介,很多企业和个人都选择在微信公众号上进行推广和交流。而自定义菜单则是微信公众号中不可或缺的一部分,可以帮助提高用户体验和导航功能。本文将介绍如何使用PHP开发自定义菜单,并提供具体的代码示例。首先,我们需要先了解微信公众号自定义菜单的相关概念和限制。自定义菜单的类型在微信公众号中,自定义

随着微信的普及,越来越多的企业开始将其作为营销工具。而微信群发功能,则是企业进行微信营销的重要手段之一。但是,如果只依靠手动发送,对于营销人员来说是一件极为费时费力的工作。所以,开发一款微信群发工具就显得尤为重要。本文将介绍如何使用PHP开发微信群发工具。一、准备工作开发微信群发工具,我们需要掌握以下几个技术点:PHP基础知识微信公众平台开发开发工具:Sub

随着互联网和移动智能设备的发展,微信成为了社交和营销领域不可或缺的一部分。在这个越来越数字化的时代,如何使用PHP进行微信开发已经成为了很多开发者的关注点。本文主要介绍如何使用PHP进行微信开发的相关知识点,以及其中的一些技巧和注意事项。一、开发环境准备在进行微信开发之前,首先需要准备好相应的开发环境。具体来说,需要安装PHP的运行环境,以及微信公众平台提

随着微信成为了人们生活中越来越重要的一个通讯工具,其敏捷的消息传递功能迅速受到广大企业和个人的青睐。对于企业而言,将微信发展为一个营销平台已经成为趋势,而微信开发的重要性也逐渐凸显。在其中,群发功能更是被广泛使用,那么,作为PHP程序员,如何实现群发消息发送记录呢?下面将为大家简单介绍一下。1.了解微信公众号相关开发知识在了解如何实现群发消息发送记录之前,我

ThinkPHP6微信开发指南:快速搭建微信公众号应用引言:微信公众号作为一种重要的社交媒体平台,为个人和企业在市场推广、信息传播等方面提供了很大的机会。在这篇文章中,我们将介绍如何使用ThinkPHP6快速搭建一个微信公众号应用,并且提供一些常用的代码示例。环境准备在开始开发之前,我们首先需要准备好以下环境:PHP7以上版本ThinkPHP6框架微信公众号


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools
