微信公众平台推出一自定义菜单功能,我们可以简单的直接在后台编辑自定义菜单,也可以利用api来设置菜单,下面我来介绍一下操作方法
腾讯微信3月19日正式公布公众平台自定义菜单功能。目前该功能仅提供给企业和机构,且内测资格需要申请。对于这一新增功能,目前仅有少数账号已经开通。至此,微信的商业化价值被进一步挖掘出来。
开发者可利用该功能为公众账号的会话界面底部增加自定义菜单。用户点击菜单中的选项,可以调出相应的回复信息或网页链接。
菜单创建
接口说明
通过POST一个特定结构体,实现在微信客户端创建自定义菜单。
请求说明
http请求方式:POST
https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN
结构体其实就是一个json格式的字符串,相信很多朋友就卡在这里了,怎么往这个接口地址 post 一个结构体呢,实现代码如下:
public static void main(String[] args) throws Exception { URL url = new URL("https://api.weixin.qq.com/cgi-bin /menu/create?access_token=TOKEN"); String responeJsonStr = "{"+ ""button":["+ "{"name":"酒店预订","+ ""sub_button":["+ "{"+ ""type":"click","+ ""name":"附近酒店","+ ""key":"jintoneinn488878-1""+ "},"+ "{"+ ""type":"click","+ ""name":"查找酒店","+ ""key":"jintoneinn488878-2""+ "}"+ "]"+ "}" "]"+ "}"; HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.connect(); conn.getOutputStream().write(responeJsonStr.getBytes("utf-8")); InputStream is = conn.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(is,"utf-8")); StringBuffer buffer = new StringBuffer(); String line = ""; while ((line = in.readLine()) != null) { buffer.append(line); } System.out.println(buffer.toString()); }
菜单查询
接口说明
查询当前使用的自定义菜单结构。
请求说明
http请求方式:GET
https://api.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN
返回说明
对应创建接口,正确的Json返回结果:
{"menu":{"button":[{"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC","sub_button":[]},{"type":"click","name":"歌手简介","key":"V1001_TODAY_SINGER","sub_button":[]},{"name":"菜单","sub_button":[{"type":"click","name":"hello word","key":"V1001_HELLO_WORLD","sub_button":[]},{"type":"click","name":"赞一下我们","key":"V1001_GOOD","sub_button":[]}]}]}}
菜单删除
接口说明
取消当前使用的自定义菜单。
请求说明
http请求方式:GET
https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN
返回说明
对应创建接口,正确的Json返回结果:
{"errcode":0,"errmsg":"ok"}

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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

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),