Home Backend Development PHP Tutorial WeChat public account development tutorial Part 9 - Sending and receiving QQ emoticons_PHP tutorial

WeChat public account development tutorial Part 9 - Sending and receiving QQ emoticons_PHP tutorial

Jul 20, 2016 am 11:12 AM
one indivual right develop WeChat take over Tutorial of expression

I think everyone will be familiar with QQ emoticons. Each small avatar greatly enriches the fun of chatting, making chatting no longer a simple text narrative, but can also be accompanied by characters expressing happiness, anger, sadness, joy, etc. Small pictures of mood. The focus of this article is how to use QQ emoticons on the WeChat public platform, that is, in the WeChat public account development mode, how to send QQ emoticons to users, and how to identify that the users are sending QQ emoticons.

QQ emoticon code list

The first thing that needs to be made clear is that although QQ emoticons are presented as dynamic emoticon pictures, they are text messages in the messaging interface of the WeChat public platform; that is to say, when a user sends a QQ emoticon to a public account, The value of the message type MsgType received by the public account background program is text. As long as the above point can be understood, the following work can be carried out easily.

For QQ emoticons, what is sent is a text message, but an emoticon picture is displayed, so each QQ emoticon picture must have a corresponding emoticon code. Below is a comparison table of QQ emoticon codes used in WeChat public accounts:

A total of 105 QQ emoticons are listed above. Each emoticon has its corresponding text code and symbol code (perhaps these two names are not appropriate). As for how these two codes came from And how to use it will be discussed shortly below.

Users send QQ emoticons to public accounts

How to send QQ emoticons when using a public account on WeChat? I think few people don’t know how to do this. There is a smiley face picture button next to the input box. Clicking it will pop up the expression selection interface. The selectable expressions are "QQ emoticons", "symbol emoticons" and "animated emoticons". When we click to select a QQ emoticon, we find that the text code of the emoticon will be displayed in the input box, which is enclosed by a pair of square brackets, as shown in the following figure:

In fact, when we are familiar with the text codes for using QQ emoticons, we can also directly enter the emoticon code in the input box without popping up the emoticon selection box. As shown below:

As can be seen from the picture above, entering the three codes "[呲ya]", "/呲ya" and "/::D" in the input box have the same effect, they all send QQ emoticons of 呲ya . At this time, if you go back and look at the QQ emoticon code comparison table at the beginning of the article, you will understand what is going on.

Public accounts send QQ emoticons to users

Just like users sending QQ emoticons to public accounts, in development mode, public accounts can also use the same emoticon code (text code or symbol code) to reply to users with QQ emoticons. The code snippet is as follows:

