WeChat public account development tutorial 11th-sending of symbolic expressions (I) _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Article 3 of the public account development tutorial-sending of symbolic expressions (I ). I believe that this article has made everyone wait for too long. it does not mean that it takes too much time to write an article. Maybe an external question (you can skip it)

I believe this article has made everyone wait for too long. it takes too much time to write an article instead of being confused and appetizing. Maybe it takes 3-5 minutes for you to finish reading an article and learn how to master it, but it takes 2-3 hours for me to complete it, maybe only those who have carefully written articles can understand it and hope everyone can understand each other!

Some people once told me that what I write is too basic and is an entry level. Well, I admit it's hard to satisfy all the readers. In addition, I am just a newbie, a beginner who heard about the word "public platform" before April, thank you for your encouragement in different ways. I will work harder!

9th articles introduce sending and receiving QQ expressions. After that, many of my friends asked me how to make emoji expressions (called symbolic expressions), which gave me the determination to write this article. Before that, I searched a lot on the internet and found that I did not introduce this article at all. I also asked a question in the official public account development group, few people know how to send emoji. Today, let's unveil its mysteries together!

Article overview

This article focuses on how to send symbolic expressions to users through program code in the public account development mode. As for how to identify a user sending a symbolic expression, we will not explain it here, leaving you with a little space for learning and thinking. I just gave you a prompt: a user sends a symbolic expression to a public account, which is actually a text message, which is the same as QQ, that is, a text message, print the received symbolic emoticon content to the log. don't you know the text corresponding to each emoticon? Haha, of course, it's not that simple, it's not like other text messages. here we need to connect to the received symbolic emoticon message and perform encoding conversion first. Well, there are so many prompts.

Recognize symbolic expressions

On the main interaction interface of the public account, there is a smiley image button next to the input box at the bottom of the window. Clicking it will bring up the selection interface, you can select "QQ emoticons", "symbol emoticons", and "animated emoticons" in sequence. we select "symbol emoticons" and you will see the interface shown in:

It can be seen that the symbolic expression is more practical than the QQ expression. Why? Because QQ expressions are mostly facial expressions, in addition to facial expressions, there are also many expressions closely related to life, such: animals, flowers, trees, TV, telephone, computer, guitar, ball games, transportation, etc. Will it be more vivid and interesting to use a symbolic expression in a message?

Let's take a look at the effect of the symbolic expression used in the Q robot. The first two figures are shown:

On the left is the main menu of the Q robot. the expression next to the Q circle text is a symbolic expression, a female, a male, and a friend of two, it indicates that you can get to know more friends in Q's circle of friends. On the right side is a guide to the use of facial recognition functions. the "camera" and "grimace" inside are also symbolic expressions. does this look more interesting? If it is plain text, it will be too monotonous and boring.

Emoji classification

There are many Emoji versions, including uniied, DoCoMo, KDDI, Softbank, and Google. the Emoji code of different versions is different. What's worse: different mobile phone operating systems and even different versions of the same operating system support different emoji expressions. Therefore, Perfectionists can stop, because currently, emoji expressions cannot be used properly on all terminals.

Fortunately, I have tested emoji on more than 10 terminals, including iPhone 4 S, iPhone 5, Android 2.2, Android 4.0 +, Win8, and iPad2, only a few terminals cannot be displayed or displayed as a small square, so there is no big impact, so you can rest assured to use it!

Uniied version of Emoji emoticon code table

The emoji expressions of the previous versions are represented by unicode encoding. In other words, the unicode encoding values of emoji expressions of different versions are different. In this article, I will first give a code table for the emoji of the uniied version, as shown in:

How do public accounts send emoji to users?

The above provides the uniied unicode code table for emoji expressions. how can I use these codes to send the corresponding emoji expressions? If you simply write the emoji code in the Content of a text message like using the QQ emoticons code, it will be displayed as it is.

Here we need to use a Java method for conversion. the code of the method is as follows:

/*** Emoji conversion (hex-> UTF-16) *** @ param hexEmoji * @ return */public static String emoji (int hexEmoji) {return String. valueOf (Character. toChars (hexEmoji ));}

Method description: for example, the unicode value of "bicycle" is U + 1F6B2. if we want to use the emoji "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 code. Instead, replace the U + in the code table with 0x, call the emoji method for conversion, and place the converted result in the Content of the text message, the emoji will be displayed when it is returned to the user.

The following is a complete example of using emoji:

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; /*** core service class ** @ author liufeng * @ date 2013-05-20 */public class CoreService {/*** process sent requests ** @ param request * @ return */public static String processRequest (HttpServletRequest request) {String respMessage = null; try {// xml request parsing Map
 
  
RequestMap = MessageUtil. parseXml (request); // sender account (open_id) String fromUserName = requestMap. get ("FromUserName"); // public account String toUserName = requestMap. get ("ToUserName"); // reply to the text message 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 ("bicycle" + emoji (0x1F6B2) + "male" + emoji (0x1F6B9) + "wallet" + emoji (0x1F4B0); respMessage = MessageUtil. textMessageToXml (textMessage);} catch (Exception e) {e. printStackTrace ();} return respMessage;}/*** emoji conversion (hex-> UTF-16) ** @ param hexEmoji * @ return */public static String emoji (int hexEmoji) {return String. valueOf (Character. toChars (hexEmoji ));}}
 

The purpose of the above code is to return text messages containing three emoji expressions no matter what type of messages the user sends. If you do not understand what is going on with the CoreService class, check the 5th articles in this series of tutorials, or you only need to carefully read the 42nd lines of code, I know how to put the emoji code in the Content of a text message. Finally, let's take a look at the running effect:

The content of this article is now over, but the explanation of emoji is not over. why? Take a closer look at the second one in this article, that is, the text menu of the Q robot, the emoji expressions used in this article cannot be found in the emoji code table provided in this article (the emoji expressions on are exactly the same as those in the code table). how can I send this emoji expression, please try again!

If the article is helpful to you, please leave a message or follow the public account xiaoqrobot to support Liu Feng!

Post please indicate this article from Liu Feng blog (http://blog.csdn.net/lyq8479), please respect others' hard work results, thank you!


Sorry, I believe this article has made everyone wait for too long. it takes too much time to write an article instead of being confused and appetizing. Maybe one...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.