Micro-Credit Public account development tutorial (13) text message all Raiders

Source: Internet
Author: User
Tags expression

Introduction and summary of content

Several readers have complained that "Liu Feng only uses text messages as an example, never mention the picture and text message, do not know how to use the message", well, I was wrong, originally thought that the basic API encapsulation, the framework to build, and then give a text message to use the example, we can suit, Perhaps because of my poor painting skills, the picture of the cat is not like the cat bar ...

This article mainly introduces the use of text message in the development of micro-credit public account, as well as several manifestations of the text message. Title named "Text Message", this is definitely not the title party, is to take this opportunity to the text of the message related to the problem, doubts, obstacles to all clear away.

The main parameter description of the picture and text message

Through the micro-letter Official Message Interface guide, you can see the text message parameters, as shown in the following figure:

You can see from the diagram that:

1 The number of text messages is limited to 10, that is, the value of Articlecount in the picture (the number of messages, limited within 10);

2 for multiple text messages, the first picture and text display as a large image, other pictures of the picture displayed as a small map;

3 The first text picture size suggested for 640*320, other pictures and texts of the picture size suggested for 80*80;

Well, to understand these, and combined with the 4th article on the message and Message processing tool encapsulation, want to reply to the text message to the user is not difficult.

Multiple manifestations of a text message

Below directly through the code to illustrate the main five manifestations of the use of text messages, the source code is as follows:

Package org.liufeng.course.service;  
Import java.util.ArrayList;  
Import Java.util.Date;  
Import java.util.List;  
      
Import Java.util.Map;  
      
Import Javax.servlet.http.HttpServletRequest;  
Import org.liufeng.course.message.resp.Article;  
Import Org.liufeng.course.message.resp.NewsMessage;  
Import Org.liufeng.course.message.resp.TextMessage;  
      
