国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home WeChat Applet WeChat Development WeChat development custom menu--weixin-java-tools

WeChat development custom menu--weixin-java-tools

Mar 08, 2017 pm 04:46 PM
WeChat development

1. Foreword

Usually in the process of developing WeChat, we will definitely design the use of WeChat-related menus. This time I will introduce to you how to use weixin-java-tools to manage the menu

2. Custom menu classification

1. Click: Click push event After the user clicks the click type button, the WeChat server will push the message type event structure 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, WeChat The 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 basic user information to obtain basic user information.

 3. scancode_push: After the user clicks the button in the scan code push event, the WeChat client will launch the scan tool. After completing the scan code operation, the scan result will be displayed (if it is a URL, the URL will be entered), and the The result of scanning the code is sent to the developer, and the developer 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 activate the scan tool. After completing the code scanning operation, the scan code results will be displayed. Pass it to the developer, put away the scanning tool at the same time, and then the "Message Receiving" prompt box will pop up, and you may receive a message from the developer.

 5. pic_sysphoto: After the user clicks the button to take pictures and send pictures from the system, the WeChat client will call up the system camera. After completing the picture taking operation, the taken pictures will be sent to the developer and the event will be pushed to the developer. , and put away the system camera at the same time, and then you may receive a message from the developer.

 6. pic_photo_or_album: After the user clicks the button to take a photo or send a picture to an album, the WeChat client will pop up a selector for the user to choose "take a photo" or "select from the mobile phone album". After the user chooses, he will go through the other two processes.

7. pic_weixin: After the user clicks the button of the pop-up WeChat photo album sender, the WeChat client will call up the WeChat photo album. After completing the selection operation, the selected photos will be sent to the developer's server and the event will be pushed to Developer, close the photo album at the same time, and you may receive a message from the developer later.

8. Location_select: After the user clicks the button of the pop-up geographical location selector, the WeChat client will call up the geographical location selection tool. After completing the selection operation, the selected geographical location will be sent to the developer's server and collected at the same time. Start the location selection tool, and then you may receive a message from the developer.

9. media_id: Send messages (except text messages). After the user clicks the media_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 type can be a picture. , audio, video, graphic messages. Please note: the permanent material ID must be a legal ID obtained after uploading through the "Material Management/Add Permanent Material" interface.

 10. view_limited: Jump to the graphic message URL. After the user clicks the view_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 a legal ID obtained after uploading through the "Material Management/Add Permanent Material" interface.

 Please note that all events from 3 to 8 only support WeChat iPhone 5.4.1 or above, and WeChat users with Android 5.4 or above. WeChat users with older versions will not respond after clicking. , developers cannot receive event push normally. 9 and 10 are event types specially prepared for subscription accounts of third-party platforms that have not been certified by WeChat (specifically, those who have failed to pass the qualification certification). They do not have event push and their capabilities are relatively limited. Other types of public accounts No need to use.

3. Calling interface address: http Request method: POST (please use https protocol) https://api.weixin.qq.com/ cgi-bin/menu/create?access_token=ACCESS_TOKEN

4. Request example

{
     "button":[
     {	
          "type":"click",
          "name":"今日歌曲",
          "key":"V1001_TODAY_MUSIC"
      },
      {
           "name":"菜單",
           "sub_button":[
           {	
               "type":"view",
               "name":"搜索",
               "url":"http://www.soso.com/"
            },
            {
               "type":"view",
               "name":"視頻",
               "url":"http://v.qq.com/"
            },
            {
               "type":"click",
               "name":"贊一下我們",
               "key":"V1001_GOOD"
            }]
       }]
 }

5. Parameter description

參數(shù)是否必須說明
button一級菜單數(shù)組,個數(shù)應(yīng)為1~3個
sub_button二級菜單數(shù)組,個數(shù)應(yīng)為1~5個
type菜單的響應(yīng)動作類型
name菜單標(biāo)題,不超過16個字節(jié),子菜單不超過40個字節(jié)
keyclick等點擊類型必須菜單KEY值,用于消息接口推送,不超過128字節(jié)
urlview類型必須網(wǎng)頁鏈接,用戶點擊菜單可打開鏈接,不超過1024字節(jié)
media_idmedia_id類型和view_limited類型必須調(diào)用新增永久素材接口返回的合法media_id

