WeChat Public Account development tutorial 11th-Sending of symbolic emoticons (on) _php tutorial

Source: Internet
Author: User
Tags comparison table
Off-topic (can skip)

I believe this article has let everyone wait too long, not my trick, hang everyone's appetite, but write an article really need to spend too much time. Perhaps an article, you spend 3-5 minutes to read, school will master, and I will spend 2-3 hours of time to complete, perhaps only attentively wrote the article the person can understand, hope we can mutual understanding!

Someone once said to me, I write things too elementary, are entry-level things. Well, I admit that tune, it is difficult to meet all the readers, plus I am just a novice, a April ago only to hear the word public platform for beginners, thank you in different ways to my motivation, I will work harder!

The 9th article introduces the sending and receiving of QQ expression. After this, many friends asked me how to send emoji expression (the sign expression), also let me have to write this article's determination. Before that, I did a lot of searching on the internet, found that there was no introduction to this article, and asked questions in the public Account Development official communication group, and few people knew how to send emoji expression. Today, let us come together to uncover its mystery!

Article overview

This article focuses on how to send a symbolic expression to the user through the program code in the public account development mode. As to how to identify the user sent a symbolic expression, it is not explained here, leaving us a little space to learn to think. I just give you a hint: the user to the public account to send symbolic expression, is actually a text message, which is the same as the QQ performance is the same, that is, text message, will receive the symbol expression content printed to the log, do not know each expression corresponding text? Hehe, of course, it is not so simple, not like other text messages, here need to connect to receive symbolic expression message first to do encoding conversion. All right, so much for the tip.

Recognize symbolic expressions

In the public account of the main interface, the window at the bottom of the input box next to a smiley face Picture button, click on it will pop up the expression selection interface, can choose the expression "QQ expression", "symbolic expression" and "animated expression", we choose "symbolic expression", we will see the interface as shown:

Can be held to see, compared to QQ expression, symbolic expression to be more practical. Why do you say that? Because most of the QQ expression is facial expression, and the symbolic expression in addition to facial expressions, there are a lot of life-related expressions, such as: Animals, flowers, trees, television, telephone, computer, guitar, ball, transport and so on. If you can use symbolic expressions in messages, will it appear more vivid and interesting?

Take a look at the effect of using symbolic expressions in a small Q robot, first two pictures:

On the left is the main menu of the small Q robot, in the Q circle next to the expression is the symbol expression, is a woman a man and two children, signaling in Q Circle can get to know more friends, do not think crooked, ^_^. On the right is the use of the face Recognition function guide, the inside of the "camera", "grimace" is also a symbolic expression, so it seems more interesting? If it is plain text, it will appear too monotonous, too dull.

The classification of emoji expression

There are many versions of the emoji expression, including unified, DoCoMo, KDDI, SoftBank and Google, and different versions of the expression code are not the same, and more abhorrent is: different mobile phone operating systems, Even the emoji expressions supported by different versions of the same operating system are not the same. Therefore, the perfectionist can stop, because the current emoji expression does not guarantee that all terminals can be used normally.

Fortunately, I have tested the use of emoji expressions on more than 10 more than terminals, including iphone 4S, iphone 5, Android 2.2, Android 4.0+, Win8, iPad2, which are not displayed or displayed as a small square on very individual terminals. , so there is no big impact, you can rest assured that the use of it!

Unified version of Emoji Expression Code table

Several versions of the emoji expression described above are represented by Unicode encoding. In other words, different versions of the emoji expression correspond to the same Unicode encoding values. In this article, I first give the unified version of the Emoji Expression Code table, as shown in:

How public accounts send emoji emoticons to users

Above has given the emoji expression of the unified Unicode Code Comparison table, then how to use these code to send out the corresponding emoji expression? If you just like using the QQ expression code, directly in the content of the text message to write emoji expression code, must be displayed as is.

Here a Java method is needed to do the conversion processing, the code of the method is as follows:

/** * Emoji expression conversion (hex--utf-16) *  * @param hexemoji * @return */public static String emoji (int hexemoji) {return Str Ing.valueof (Character.tochars (Hexemoji));}

Method Description: For example, "bike" Unicode encoded value is U+1F6B2, if we want to use in the program code "bicycle" This emoji expression, need this use:

String bike = string.valueof (Character.tochars (0X1F6B2));

In fact, the previous emoji () method is a simple encapsulation of the above line of code. Now know how to use the emoji expression code, in fact, is to replace the u+ in the code table with 0x, and then call the emoji method to convert, put the converted results in the content of the text message, return to the user will show the emoji expression.

Below, I give a complete example of using emoji emoticons, 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;/** * Core Service class * * @author Liufeng * @date 2013-05-20 */public class Coreservice {/** * Processing Requests Sent * * @param request * @return */public static string ProcessRequest (HttpServletRequest request) {string Respmessag E = 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 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 ("Bike" + emoji (0x1f6b2) + "male" + emoji (0x1f6b9) + "purse" + emoji (0x1f4b0) ); respmessage = Messageutil.textmessagetoxml (textmessage);} catch (Exception e) {e.printstacktrace ();} return respmessage;} /** * Emoji expression conversion (hex--utf-16) * * @param hexemoji * @return */public static string emoji (int Hexemoji) {return string
. ValueOf (Character.tochars (Hexemoji));}} 
  
 

The code above is to return a text message containing three emoji emoticons, regardless of what type of message the user sends. If you don't understand what's going on in the Coreservice class, check out the 5th article in this series, or you just need to look at the 42nd line of code and know how to put the emoji expression code in the content of the text message. Finally look at the effect of the operation:

The content of this article is finished, but the explanation about emoji expression is not over, why do you say so? Please take a closer look at the second sheet of this article, that is, the small Q Robot Text menu, the emoji expression used in this article is not found in the Emoji Code list (on the emoji expression and the Code table exactly the same), then this emoji expression is how to send it, please listen to tell!

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

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


http://www.bkjia.com/PHPjc/444566.html www.bkjia.com true http://www.bkjia.com/PHPjc/444566.html techarticle off-topic (can skip) believe this article has let everyone wait too long, not my trick, hang everyone's appetite, but write an article really need to spend too much time. Maybe a ...

  • 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.