Micro-Credit Public account development tutorial text message all Raiders _java

Source: Internet
Author: User
Tags blank page

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 graph (the number of messages, limited within 10);
    2. For multiple text messages, the first picture is displayed as a large image, and other pictures display as small image;
    3. The first text picture size suggested for 640*320, other pictures and texts of the picture size suggested for 80*80;

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 Request * * @param req
 Uest * @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 quotation mark of the string itself, you want to escape textmessage.setcontent ("Welcome to <a href=\" http://blog.csdn.net/lyq8479\ "
 > Liu Feng's 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 the text message content sent by the user String content = requestmap.get ("Cont
 Ent ");
 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 Article = 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,", "+ emoji (0x1f6b9) +", micro-letter 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! \ n \ nyou have launched a total of 12 tutorials, including interface configuration, message encapsulation, frame structure, QQ expression Send, symbolic expression sent. \ n later also plans to launch a number of practical features of the development of the explanation, 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 = new Article ();
  Article1.settitle ("Introduction to micro-credit public account Development tutorial");
  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 ("2nd of the type of micro-trust public account");
  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 article \ 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 article1 = 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 \ Package of message and message processing Tools");
  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 article \ 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 limit uncovered");
  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);
  //Multiple text message---The last message does not contain a picture else if ("5". Equals (content)) {Article article1 = new Article ();
  Article1.settitle ("7th article \ n the use of line breaks in text messages");
  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 ("8th article \ n Text message using a Web page HYPERLINK");
  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 feel the articleFor your help, please message or focus on 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/public static String emoji (int hexemoji) {R
 Eturn string.valueof (Character.tochars (Hexemoji));
 }
}

The above code realizes the function is when the user sends the number 1-5, replies separately five different forms the message to the user, as follows:

A the user sends 1, replies the single text message. Reference code 68~81 line, the effect is as follows:

b The user sends 2, replies the single text message---does not contain the picture. Reference code 82~96 line, the effect is as follows:

Description: Text message title, description can include QQ expression, sign expression.

c the user sends 3, replies the multiple text message. Reference code 97~123 line, the effect is as follows:

Description: For multiple text messages, the description will not be displayed, you can use line breaks in the title, making the display more beautiful.

d The user sends 4, replies the multiple text message---The first message does not contain the picture. Reference code 124~158 line, the effect is as follows:

E The user sends 5, replies the multiple text message---The last message does not contain a picture. Reference code 159~186 line, the effect is as follows:

It can be seen that the message has a rich content and diverse forms of expression, I hope that we can according to their characteristics and the actual use needs, reasonable use.

Finally, based on practical experience, I make a summary of the use of text messages :

1 must assign a value to the URL property of the text message. whether it is a single text, or more text, or without pictures of the text, there may be users click. If the URL is empty, the user will open a blank page after clicking, which gives the user the experience is very poor;

2 only a single graphic description will be displayed, the description of multiple graphics will not be displayed ;

3 Text Message title, description can use QQ expression and sign expression. The rational use of emoticons will make the message more vivid;

4 Text Message title, the description can be used in line breaks. The rational use of line breaks will make the content structure more clear;

5 text Message title, the description does not support hypertext link (HTML <a> tags). not only technically can not be achieved, even logically, because a text message anywhere is clicked, will invoke the micro-letter built-in browser to open the URL, if the title, the description of a few hyperlinks, do not know click on which page to open. I do not understand why there are several students are asking this question, is not designed to be a lot of graphics and text is not good?

6 text message link, picture link can use the resources under the external domain name, as in this example: Liu Feng's head, the link of Bowen, all is the resource that points to CSDN website. On the Internet, even micro-letter official Exchange Group, that the text message URL, Picurl can not use outside the chain of the crowd, do not know where this rumor began, practice is the only criterion to test the truth!

7 Use a picture of the specified size. The first text picture size is recommended for 640*320, other picture size suggested for 80*80. If you use a picture that is too large, slow to load, and consumes a lot of traffic, if you use a picture that is too small, it will be stretched and distorted.

8 The picture and text of each message of the proposed control in 1-4. In this way, most terminals on a screen can be displayed, users can scan a glance to understand the main content of the message, which is most likely to motivate users to click and read.

The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring some help, but also hope that a lot of support cloud Habitat community!

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.