// 文本消息
if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_TEXT)) {
	// 回复文本消息
	TextMessage textMessage = new TextMessage();
	textMessage.setToUserName(fromUserName);
	textMessage.setFromUserName(toUserName);
	textMessage.setCreateTime(new Date().getTime());
	textMessage.setMsgType(MessageUtil.RESP_MESSAGE_TYPE_TEXT);
	textMessage.setFuncFlag(0);
	textMessage.setContent("[难过] /难过 /::(");
	
	// 文本消息对象转换成xml字符串
	respMessage = MessageUtil.textMessageToXml(textMessage);
}
Copy after login
​ The function of the above code snippet is to determine the type of message sent. If it is a text message (MsgType=text), then reply three sad QQ emoticons to the user. It can be seen that whether the user sends it to a public account or a public account sends it to a user, the text code (such as: [sad] /sad) and symbol code (such as /::() of QQ emoticons can be used.

Public accounts identify QQ emoticons sent by users

After mastering how to send QQ emoticons, let’s take a look at how public accounts can identify that users are sending QQ emoticons. What does this mean? When a user sends a QQ emoticon to a public account, what value will be received in the background program, and how do we know that this value is a QQ emoticon.

In fact, as long as you do a simple test, for example: output the received text message to the log (you can use log4j or System.out.print), it is not difficult to find: send a QQ emoticon to the public account, in the background What is received in the program is the symbol code of QQ emoticons.

The following is a method I simply encapsulated, implemented through regular expressions, to determine whether the user sends a single QQ emoticon.

/**
 * 判断是否是QQ表情
 * 
 * @param content
 * @return
 */
public static boolean isQqFace(String content) {
	boolean result = false;

	// 判断QQ表情的正则表达式
	String qqfaceRegex = "/::\\)|/::~|/::B|/::\\||/:8-\\)|/::<|/::$|/::X|/::Z|/::&#39;\\(|/::-\\||/::@|/::P|/::D|/::O|/::\\(|/::\\+|/:--b|/::Q|/::T|/:,@P|/:,@-D|/::d|/:,@o|/::g|/:\\|-\\)|/::!|/::L|/::>|/::,@|/:,@f|/::-S|/:\\?|/:,@x|/:,@@|/::8|/:,@!|/:!!!|/:xx|/:bye|/:wipe|/:dig|/:handclap|/:&-\\(|/:B-\\)|/:<@|/:@>|/::-O|/:>-\\||/:P-\\(|/::&#39;\\||/:X-\\)|/::\\*|/:@x|/:8\\*|/:pd|/:<W>|/:beer|/:basketb|/:oo|/:coffee|/:eat|/:pig|/:rose|/:fade|/:showlove|/:heart|/:break|/:cake|/:li|/:bome|/:kn|/:footb|/:ladybug|/:shit|/:moon|/:sun|/:gift|/:hug|/:strong|/:weak|/:share|/:v|/:@\\)|/:jj|/:@@|/:bad|/:lvu|/:no|/:ok|/:love|/:<L>|/:jump|/:shake|/:<O>|/:circle|/:kotow|/:turn|/:skip|/:oY|/:#-0|/:hiphot|/:kiss|/:<&|/:&>";
	Pattern p = Pattern.compile(qqfaceRegex);
	Matcher m = p.matcher(content);
	if (m.matches()) {
		result = true;
	}
	return result;
}
Copy after login
下面是方法的使用,实现了这样一个简单的功能:用户发什么QQ表情给公众帐号,公众帐号就回复什么QQ表情给用户(xiaoqrobot就是这么做的)。实现代码如下:

// 文本消息
if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_TEXT)) {
	// 文本消息内容
	String content = requestMap.get("Content");
	
	// 判断用户发送的是否是单个QQ表情
	if(XiaoqUtil.isQqFace(content)) {
		// 回复文本消息
		TextMessage textMessage = new TextMessage();
		textMessage.setToUserName(fromUserName);
		textMessage.setFromUserName(toUserName);
		textMessage.setCreateTime(new Date().getTime());
		textMessage.setMsgType(MessageUtil.RESP_MESSAGE_TYPE_TEXT);
		textMessage.setFuncFlag(0);
		// 用户发什么QQ表情,就返回什么QQ表情
		textMessage.setContent(content);
		
		// 将文本消息对象转换成xml字符串
		respMessage = MessageUtil.textMessageToXml(textMessage);
	}
}
Copy after login
好了,关于微信公众帐号中QQ表情的使用就介绍这么多。其实,我并不希望初学者上来只是简单拷贝我贴出的代码,实现了自己想要的功能就完事了,更希望初学的朋友能够通过此文章学会一种思考问题和解决问题的方法。

 


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/444568.htmlTechArticle我想大家对QQ表情一定不会陌生,一个个小头像极大丰富了聊天的乐趣,使得聊天不再是简单的文字叙述,还能够配上喜、怒、哀、乐等表...
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

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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

There are rumors that 'iPhone 16 may not support WeChat', and Apple's technical consultant in China said that it is communicating with Tencent about app store commissions There are rumors that 'iPhone 16 may not support WeChat', and Apple's technical consultant in China said that it is communicating with Tencent about app store commissions Sep 02, 2024 pm 10:45 PM

Thanks to netizens Qing Qiechensi, HH_KK, Satomi Ishihara and Wu Yanzu of South China for submitting clues! According to news on September 2, there are recent rumors that "iPhone 16 may not support WeChat." In response to this, a reporter from Shell Finance called Apple's official hotline. Apple's technical consultant in China responded that whether iOS systems or Apple devices can continue to use WeChat, and WeChat The issue of whether it can continue to be listed and downloaded on the Apple App Store requires communication and discussion between Apple and Tencent to determine the future situation. Software App Store and WeChat Problem Description Software App Store technical consultant pointed out that developers may need to pay fees to put software on the Apple Store. After reaching a certain number of downloads, Apple will need to pay corresponding fees for subsequent downloads. Apple is actively communicating with Tencent,

deepseek image generation tutorial deepseek image generation tutorial Feb 19, 2025 pm 04:15 PM

DeepSeek: A powerful AI image generation tool! DeepSeek itself is not an image generation tool, but its powerful core technology provides underlying support for many AI painting tools. Want to know how to use DeepSeek to generate images indirectly? Please continue reading! Generate images with DeepSeek-based AI tools: The following steps will guide you to use these tools: Launch the AI ​​Painting Tool: Search and open a DeepSeek-based AI Painting Tool (for example, search "Simple AI"). Select the drawing mode: select "AI Drawing" or similar function, and select the image type according to your needs, such as "Anime Avatar", "Landscape"

In summer, you must try shooting a rainbow In summer, you must try shooting a rainbow Jul 21, 2024 pm 05:16 PM