Import Org.liufeng.course.util.MessageUtil; 
     /** * Core Service class * * @author Liufeng * @date 2013-07-25/public class Coreservice {/** * processing micro-letter Requests  * @param request * @return/public static String ProcessRequest (HttpServletRequest request)  
        {String respmessage = null;  
      
            try {//XML request parsing map<string, string> requestmap = messageutil.parsexml (request);  
            Sender account (open_id) String fromusername = Requestmap.get ("Fromusername"); Public account String Tousername = RequeStmap.get ("Tousername");  
      
            Message type String Msgtype = Requestmap.get ("Msgtype");  
            The default reply to this 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); Because the value of the HREF attribute must be enclosed in double quotes, which conflicts with the double quotes of the string itself, Escape textmessage.setcontent ("Welcome to <a href=" http://blog.csdn.net/lyq847  
            9 "> Liu Feng blog </a>!");  
      
            Converts a text message object to an XML string respmessage = Messageutil.textmessagetoxml (TextMessage);  
                Text message if (Msgtype.equals (Messageutil.req_message_type_text)) {//Receive text message content sent by user  
      
                String content = requestmap.get ("content");  
            Create a text message    Newsmessage newsmessage = new Newsmessage ();  
                Newsmessage.settousername (Fromusername);  
                Newsmessage.setfromusername (Tousername);  
                Newsmessage.setcreatetime (New Date (). GetTime ());  
                Newsmessage.setmsgtype (messageutil.resp_message_type_news);  
      
                Newsmessage.setfuncflag (0);  
                list<article> articlelist = new arraylist<article> ();  
                    Single text message if ("1". Equals (content)) {Article Article = new Article ();  
                    Article.settitle ("Micro-credit public Account Development Tutorial Java Edition"); Article.setdescription ("Liu Feng,", the micro-credit public account development experience 4 months. To help beginners get started, the introduction of this series of tutorials, but also hope to take this opportunity to know more peers!  
                    ");  
                    Article.setpicurl ("http://0.xiaoqrobot.duapp.com/images/avatar_liufeng.jpg");  
                    Article.seturl ("http://blog.csdn.net/lyq8479");  
                    Articlelist.add (article);  
      Set the number of text messages              Newsmessage.setarticlecount (Articlelist.size ());  
                    Set up the picture and text collection Newsmessage.setarticles (articlelist) that the message contains;  
                Converts a text message object to an XML string respmessage = Messageutil.newsmessagetoxml (newsmessage); //Single text message---does not contain pictures else if ("2". Equals (content)) {Article articl  
                    E = new Article ();  
                    Article.settitle ("Micro-credit public Account Development Tutorial Java Edition");  
                            The message can be used QQ expression, sign expression article.setdescription ("Liu Feng, after," + Emoji (0X1F6B9) + ", micro-credit public account development experience 4 months." To help beginners, the introduction of this series of serial tutorials, but also hope to take this opportunity to know more peers! NN has now launched a total of 12 tutorials, including interface configuration, message encapsulation, frame construction, QQ expression send, symbolic expression sent. NN later also plans to introduce some practical functions of development, such as: Weather forecasts, peripheral search, chat functions.  
                    ");  
                    Place the picture as an empty Article.setpicurl ("");  
                    Article.seturl ("http://blog.csdn.net/lyq8479");  
            Articlelist.add (article);        Newsmessage.setarticlecount (Articlelist.size ());  
                    Newsmessage.setarticles (articlelist);  
                Respmessage = Messageutil.newsmessagetoxml (newsmessage); //Multiple text message else if ("3". Equals (content)) {Article Article1 = NE  
                    W Article ();  
                    Article1.settitle ("Micro-credit public account development Tutorial N Introduction");  
                    Article1.setdescription ("");  
                    Article1.setpicurl ("http://0.xiaoqrobot.duapp.com/images/avatar_liufeng.jpg");  
      
                    Article1.seturl ("http://blog.csdn.net/lyq8479/article/details/8937622");  
                    Article article2 = new Article ();  
                    Article2.settitle ("The 2nd article N micro-letter public account type");  
                    Article2.setdescription ("");  
                    Article2.setpicurl ("http://avatar.csdn.net/1/4/A/1_lyq8479.jpg"); Article2.seturl ("http://blog.csdn.net/lyq8479/article/details/8941577 ");  
                    Article article3 = new Article ();  
                    Article3.settitle ("3rd N Development mode enabled and interface Configuration");  
                    Article3.setdescription ("");  
                    Article3.setpicurl ("http://avatar.csdn.net/1/4/A/1_lyq8479.jpg");  
      
                    Article3.seturl ("http://blog.csdn.net/lyq8479/article/details/8944988");  
                    Articlelist.add (ARTICLE1);  
                    Articlelist.add (Article2);  
                    Articlelist.add (ARTICLE3);  
                    Newsmessage.setarticlecount (Articlelist.size ());  
                    Newsmessage.setarticles (articlelist);  
                Respmessage = Messageutil.newsmessagetoxml (newsmessage); //Multiple text message---The first message does not contain a picture else if ("4". Equals (content)) {Article AR  
                    Ticle1 = new Article ();  
                    Article1.settitle ("Micro-credit public Account Development Tutorial Java Edition"); Article1.setdescription ("");  
                    Place the picture as an empty Article1.setpicurl ("");  
      
                    Article1.seturl ("http://blog.csdn.net/lyq8479");  
                    Article article2 = new Article ();  
                    Article2.settitle ("4th article n message and Message processing tool encapsulation");  
                    Article2.setdescription ("");  
                    Article2.setpicurl ("http://avatar.csdn.net/1/4/A/1_lyq8479.jpg");  
      
                    Article2.seturl ("http://blog.csdn.net/lyq8479/article/details/8949088");  
                    Article article3 = new Article ();  
                    Article3.settitle ("5th n the reception and response of various messages");  
                    Article3.setdescription ("");  
                    Article3.setpicurl ("http://avatar.csdn.net/1/4/A/1_lyq8479.jpg");  
      
                    Article3.seturl ("http://blog.csdn.net/lyq8479/article/details/8952173");  
                    Article article4 = new Article ();  
     Article4.settitle ("6th article n text message content length limitation revealing");               Article4.setdescription ("");  
                    Article4.setpicurl ("http://avatar.csdn.net/1/4/A/1_lyq8479.jpg");  
      
                    Article4.seturl ("http://blog.csdn.net/lyq8479/article/details/8967824");  
                    Articlelist.add (ARTICLE1);  
                    Articlelist.add (Article2);  
                    Articlelist.add (ARTICLE3);  
                    Articlelist.add (ARTICLE4);  
                    Newsmessage.setarticlecount (Articlelist.size ());  
                    Newsmessage.setarticles (articlelist);  
                Respmessage = Messageutil.newsmessagetoxml (newsmessage); //multi-text message---The last message does not contain a picture else if ("5". Equals (content)) {Article  
                    Article1 = new Article ();  
                    Article1.settitle ("Use of line breaks in the 7th N Text message");  
                    Article1.setdescription (""); Article1.setpicurl ("Http://0.xiaoqrobot.duapp.com/images/avatAr_liufeng.jpg ");  
      
                    Article1.seturl ("http://blog.csdn.net/lyq8479/article/details/9141467");  
                    Article article2 = new Article ();  
                    Article2.settitle ("Use Web hyperlink in 8th N Text message");  
                    Article2.setdescription ("");  
                    Article2.setpicurl ("http://avatar.csdn.net/1/4/A/1_lyq8479.jpg");  
      
                    Article2.seturl ("http://blog.csdn.net/lyq8479/article/details/9157455");  
                    Article article3 = new Article (); Article3.settitle ("If you think the article is helpful to you, please leave a message or pay attention to the micro-letter public account Xiaoqrobot to support Liu Feng!")  
                    ");  
                    Article3.setdescription ("");  
                    Place the picture as an empty Article3.setpicurl ("");  
      
                    Article3.seturl ("http://blog.csdn.net/lyq8479");  
                    Articlelist.add (ARTICLE1);  
                    Articlelist.add (Article2);  
                    Articlelist.add (ARTICLE3);Newsmessage.setarticlecount (Articlelist.size ());  
                    Newsmessage.setarticles (articlelist);  
                Respmessage = Messageutil.newsmessagetoxml (newsmessage);  
        A catch (Exception e) {e.printstacktrace ());  
    return respmessage; /** * Emoji expression conversion (hex-> utf-16) * * @param hexemoji * @return * * * publi  
    C Static String emoji (int hexemoji) {return string.valueof (Character.tochars (Hexemoji)); }  
}

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.