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 Personalized menu Interface developed by Wechat Public platform

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly shows you the "example analysis of personalized menu interface developed by Wechat public platform", which is easy to understand and well-organized. I hope it can help you solve your doubts. Now let the editor lead you to study and study the article "sample analysis of personalized menu interface for Wechat public platform development".

Not long ago, Wechat launched a personalized menu interface, and Senparc.Weixin SDK has been updated synchronously.

This update upgrades the Senparc.Weixin.MP version to v13.5.2, depending on Senparc.Weixin version 4.5.4. Both branches of. Net 4.5 (master) /. Net 4. 0 have been updated synchronously.

Due to the great changes in personalized menus, the entire menu interface has been reconstructed in the largest area so far (it can be downwards compatible).

Compared with the previous custom menu, the relevant functions of the entire menu have been comprehensively sorted out for the file structure:

Interface

The menu APIs are all under the CommonAPIs/Menu directory, and there are three more class files under some of the CommonApi classes:

File name description CommonApi.Menu.Common.cs menu Public method CommonApi.Menu.Conditional.cs Personalized menu CommonApi.Menu.Custom.cs General Custom menu

Menu interface file

Among them, the custom menu interface has ensured downward compatibility. In the past, if there are projects that have developed custom menu functions, you can rest assured to upgrade.

The contents of personalized menu classes are as follows:

/ *-Copyright (C) 2015 Senparc File name: CommonApi.Menu.Conditional File function description: personalized Custom menu API creation ID: Senparc-20151222 Modify logo: Senparc-20151222 modify description: V13.5.1 add personalized menu interface-* / * API: http://mp.weixin.qq.com/wiki / 0/c48ccd12b69ae023159b4bfaa7c39c20.html * / using Senparc.Weixin.Entities Using Senparc.Weixin.Helpers;using Senparc.Weixin.MP.Entities;using Senparc.Weixin.MP.Entities.Menu;namespace Senparc.Weixin.MP.CommonAPIs {public partial class CommonApi {/ create a Xinhua menu / AccessToken or AppId. When AppId, the AccessToken error will be automatically fetched once. When null, gets the first AppId currently registered. / / menu content / / public static CreateMenuConditionalResult CreateMenuConditional (string accessTokenOrAppId, ConditionalButtonGroup buttonData, int timeOut = Config.TIME_OUT) {return ApiHandlerWapper.TryCommonApi (accessToken = > {var urlFormat = "https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token={0}"; var jsonSetting = new JsonSetting (true)) Return CommonJsonSend.Send (accessToken, urlFormat, buttonData, timeOut: timeOut, jsonSetting: jsonSetting);}, accessTokenOrAppId) } # region GetMenu / * the default menu and all personalized menu information can be obtained by using the common custom menu query API. Please see the description of the custom menu query API * / Test personalized menu matching results / can be fans' OpenID. It can also be the WeChat account of fans. / / public static MenuTryMatchResult TryMatch (string accessTokenOrAppId, string userId) {return ApiHandlerWapper.TryCommonApi (accessToken = > {var url = string.Format ("https://api.weixin.qq.com/cgi-bin/menu/delconditional?access_token={0}", accessToken)) Var data = new {user_id = userId}; return CommonJsonSend.Send (accessToken, url, data, CommonJsonSendType.POST);}, accessTokenOrAppId) } # endregion / delete menu / menu Id / public static WxJsonResult DeleteMenuConditional (string accessTokenOrAppId String menuId) {return ApiHandlerWapper.TryCommonApi (accessToken = > {var url = string.Format ("https://api.weixin.qq.com/cgi-bin/menu/delconditional?access_token={0}", accessToken)) Var data = new {menuId = menuId}; return CommonJsonSend.Send (accessToken, url, data, CommonJsonSendType.POST);}, accessTokenOrAppId) } / * use the common custom menu deletion API to delete all custom menus (including default menus and all personalized menus). See the description of Custom menu deletion API. * /}}

In the menu public method, the GetButtonGroup () method adds a parameter: buttonGroup, which specifies the menu button list type (personalized menu or custom menu).

Entity

Changes to entity classes are reflected in the Entities/Menu directory, with new IButtonGroupBase interfaces and ButtonGroupBase base classes. Both ButtonGroup (custom menu) and ConditionalButtonGroup (personalized menu) buttons inherit from ButtonGroupBase.

All button types under the Entities/Menu/Buttons/ directory are common.

Return type

The reorganized return types are all in the Entities/JsonResult/Menu/ directory:

Pay attention

The menu add and delete interfaces of custom menu and personalized menu are different, and different interfaces need to be called when they are used.

If you use a personalized menu, you must fill in at least one rule in MenuMatchRule.

For using personalized menus or not, the data returned when getting the menu is different (the former includes the latter), so SDK only provides the same entity for both cases: GetMenuResult (the corresponding receiving message entity is GetMenuResultFull). Information about a Xinhua menu (list) can be read directly from GetMenuResult.conditionalmenu. If it is null or the list is empty, there is no personalized menu.

Testing and visual editing

The source code provides a simple visual editing tool, while you can view the menu JSON data format (showing the operation of the entity converted to JSON, not the original JSON).

The above is all the contents of the article "sample Analysis of Personalized menu Interface developed by Wechat Public platform". 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!

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