Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Java to implement Wechat official account Custom menu

Shulou Source: shulou.com Published: 2022-06-03 09:45:59 09月26日 Update

This article mainly shows you "how to use Java to achieve Wechat official account custom menu", the content is easy to understand, clear, hope to help you solve your doubts, now let the editor lead you to study and learn "how to use Java to achieve Wechat official account custom menu" this article.

The details are as follows:

When developing official accounts, you may need to add events to some custom menus, such as clicking on a menu and then the server pushes information to the user.

We can also use the web debugging tool provided by Wechat to generate menus directly, but we need to consider whether it will affect users.

Note: using code to customize menu events, manually added menus will become invalid! Use it carefully!

Official document

If necessary, the httpClientUtil utility class can be obtained from the previous Wechat official account to obtain access_token.

Public class WechatDIYMenuTest {public static void main (String [] args) {String accessToken = "15_A0pP-hwxjv3DCQbQmk9Gl99aIvjieSO6FStnoNyt78_S_Souv9RmMWRu9ndzlFJT4iD1e3iLXNGvxP2AB4aZ0k1" + "pK76Sp9DYMVLJZThKcsRCIJtFOw3qfGuM5d0GTDdAAAMZJ"; JSONObject jsonObject = new JSONObject (); JSONArray jsonArray = new JSONArray (); / / first-level menu JSONObject menu1 = new JSONObject (); menu1.put ("type", "click"); menu1.put ("name", "menu 1"); menu1.put ("key", "key_1") JsonArray.add (menu1); / / first-level menu JSONObject menu2 = new JSONObject (); menu2.put ("name", "menu 2"); JSONArray jsonArray2 = new JSONArray (); / / second-level menu JSONObject menu3 = new JSONObject (); menu3.put ("type", "click"); menu3.put ("name", "menu 3"); menu3.put ("key", "key_3") JsonArray2.add (menu3); menu2.put ("sub_button", jsonArray2); jsonArray.add (menu2); JSONObject menu4 = new JSONObject (); menu4.put ("type", "click"); menu4.put ("name", "menu 4"); menu4.put ("key", "key_4"); jsonArray.add (menu4); jsonObject.put ("button", jsonArray) String url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + accessToken; String result = HttpClientUtil.doPostJson (url, jsonObject.toJSONString ()); System.out.println (result);}} these are all the contents of the article" how to use Java to implement the custom menu of Wechat official account ". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Menus public content articles events tools users learning help code information official manual documentation time easy to understand more organization knowledge editing Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MariaDB MySQL Linux Apple