search
HomeWeChat AppletWeChat DevelopmentDevelopment example of personalized menu in WeChat public account

Development example of personalized menu in WeChat public account

Sep 07, 2017 am 09:32 AM
personaliseDevelopment example

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

<?php
require_once(&#39;./Utils.php&#39;);
//个性化菜单字符串
$menujson = &#39;{
	"button":[
 	{
    	"type":"click",
    	"name":"单击",
     	"key":"V1001_TODAY_MUSIC"
	},
	{
		"name":"搜素",
		"sub_button":[
            {
                "type":"view",
                "name":"百度",
                "url":"http://www.baidu.com/"
            }
        ]
 }],
 "matchrule":{
  "sex":"1"
  }
}&#39;;
$url = "https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token=".Utils::get_access_token();
//创建个性化菜单
$result = Utils::https_request($url, $menujson);
//返回返回menuid表示成功
echo $result;

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

<?php
    @header(&#39;Content-type: text/plain;charset=UTF-8&#39;);
    require_once(&#39;./Utils.php&#39;);
    $url = "https://api.weixin.qq.com/cgi-bin/menu/trymatch?access_token=".Utils::get_access_token();
    //user_id可以是粉丝的OpenID,也可以是粉丝的微信号
    $userID = &#39;{"user_id":"o4WmZ0h-4huBUVQUczx2ezaxIL9c"}&#39;;
    $result = Utils::https_request($url, $userID);
    echo $result;
?>

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

<?php
    @header(&#39;Content-type: text/plain;charset=UTF-8&#39;);
    require_once(&#39;./Utils.php&#39;);
    $url = "https://api.weixin.qq.com/cgi-bin/menu/delconditional?access_token=".Utils::get_access_token();
    //menuid,个性化菜单的menuid
    $menuID = &#39;{"menuid":414784577}&#39;;
    $result = Utils::https_request($url, $menuID);
    echo $result;
?>

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

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

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.