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); }
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|/::'\\(|/::-\\||/::@|/::P|/::D|/::O|/::\\(|/::\\+|/:--b|/::Q|/::T|/:,@P|/:,@-D|/::d|/:,@o|/::g|/:\\|-\\)|/::!|/::L|/::>|/::,@|/:,@f|/::-S|/:\\?|/:,@x|/:,@@|/::8|/:,@!|/:!!!|/:xx|/:bye|/:wipe|/:dig|/:handclap|/:&-\\(|/:B-\\)|/:<@|/:@>|/::-O|/:>-\\||/:P-\\(|/::'\\||/: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; }
// 文本消息 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); } }