六、代碼實現(xiàn):

  

package com.weixin.menu;

import java.util.ArrayList;
import java.util.List;

import me.chanjar.weixin.common.bean.WxMenu;
import me.chanjar.weixin.common.bean.WxMenu.WxMenuButton;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxMpServiceImpl;

public class WeixinMenuService {

	public static void main(String[] args) {
		
		//創(chuàng)建菜單
		//創(chuàng)建一級菜單
		WxMenuButton button1=new WxMenuButton();
		button1.setType("click"); //點擊事件按鈕
		button1.setName("點擊菜單");
		button1.setKey("key1"); //根據(jù)標(biāo)志獲取點擊菜單
		
		//創(chuàng)建一個復(fù)合菜單
		WxMenuButton button2=new WxMenuButton();
		button2.setName("多級菜單");
		
		WxMenuButton button2_1=new WxMenuButton();
		button2_1.setType("click"); //點擊事件按鈕
		button2_1.setName("子菜單一");
		button2_1.setKey("key2"); //根據(jù)標(biāo)志獲取點擊菜單
		
		WxMenuButton button2_2=new WxMenuButton();
		button2_2.setType("click"); //點擊事件按鈕
		button2_2.setName("子菜單二");
		button2_2.setKey("key3"); //根據(jù)標(biāo)志獲取點擊菜單
		
		
		WxMenuButton button3=new WxMenuButton();
		button3.setName("url菜單");
		button3.setType("view");
		button3.setUrl("http://www.baidu.com");  //必須添加http
		
		
		List<WxMenuButton> subButtons=new ArrayList<WxMenuButton>();
		subButtons.add(button2_1);
		subButtons.add(button2_2);
		button2.setSubButtons(subButtons);
		
		List<WxMenuButton> buttons=new ArrayList<WxMenuButton>();
		buttons.add(button1);
		buttons.add(button2);
		buttons.add(button3);
		
		WxMenu menu=new WxMenu();
		menu.setButtons(buttons);
		
		
		//發(fā)送請求 創(chuàng)建菜單
		WxMpService service=new WxMpServiceImpl();	
		WxMpInMemoryConfigStorage wxConfigProvider=new WxMpInMemoryConfigStorage();
		wxConfigProvider.setAppId("wx60a8f1c3a95b0b9c");
		wxConfigProvider.setSecret("5b0e8613b538da5ac4bbc610998f10ba");
		service.setWxMpConfigStorage(wxConfigProvider);
		try {
			service.menuCreate(menu);
		} catch (WxErrorException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}


	}

}

七、點擊菜單事件推送

  7.1 消息格式

  

<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[FromUser]]></FromUserName>
<CreateTime>123456789</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[CLICK]]></Event>
<EventKey><![CDATA[EVENTKEY]]></EventKey>
</xml>

  

  7.2 參數(shù)說明

  

參數(shù)描述
ToUserName開發(fā)者微信號
FromUserName發(fā)送方帳號(一個OpenID)
CreateTime消息創(chuàng)建時間 (整型)
MsgType消息類型,event
Event事件類型,CLICK
EventKey事件KEY值,與自定義菜單接口中KEY值對應(yīng)

  

  7.3 消息處理

  在接收消息的post中判斷消息類型 并做相關(guān)處理。

//獲取消息流
		WxMpXmlMessage message=WxMpXmlMessage.fromXml(request.getInputStream());
		
		if(message.getMsgType().equals("event")){ //事件
			
			//判斷event
			if(message.getEvent().equals("click") && message.getEventKey().equals("key1")){
				//do something
				
			}
			
			
		}

  

The above is the detailed content of WeChat development custom menu--weixin-java-tools. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP WeChat development: How to implement message encryption and decryption PHP WeChat development: How to implement message encryption and decryption May 13, 2023 am 11:40 AM

PHP is an open source scripting language that is widely used in web development and server-side programming, especially in WeChat development. Today, more and more companies and developers are starting to use PHP for WeChat development because it has become a truly easy-to-learn and easy-to-use development language. In WeChat development, message encryption and decryption are a very important issue because they involve data security. For messages without encryption and decryption methods, hackers can easily obtain the data, posing a threat to users.

