Wechat public account development – example of creating custom menu and menu event response

The user-defined menu of wechat development public platform needs to spend money for authentication. If you don't want to spend money, you can only play the test account, but this does not affect the development. My development is based on Mr. Liu Feng's wechat public platform application development.

As long as we use the public platform test account, we can develop custom menus, which is more convenient. The test account opens many interfaces, which is very convenient.

When developing a custom menu, you can refer to the custom menu creation in the developer document of wechat public platform.

1、 Customize menu

1. The custom menu includes up to 3 primary menus, and each primary menu contains up to 5 secondary menus.

2. There are up to 4 Chinese characters in the first level menu and 7 Chinese characters in the second level menu. The extra part will be marked with "..." Replace.

3, after creating a custom menu, the refresh policy of the menu is that when the user enters the official account session page or the official account profile page, if the request for the last pull menu is found 5 minutes before, the menu will be pulled. If the menu is updated, the menu of the client will be refreshed. During the test, you can try to cancel paying attention to the public account and pay attention again, then

You can see the effect after creation.

The user-defined menu interface can realize various types of buttons, as follows:

1. Click: Click to push the event

After the user clicks the click type button, the wechat server will push the structure with the message type of event to the developer through the message interface (refer to the message interface Guide), and bring the key value filled in by the developer in the button. The developer can interact with the user through the customized key value;

2. View: jump URL

After the user clicks the view type button, the wechat client will open the web page URL filled in by the developer in the button, which can be combined with the web page authorization interface to obtain the user's basic information.

3、scancode_ Push: code scanning push event

After the user clicks the button, the wechat client will call up the scanning tool, display the scanning results after the code scanning operation (if it is a URL, it will enter the URL), and send the code scanning results to the developer, who can send a message.

4、scancode_ Waitmsg: scan the code to push the event and pop up the "message receiving" prompt box

After the user clicks the button, the wechat client will call up the code scanning tool. After the code scanning operation is completed, the code scanning result will be transmitted to the developer. At the same time, the code scanning tool will be put away, and then the "message receiving" prompt box will pop up, and then the message sent by the developer may be received.

5、pic_ Sysphoto: pop up the system to take photos and send pictures

After the user clicks the button, the wechat client will turn up the system camera. After completing the photographing operation, the wechat client will send the photographed photos to the developer, push the event to the developer, put away the system camera, and then may receive the message sent by the developer.

6、pic_ photo_ or_ Album: pop up to take photos or send pictures from photo albums

After the user clicks the button, the wechat client will pop up a selector for the user to choose "take photos" or "select from mobile phone album". After the user selects, the other two processes are followed.

7、pic_ Weixin: pop up wechat photo album Poster

After the user clicks the button, the wechat client will call up the wechat photo album. After the selection operation is completed, the selected photo will be sent to the developer's server, and the event will be pushed to the developer. At the same time, the photo album will be put away, and then the message may be received from the developer.

8、location_ Select: pop up the geographic location selector

After the user clicks the button, the wechat client will call up the geographic location selection tool. After the selection operation is completed, the selected geographic location will be sent to the developer's server, the location selection tool will be stowed, and then the message may be received from the developer.

9、media_ ID: send message (except text message)

The user clicks media_ After the ID type button, the wechat server will send the material corresponding to the permanent material ID filled in by the developer to the user. The permanent material types can be pictures, audio, video and graphic messages. Please note: the permanent material ID must be the legal ID obtained after uploading on the "material management / add permanent material" interface.

10、view_ Limited: jump to graphic message URL

The user clicks view_ After the limited type button, the wechat client will open the graphic message URL corresponding to the permanent material ID filled in by the developer in the button. The permanent material type only supports graphic messages. Please note: the permanent material ID must be the legal ID obtained after uploading in the "material management / add permanent material" interface

2、 Access custom menu interface

1: Get access_ token

The creation, query and deletion of user-defined menus need to call the user-defined menu interface opened by the public platform, and to call this interface, you need to obtain access first_ Token (interface access credential). These interfaces are all based on HTTPS protocol. Therefore, we must first solve the problem of how to send HTTPS requests in Java programs.

Get interface access credentials_ token:

Get access_ The token accesses the following links through get: https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET

HTTP request method: Post (please use HTTPS protocol) https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN

It's actually an address https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN Submit a menu string in JSON format by post.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>