


WeChat Public Account Development Tutorial Part 11 - Sending Emoticons (Part 1)_PHP Tutorial
Digression (can be skipped)
I believe this article has made everyone wait for too long. It’s not that I’m trying to be mysterious and whet everyone’s appetite, but it really takes too much time to write an article. Maybe it takes you 3-5 minutes to read an article and learn to master it, but it takes me 2-3 hours to complete it. Maybe only those who have carefully written the article can understand it. I hope everyone can learn from each other. Be considerate!
Someone once told me that the things I wrote were too elementary and were entry-level. Well, I admit that it is difficult to satisfy all readers. In addition, I am only a novice. I only heard about the term WeChat public platform 4 months ago. Thank you for motivating me in different ways. I will work harder!
The 9th article introduces the sending and receiving of QQ emoticons. After that, many friends asked me how to send emoji (called emoticons on WeChat), which gave me the determination to write this article. Before that, I conducted a lot of searches on the Internet and found that there were no articles introducing this aspect at all. I also asked questions in the official WeChat public account development communication group, and few people knew how to send emoji expressions. Today, let us uncover its mystery together!
Article Summary
This article focuses on how to send emoticons to users through program code in WeChat public account development mode. As for how to identify whether the user sends emoticons, I will not explain it here, leaving you with some room for learning and thinking. I just want to give you a tip: when a user sends an emoticon to a public account, it is actually a text message. This behaves the same as QQ. Since it is a text message, if the received emoticon content is printed to the log, then everyone will know Is there text corresponding to the expression? Haha, of course it is not that simple. Unlike other text messages, here you need to convert the encoding of the received emoticon message first. Okay, that’s all.
Understand emoticons
In the main interactive interface of the public account, there is a smiley face picture button next to the input box at the bottom of the window. Clicking it will pop up the emoticon selection interface. The selectable emoticons are "QQ emoticon", "symbol emoticon" and " "Animation Emoticon", we select "Symbol Emoticon" and you will see the interface as shown below:
It can be seen that compared to QQ emoticons, symbolic emoticons are more practical. Why do you say that? Because most QQ emoticons are facial expressions, and symbolic emoticons, in addition to facial expressions, there are many emoticons closely related to life, such as: animals, flowers, trees, television, telephones, computers, guitars, balls, vehicles, etc. . Would it be more lively and interesting if emoticons could be used in messages?
Let’s take a look at the effect of using emoticons in the little q robot. Let’s take a look at the two pictures:
The screenshot on the left is the main menu of the little q robot. The emoticon next to the text in the Q circle of friends is a symbolic emoticon. It is a girl and a boy. It means that you can make more friends in the Q circle of friends. Don’t Wrong thinking, ^_^. The screenshot on the right is a guide for using the face recognition function. The "camera" and "grimace" in it are also symbolic expressions. Doesn't this look more interesting? If it is pure text, it will definitely appear too monotonous and boring.
Classification of Emoji expressions
There are many versions of Emoji, including Unified, DoCoMo, KDDI, Softbank and Google, and the emoticon codes of different versions are also different. What’s even more disgusting is: different mobile operating systems, or even different versions of the same operating system. The supported emoji expressions are different. Therefore, perfectionists can stop, because currently emoji expressions are not guaranteed to work properly on all terminals.
Fortunately, I have tested the use of emoji expressions on more than 10 terminals, including iPhone 4S, iPhone 5, Android 2.2, Android 4.0+, Win8, and iPad2. Only a few terminals cannot display it. Or it is displayed as a small square, so it doesn’t have much impact, so you can use it with confidence!
Unified version of Emoji code list
The several versions of emoji expressions introduced above are all represented by unicode encoding. In other words, the unicode encoding values corresponding to different versions of emoji expressions are also different. In this article, I first give the code list of the Unified version of emoji expressions, as shown below:
How to send emoji expressions to users from public accounts
The unified unicode code comparison table of emoji expressions has been given above. So how to use these codes to send the corresponding emoji expressions? If you simply write the emoji code directly in the Content of the text message like you use the QQ emoticon code, it will definitely be displayed as it is.
A Java method is needed here for conversion processing. The code of the method is as follows:
/** * emoji表情转换(hex -> utf-16) * * @param hexEmoji * @return */ public static String emoji(int hexEmoji) { return String.valueOf(Character.toChars(hexEmoji)); }
Method description: For example, the unicode encoding value of "bicycle" is U+1F6B2. If we want to use the emoji expression "bicycle" in the program code, we need to use it like this:
String bike = String.valueOf(Character.toChars(0x1F6B2));
In fact, the previous emoji() method is a simple encapsulation of the above line of code. Now you know how to use the emoji expression code. In fact, it is to replace U+ in the code table with 0x, then call the emoji method to convert, put the converted result in the Content of the text message, and the emoji expression will be displayed when it is returned to the user. .
Below, I give a complete example of using emoji expressions, as follows:
package org.liufeng.course.service; import java.util.Date; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.liufeng.course.message.resp.TextMessage; import org.liufeng.course.util.MessageUtil; /** * 核心服务类 * * @author liufeng * @date 2013-05-20 */ public class CoreService { /** * 处理微信发来的请求 * * @param request * @return */ public static String processRequest(HttpServletRequest request) { String respMessage = null; try { // xml请求解析 Map<String, String> requestMap = MessageUtil.parseXml(request); // 发送方帐号(open_id) String fromUserName = requestMap.get("FromUserName"); // 公众帐号 String toUserName = requestMap.get("ToUserName"); // 回复文本消息 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("自行车" + emoji(0x1F6B2) + " 男性" + emoji(0x1F6B9) + " 钱袋" + emoji(0x1F4B0)); respMessage = MessageUtil.textMessageToXml(textMessage); } catch (Exception e) { e.printStackTrace(); } return respMessage; } /** * emoji表情转换(hex -> utf-16) * * @param hexEmoji * @return */ public static String emoji(int hexEmoji) { return String.valueOf(Character.toChars(hexEmoji)); } }
The function of the above code is: no matter what type of message the user sends, it will return a text message containing three emoji expressions. If you don’t understand what’s going on with the CoreService class, please check out Part 5 of this series of tutorials, or you just need to read line 42 of the code carefully to know how to put the emoji expression code in the Content of the text message. Finally, let’s take a look at the screenshot of the running effect:
This is the end of this article, but the explanation of emoji expressions is not over yet. Why do you say that? Please look carefully at the second screenshot of this article, which is the text menu of the Xiaoq robot. The emoji expressions used in it cannot be found in the emoji code table given in this article (the emoji expressions and code table on WeChat Exactly the same), then how is this emoji expression sent? Please listen to the next chapter for the breakdown!
If you think the article is helpful to you, please support Liu Feng by leaving a message or following the WeChat public account xiaoqrobot!
When reposting, please indicate that this article comes from Liu Feng’s blog (http://blog.csdn.net/lyq8479). Please respect the results of other people’s hard work. Thank you!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to master Bootstrap customization and component usage includes: 1. Use CSS variables and Sass preprocessor for style customization; 2. Deeply understand and modify component structure and behavior. Through these methods, a unique user interface can be created to improve the responsiveness and user experience of the website.

H5. The main difference between mini programs and APP is: technical architecture: H5 is based on web technology, and mini programs and APP are independent applications. Experience and functions: H5 is light and easy to use, with limited functions; mini programs are lightweight and have good interactiveness; APPs are powerful and have smooth experience. Compatibility: H5 is cross-platform compatible, applets and APPs are restricted by the platform. Development cost: H5 has low development cost, medium mini programs, and highest APP. Applicable scenarios: H5 is suitable for information display, applets are suitable for lightweight applications, and APPs are suitable for complex functions.

This article provides a detailed guide to safe download of Ouyi OKX App in China. Due to restrictions on domestic app stores, users are advised to download the App through the official website of Ouyi OKX, or use the QR code provided by the official website to scan and download. During the download process, be sure to verify the official website address, check the application permissions, perform a security scan after installation, and enable two-factor verification. During use, please abide by local laws and regulations, use a safe network environment, protect account security, be vigilant against fraud, and invest rationally. This article is for reference only and does not constitute investment advice. Digital asset transactions are at your own risk.

Compatibility issues and troubleshooting methods for company security software and application. Many companies will install security software in order to ensure intranet security. However, security software sometimes...

H5 is more flexible and customizable, but requires skilled technology; mini programs are quick to get started and easy to maintain, but are limited by the WeChat framework.

Discussion on the JS resource caching issue of Enterprise WeChat. When upgrading project functions, some users often encounter situations where they fail to successfully upgrade, especially in the enterprise...

The choice of H5 and applet depends on the requirements. For applications with cross-platform, rapid development and high scalability, choose H5; for applications with native experience, rich functions and platform dependencies, choose applets.

Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...
