Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Custom menu Interface developed by Wechat Public platform

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the example analysis of the custom menu interface developed by Wechat public platform, which has a certain reference value, and interested friends can refer to it. I hope you will learn a lot after reading this article. Let the editor take you to know it.

I. Custom menu rules

Custom menus are divided into primary menus and secondary menus.

The number of first-level menus is 1-3, that is, when you open the public account, you can see up to 3 buttons arranged at the bottom. The text of the first-level menu cannot exceed 16 bytes (equivalent to 8 Chinese characters).

The second-level menu is subordinate to the first-level menu, and the number is 1-5. The text of the second-level menu must not exceed 40 bytes (equivalent to 20 Chinese characters).

Regardless of whether the first-level menu or the second-level menu, there are two trigger events to choose from, namely: click (click, the value cannot exceed 128bytes) and open the URL (view,url cannot exceed 256bytes).

When a second-level menu exists under a first-level menu, nothing happens when the first-level menu button is clicked.

Create a menu

Using Senparc.Weixin.MP SDK to create custom menus is very simple. It only takes three steps:

Step 1: get AccessToken

Var accessToken = AccessTokenContainer.TryGetToken (appId, appSecret) .access_token

PS: if AppId is used instead of AccessToken in the third step, this step can be omitted.

Step 2: organize the menu content

ButtonGroup bg = new ButtonGroup (); / / Click bg.button.Add (new SingleClickButton () {name = "Click Test", key = "OneClick", type = ButtonType.click.ToString (), / / has been set to this type by default, here only for demonstration}) / / second-level menu var subButton = new SubButton () {name = "second-level menu"} SubButton.sub_button.Add (new SingleClickButton () {key = "SubClickRoot_Text", name = "return text"}) SubButton.sub_button.Add (new SingleClickButton () {key = "SubClickRoot_News", name = "return picture and text"}) SubButton.sub_button.Add (new SingleClickButton () {key = "SubClickRoot_Music", name = "return music"}) SubButton.sub_button.Add (new SingleViewButton () {url = "http://weixin.senparc.com", name =" Url Jump "}); bg.button.Add (subButton)

Step 3: submit to Wechat server

Var result = CommonApi.CreateMenu (accessToken, bg)

The above SingleClickButton and SingleViewButton correspond to click and view menu responses respectively.

Third, menu inquiry

The query menu also needs to get the AccessToken as above, and then only need one line of code:

Var result = CommonApi.GetMenu (accessToken)

The structure of the resulting result.menu is similar to the ButtonGroup bg variable above when the menu was created.

IV. Menu deletion

Once you get the AccessToken, it also takes only one line to delete the menu:

Var result = CommonApi.DeleteMenu (accessToken)

Menu responds to events

Whether it is click or view, the server receives different event responses (see "Wechat Public platform Development: learning about MessageHandler", which triggers OnEvent_ClickRequest () and OnEvent_ViewRequest (), respectively.

The difference is that after click, the client can get the return information, while after view receives the request, no matter what information is returned, the client cannot receive it (open URL directly).

VI. Custom menu visual editor

At present, Shengpai Network provides free custom menu visual editors in two places, eliminating the dilemma that you need to run code to operate the menu:

The first generation: http://sdk.weixin.senparc.com/Menu

The second generation: http://www.weiweihi.com, you can get a series of powerful management functions after registering and adding a public account on Wechat. (the first version of Weihai, which has been updated below, can also be found in the left menu in the background).

Thank you for reading this article carefully. I hope the article "sample Analysis of Custom menu Interface for the Development of Wechat Public platform" shared by the editor will be helpful to you. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report