Home  >  Article  >  WeChat Applet  >  Development example of personalized menu in WeChat public account

Development example of personalized menu in WeChat public account

一个新手
一个新手Original
2017-09-07 09:32:134059browse

Development example of personalized menu in WeChat public account

Personalized menu allows different user groups of the public account to see different customized menus. This interface is open to certified subscription accounts and certified service accounts. The personalized menu requires the user's WeChat client version to be iPhone 6.2.2, Android 6.2.4 or above. Other versions of WeChat are not supported for the time being. In addition, you must first define a personalized menu. Define the default menu.

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

  1. User tags (Developers can use user tags to meet their business needs to complete)

  2. gender

  3. Mobile operating system

  4. Region (the region set by the user on the WeChat client)

  5. Language (the language set by the user on the WeChat client)

Description of personalized menu matching rules:

Updates to the personalized menu will be overwritten.
For example, the public account has released the default menu, personalized menu 1, personalized menu 2, and personalized menu 3. Then when the user enters the official account page, matching will start from personalized menu 3. If personalized menu 3 is successfully matched, it will directly return to personalized menu 3. Otherwise, it will continue to try to match personalized menu 2 until a menu is successfully matched.
According to the above matching rules, in order to avoid confusion about the menu's effective time, it has been decided not to provide a personalized menu editing API. When developers need to update the menu, they need to re-release the complete configuration.

The project structure of this example is as follows. In addition to the files in the previous chapter, three files for processing personalized menus have been added.


addconditional_menu.php: Create a personalized menu

trymatch.php: Test the matching personalized menu

delconditional_menu.php: Delete personalized menu

1. Create a personalized menu

The interface for creating a personalized menu is https://api.weixin.qq.com /cgi-bin/menu/addconditional?access_token=ACCESS_TOKEN, send the menu string in post mode.

addconditional_menu.php

The return result is as follows:

View the menu and find that it has changed from the default menu to a personalized menu , as shown below

#Only gender filtering is set here, 1 means male. For other condition settings, please refer to the personalized menu interface.

2. Test the personalized menu matching results

The test interface is https://api.weixin.qq.com/cgi-bin/menu/trymatch?access_token=ACCESS_TOKEN, which requires post " user_id" past.

trymatch.php

The returned results are as follows:


3. Delete the personalized menu

The interface to delete the personalized menu is https://api.weixin.qq.com/cgi-bin/menu/delconditional?access_token=ACCESS_TOKEN, and you need to post "menuid".

delconditional_menu.php

The return result is as follows to indicate success:

4. Query personalized menu

Use The common custom menu query interface can obtain the default menu and all personalized menu information, please refer to the previous chapter.


The results after the query are as follows:


The menuid here is different from the above because I deleted the previous one Personalize the menu and then reinitialize it.


5. Delete all menus

Use the common custom menu deletion interface to delete all custom menus (including default menus and all personalized menus)

The above is the detailed content of Development example of personalized menu in WeChat public account. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn