WeChat Public Account Development tutorial 9th-QQ Send and receive emoticons _php tutorial

Source: Internet
Author: User
Tags comparison table
I think we will not be unfamiliar QQ expression, a small avatar greatly enriched the fun of chatting, so that chat is no longer a simple narrative, but also with the joy, anger, sorrow, music and other expressions of the mood of the small picture. This article focuses on how to use the QQ expression in the public platform, that is, in the public account development mode, how to send QQ expression to the user, and how to identify the user is the QQ expression.

QQ Expression Code table

First of all, it needs to be clear: QQ expression, although presented as a dynamic expression picture, but in the public platform of the message interface is a text message, that is, when users send QQ expression to the public account, the public account daemon received the message type Msgtype value of text. As long as the above point is understandable, the following work will be done.

For QQ expression, send is text message, but appear is the expression picture, then every QQ expression picture must have corresponding expression code. Below is the QQ Expression code table used in the public account I have compiled:

The above is a list of 105 QQ expressions, each expression gives the corresponding text code and symbol code (perhaps these two are not appropriate), as to how the two code and how to use, the following will be discussed.

Users send QQ emoticons to public accounts

In the use of public accounts, how to send QQ expression, I think this few people will not. Next to the input box has a smiley face Picture button, click on it will pop up the expression selection screen, can choose the expression "QQ expression", "symbolic expression" and "animated expression". When we click on the selected QQ expression, found in the input box will display the expression of the text code, here is a pair of brackets caused by, as shown in:

In fact, when we are familiar with the use of QQ emoticons text code, you can also directly enter the expression code in the input box, without the need to pop up the expression selection box. As shown in the following:

As can be seen in the input box to enter the "[Bared]", "/Bared Teeth" and "/::D" The role of the three code, are sending bared teeth QQ expression. This time, we go back to see the article at the beginning of the QQ Expression Code Comparison table, I understand what is going on.

Public accounts send QQ emoticons to users

With the user to the public account to send QQ expression, in the development mode, the public account can also use the same expression code (text code or symbol code) to reply to the user QQ expression. The code snippet is as follows:

Text message if (Msgtype.equals (Messageutil.req_message_type_text)) {//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 ("[sad]/sad/::(");//The text message object is converted to an XML string respmessage = Messageutil.textmessagetoxml (textmessage);}
The function of the above code fragment is: To determine the type of message sent, if it is a text message (msgtype=text), then reply to three sad QQ expression to the user. It can be seen that whether the user to the public account, or public account to the user, you can use the QQ expression text code (such as: [Sad]/sad) and symbol code (such as/::().

Public account to identify QQ expressions sent by users

After mastering how to send QQ expression, we come to see how the public account to identify the user is sent QQ expression. What does that mean? When the user sends a QQ expression to the public account, what value will be received in the backstage program, how do we know this value is a QQ expression.

In fact, as long as a simple test, such as: The received text message output to the log (can be used log4j or System.out.print), it is not difficult to find: send a QQ expression to the public account, in the background program received QQ expression symbol code.

Here is my simple encapsulation of a method, through the regular expression, to determine whether the user is sending a single QQ expression.

/** * Determine whether it is QQ expression * * @param content * @return */public static Boolean isqqface (String content) {Boolean result = false;// A regular expression for judging qq expression string Qqfaceregex = "/::\\) |/::~|/::b|/::\\| | /:8-\\) |/::<|/::$|/::x|/::z|/:: ' \ \ (|/::-\\| | /::@|/::P |/::D |/::o|/::\\ (|/::\\+|/:--b|/::q|/::t|/:,@p|/:,@-d|/::d |/:,@o|/::g|/:\\|-\\) |/::!| /::l|/::>|/::,@|/:,@f|/::-s|/:\\?| /:,@x|/:,@@|/::8|/:,@!| /:!!!| /:xx|/:bye|/:wipe|/:d ig|/:handclap|/:&-\\ (|/:b-\\) |/:<@|/:@>|/::-O |/:>-\\| | /:P-\\ (|/:: ' \\| | /:x-\\) |/::\\*|/:@x|/:8\\*|/:p d|/:
 
  
   |/:beer|/:basketb|/:oo|/:coffee|/:eat|/:p ig|/: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|/: 
   
    |/:jump|/:shake|/: 
    
     |/: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;} 
    
 
   

  
 
The following is the use of methods, the implementation of such a simple function: The user sends what QQ expression to the public account, the public account will reply to what QQ expression to the user (Xiaoqrobot is to do so). The implementation code is as follows:

Text message if (Msgtype.equals (Messageutil.req_message_type_text)) {//Text message contents String content = Requestmap.get ("content");// Determine if the user is sending a single QQ expression if (xiaoqutil.isqqface (content)) {//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);// The user sends what QQ expression, return what QQ expression textmessage.setcontent (content);//Convert text message object to XML string respmessage = Messageutil.textmessagetoxml ( TextMessage);}}
Well, about the use of QQ expression in the public account is introduced so much. In fact, I do not want to be a beginner to simply copy the code I posted, to achieve the function I want to be finished, but also hope that the novice friends can learn a way to think and solve problems through this article.


http://www.bkjia.com/PHPjc/444568.html www.bkjia.com true http://www.bkjia.com/PHPjc/444568.html techarticle I think we will not be unfamiliar to QQ expression, a small avatar greatly enriched the fun of chatting, making chat is no longer a simple narrative, but also with the XI, anger, sorrow, music and other tables ...

  • Related Article

    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.