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

How to realize personalized menu in the development of Wechat

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is about how Wechat develops personalized menus. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

In order to help the official account achieve flexible business operation, a personalized menu interface has been added to the Wechat public platform, through which developers can let different user groups of the official account see different custom menus. The interface is open to authenticated Subscription account and authenticated service numbers.

Developers can set the menu that users see with the following conditions:

1. User grouping (the business needs of developers can be accomplished with the help of user grouping)

2. Gender

3. Mobile phone operating system

4. Region (the region set by users on the Wechat client)

5. Language (the language set by users on Wechat client)

Personalized menu API description:

1. Personalized menu requires users to have a Wechat client version of iPhone6.2.2,Android 6.2.4 or above.

2. The menu refresh strategy is that when users enter the official account session page or the official account profile page, if they find that the last request to pull the menu was 5 minutes ago, the menu will be pulled, and if the menu is updated, the menu on the client will be refreshed. During the test, you can try to unfollow the public account and follow it again, and you can see the effect after the creation.

3. The daily limit of the new interface of the personalized menu of the ordinary official account is 2000 times, the deletion interface is also 2000 times, and the matching result interface of testing personalized menu is 20000 times.

4. For security reasons, all personalized menus on an official account can only be set to jump to links under three domain names at most.

5. Before creating a personalized menu, you must first create a default menu (the default menu refers to the menu created using the general custom menu creation API). If you delete the default menu, the personalized menu will also be deleted

Personalized menu matching rules description:

When the official account creates multiple personalized menus, it will match the new to the old one according to the release order until the user information matches the matchrule. If all personalized menus do not match, the default menu is returned.

For example, the official account has successively released the default menu, personalized menu 1, personalized menu 2, personalized menu 3. Then when the user enters the official account page, the match will start with the personalized menu 3, and if the personalized menu 3 matches successfully, it will directly return to the personalized menu 3, otherwise continue to try to match the personalized menu 2 until a menu is successfully matched.

According to the above matching rules, in order to avoid confusion about the effective time of the menu, it is decided not to provide personalized menu editing API. When developers need to update the menu, they need to release the complete configuration again.

Catalogue

1 create a personalized menu

2 delete personalized menu

3 test the matching results of personalized menu

4 query personalized menu

5 remove all menus

Create a personalized menu

Http request method: POST (please use https protocol)

Api.weixin.qq.com/cgi-bin/menu/addconditional?access_token=ACCESS_TOKEN

Request example

{"button": [{"type": "click", "name": "Today's Song", "key": "V1001_TODAY_MUSIC"}, {"name": "menu", "sub_button": [{"type": "view", "name": "search", "url": "http://www.soso.com/"},{"type":"view","name":" Video" "url": "http://v.qq.com/"},{"type":"click","name":" praise us", "key": "V1001_GOOD"}]}], "matchrule": {"group_id": "2", "sex": "1", "country": "China", "province": "Guangdong", "city": "Guangzhou" "client_platform_type": "2"language": "zh_CN"}}

Parameter description

Matchrule has a total of six fields, all of which can be empty, but not all of them. At least one matching information must be not empty. The regional information composed of country, province and city will be verified in the order of country, province and city, which should be in line with the contents of the regional information table. The regional information is verified from large to small, and the small one can be left unfilled, that is, if the provincial information is filled in, the national information must be filled and matched, and the urban information can be left unfilled. For example, "Guangzhou, Guangdong Province, China" and "Guangdong Province, China" are legal regional information, while "Guangzhou, China" is illegal because the city information is filled in but not the province information. Please click to download the area information sheet.

Return the result

The returned JSON packet is as follows when it is correct. For the error return code, please see the API error code description.

{"menuid": "208379533"}

Delete personalized menu

Http request method: POST (please use https protocol)

Api.weixin.qq.com/cgi-bin/menu/delconditional?access_token=ACCESS_TOKEN

Request example

{"menuid": "208379533"}

Menuid is menu id, which can be obtained through custom menu query API.

The returned JSON packet is as follows when it is correct. For the error return code, please see the API error code description. :

{"errcode": 0, "errmsg": "ok"}

Test personalized menu matching results

Http request method: POST (please use https protocol)

Api.weixin.qq.com/cgi-bin/menu/trymatch?access_token=ACCESS_TOKEN

Request example

{"user_id": "weixin"}

User_id can be a fan's OpenID or a fan's WeChat account.

If the result is returned, the API will return menu configuration. Examples are as follows:

{"button": [{"type": "view", "name": "tx", "url": "http://www.qq.com/"," sub_button ": []}, {" type ":" view "," name ":" tx " "url": "http://www.qq.com/"," sub_button ": []}, {" type ":" view "," name ":" tx "," url ":" http://www.qq.com/", "sub_button": []}}

For the error return code, please see the API error code description.

Query personalized menu

The default menu and all personalized menu information can be obtained by using the general custom menu query API. Please see the description of the custom menu query API.

Delete all menus

Use the normal custom menu deletion API to delete all custom menus (including default menus and all personalized menus). See the description of the custom menu deletion API.

Thank you for reading! This is the end of the article on "how to achieve personalized menus in Wechat development". I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it for more people to see!

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