After rain in summer, you can often see a beautiful and magical special weather scene - rainbow. This is also a rare scene that can be encountered in photography, and it is very photogenic. There are several conditions for a rainbow to appear: first, there are enough water droplets in the air, and second, the sun shines at a low angle. Therefore, it is easiest to see a rainbow in the afternoon after the rain has cleared up. However, the formation of a rainbow is greatly affected by weather, light and other conditions, so it generally only lasts for a short period of time, and the best viewing and shooting time is even shorter. So when you encounter a rainbow, how can you properly record it and photograph it with quality? 1. Look for rainbows. In addition to the conditions mentioned above, rainbows usually appear in the direction of sunlight, that is, if the sun shines from west to east, rainbows are more likely to appear in the east.

People familiar with the matter responded that 'WeChat may not support Apple iPhone 16': Rumors are rumors People familiar with the matter responded that 'WeChat may not support Apple iPhone 16': Rumors are rumors Sep 02, 2024 pm 10:43 PM

Rumors of WeChat supporting iPhone 16 were debunked. Thanks to netizens Xi Chuang Jiu Shi and HH_KK for submitting clues! According to news on September 2, there are rumors today that WeChat may not support iPhone 16. Once the iPhone is upgraded to the iOS 18.2 system, it will not be able to use WeChat. According to "Daily Economic News", it was learned from people familiar with the matter that this rumor is a rumor. Apple's response: According to Shell Finance, Apple's technical consultant in China responded that the issue of whether WeChat can continue to be used on iOS systems or Apple devices, and whether WeChat can continue to be listed and downloaded in the Apple App Store, needs to be resolved between Apple and Tencent. Only through communication and discussion can we determine the future situation. Currently, Apple is actively communicating with Tencent to confirm whether Tencent will continue to

How to retrieve the wrong chain of virtual currency? Tutorial on retrieving the wrong chain of virtual currency transfer How to retrieve the wrong chain of virtual currency? Tutorial on retrieving the wrong chain of virtual currency transfer Jul 16, 2024 pm 09:02 PM

The expansion of the virtual market is inseparable from the circulation of virtual currency, and naturally it is also inseparable from the issue of virtual currency transfers. A common transfer error is the address copy error, and another error is the chain selection error. The transfer of virtual currency to the wrong chain is still a thorny problem, but due to the inexperience of transfer operations, novices often transfer the wrong chain. So how to recover the wrong chain of virtual currency? The wrong link can be retrieved through a third-party platform, but it may not be successful. Next, the editor will tell you in detail to help you better take care of your virtual assets. How to retrieve the wrong chain of virtual currency? The process of retrieving virtual currency transferred to the wrong chain may be complicated and challenging, but by confirming the transfer details, contacting the exchange or wallet provider, importing the private key to a compatible wallet, and using the cross-chain bridge tool

gateio Chinese official website gate.io trading platform website gateio Chinese official website gate.io trading platform website Feb 21, 2025 pm 03:06 PM

Gate.io, a leading cryptocurrency trading platform founded in 2013, provides Chinese users with a complete official Chinese website. The website provides a wide range of services, including spot trading, futures trading and lending, and provides special features such as Chinese interface, rich resources and community support.

Why do you need to know histograms to learn photography? Why do you need to know histograms to learn photography? Jul 20, 2024 pm 09:20 PM

In daily shooting, many people encounter this situation: the photos on the camera seem to be exposed normally, but after exporting the photos, they find that their true form is far from the camera's rendering, and there is obviously an exposure problem. Affected by environmental light, screen brightness and other factors, this situation is relatively normal, but it also brings us a revelation: when looking at photos and analyzing photos, you must learn to read histograms. So, what is a histogram? Simply understood, a histogram is a display form of the brightness distribution of photo pixels: horizontally, the histogram can be roughly divided into three parts, the left side is the shadow area, the middle is the midtone area, and the right side is the highlight area; On the left is the dead black area in the shadows, while on the far right is the spilled area in the highlights. The vertical axis represents the specific distribution of pixels

Stable Diffusion 3 construction tutorial and official example demonstration, GALAXY GeForce RTX 4070 Ti SUPER Xingyao OC runs to full speed in an instant Stable Diffusion 3 construction tutorial and official example demonstration, GALAXY GeForce RTX 4070 Ti SUPER Xingyao OC runs to full speed in an instant Jun 24, 2024 am 05:59 AM

As the latest version of the AI ​​image generation model, StableDiffusion3 comes with great expectations. I believe that many friends must have used the image generation model more or less in work and life, so let’s share Stablediffusion3 below. Let’s take a look at the local construction process. Without further ado, here’s the practical information. The platform configuration used in this build is as follows: Considering the strong demand for computing power when running Stablediffusion3 locally, we chose the GALAXY GeForceRTX4070TiSUPER Xingyao OC graphics card this time. GEFORCERTX4070TiSUPER is built based on the AD103 core and is also the largest graphics card of this kind.

See all articles