PHP WeChat development: How to implement voting function PHP WeChat development: How to implement voting function May 14, 2023 am 11:21 AM

In the development of WeChat public accounts, the voting function is often used. The voting function is a great way for users to quickly participate in interactions, and it is also an important tool for holding events and surveying opinions. This article will introduce you how to use PHP to implement WeChat voting function. Obtain the authorization of the WeChat official account. First, you need to obtain the authorization of the WeChat official account. On the WeChat public platform, you need to configure the API address of the WeChat public account, the official account, and the token corresponding to the public account. In the process of our development using PHP language, we need to use the PH officially provided by WeChat

Using PHP to develop WeChat mass messaging tools Using PHP to develop WeChat mass messaging tools May 13, 2023 pm 05:00 PM

With the popularity of WeChat, more and more companies are beginning to use it as a marketing tool. The WeChat group messaging function is one of the important means for enterprises to conduct WeChat marketing. However, if you only rely on manual sending, it is an extremely time-consuming and laborious task for marketers. Therefore, it is particularly important to develop a WeChat mass messaging tool. This article will introduce how to use PHP to develop WeChat mass messaging tools. 1. Preparation work To develop WeChat mass messaging tools, we need to master the following technical points: Basic knowledge of PHP WeChat public platform development Development tools: Sub

PHP WeChat development: How to implement user tag management PHP WeChat development: How to implement user tag management May 13, 2023 pm 04:31 PM

In the development of WeChat public accounts, user tag management is a very important function, which allows developers to better understand and manage their users. This article will introduce how to use PHP to implement the WeChat user tag management function. 1. Obtain the openid of the WeChat user. Before using the WeChat user tag management function, we first need to obtain the user's openid. In the development of WeChat public accounts, it is a common practice to obtain openid through user authorization. After the user authorization is completed, we can obtain the user through the following code

PHP WeChat development: How to implement customer service chat window management PHP WeChat development: How to implement customer service chat window management May 13, 2023 pm 05:51 PM

WeChat is currently one of the social platforms with the largest user base in the world. With the popularity of mobile Internet, more and more companies are beginning to realize the importance of WeChat marketing. When conducting WeChat marketing, customer service is a crucial part. In order to better manage the customer service chat window, we can use PHP language for WeChat development. 1. Introduction to PHP WeChat development PHP is an open source server-side scripting language that is widely used in the field of Web development. Combined with the development interface provided by WeChat public platform, we can use PHP language to conduct WeChat

PHP WeChat development: How to implement group message sending records PHP WeChat development: How to implement group message sending records May 13, 2023 pm 04:31 PM

As WeChat becomes an increasingly important communication tool in people's lives, its agile messaging function is quickly favored by a large number of enterprises and individuals. For enterprises, developing WeChat into a marketing platform has become a trend, and the importance of WeChat development has gradually become more prominent. Among them, the group sending function is even more widely used. So, as a PHP programmer, how to implement group message sending records? The following will give you a brief introduction. 1. Understand the development knowledge related to WeChat public accounts. Before understanding how to implement group message sending records, I

Steps to implement WeChat public account development using PHP Steps to implement WeChat public account development using PHP Jun 27, 2023 pm 12:26 PM

How to use PHP to develop WeChat public accounts WeChat public accounts have become an important channel for promotion and interaction for many companies, and PHP, as a commonly used Web language, can also be used to develop WeChat public accounts. This article will introduce the specific steps to use PHP to develop WeChat public accounts. Step 1: Obtain the developer account of the WeChat official account. Before starting the development of the WeChat official account, you need to apply for a developer account of the WeChat official account. For the specific registration process, please refer to the official website of WeChat public platform

How to use PHP for WeChat development? How to use PHP for WeChat development? May 21, 2023 am 08:37 AM

With the development of the Internet and mobile smart devices, WeChat has become an indispensable part of the social and marketing fields. In this increasingly digital era, how to use PHP for WeChat development has become the focus of many developers. This article mainly introduces the relevant knowledge points on how to use PHP for WeChat development, as well as some of the tips and precautions. 1. Development environment preparation Before developing WeChat, you first need to prepare the corresponding development environment. Specifically, you need to install the PHP operating environment and the WeChat public platform

See all articles