C # development WeChat Portal and Application (iii) text message and message reply

Source: Internet
Author: User
This article is mainly for you to introduce the C # development portal and application of the second, text messages and texts of the response, with a certain reference value, interested in small partners can refer to

Application in full swing, many companies want to catch Information Express, this is a business opportunity, is also a technical direction, therefore, the research under the study of the relevant development, also become one of the planning things. This series of articles hope that from a gradual point of view, a comprehensive introduction of the relevant development process and related experience summarized, I hope to give you a look at the relevant development history.

In the previous two essays, "C # Development Portal and Applications (1)-Getting Started with interfaces" and "C # Development Portal and Applications (2)-Message processing and response", this essay goes on to introduce the framework of my application, and introduces the topic of text reply and the process of textual reply.

We know that to send a response message to mobile users, it can be divided into a number of ways, such as replying to text messages, reply to picture messages, reply to voice messages, reply to video messages, reply to music messages, reply text messages, and so on, as shown below.

And the picture, video, voice, these three ways, it is necessary to open authentication to send users to the presence of media information on the server, generally no certification of the public number or service number, is not able to send these kinds of content.

1. Entity Information Relationship and definition

In the last essay I developed, I showed the application entity classes for receiving messages and reply messages that I had encapsulated on an application level, as needed, according to development needs, such as the message relationship for replies, as shown below.

The entity class definition for the message base class Basemessage is as follows, it constructs a numeric value for the date, has some general properties, and an important ToXml method for passing the XML data to the method.


<summary>  ////Basic message content///</summary> [XmlRoot (elementname = "xml")] public  class Basemessage {//<summary>////    Initialize some content, such as create time for shaping,/    ///</summary> public    Basemessage ()    {this      . Createtime = DateTime.Now.DateTimeToInt ();    }    <summary>///Developer number///    </summary> public    string Tousername {get; set;}    <summary>    ///Sender account (one OpenID)///    </summary> public    string Fromusername {get; set;}    //<summary>///Message creation time (integer)///    </summary> public    int Createtime {get; set;}    <summary>////message type///    </summary> public    string Msgtype {get; set;}    Public virtual string ToXml ()    {this      . Createtime = DateTime.Now.DateTimeToInt ();//re-update      return myxmlhelper.objecttoxml (this);}  }

Reply to the text message entity class Code as shown below, we can see that it inherits a lot of common entity properties, and also has a common method of toxml, we need to convert it to the XML of the response, it is possible to use this method.


  <summary>  //Reply text message  ///</summary> [System.Xml.Serialization.XmlRoot (ElementName = " XML ")] public  class Responsetext:basemessage  {public    responsetext ()    {this      . Msgtype = ResponseMsgType.Text.ToString (). ToLower ();    }    Public ResponseText (basemessage info): this ()    {this      . Fromusername = info. Tousername;      This. Tousername = info. fromusername;    }    <summary>///content//    </summary> public string content        {get; set;}  }

and the text message object class Responsenews, it contains more information definition


  <summary>  //reply message  ///</summary> [System.Xml.Serialization.XmlRoot (ElementName = " XML ")] public  class Responsenews:basemessage  {public    responsenews ()    {this      . Msgtype = ResponseMsgType.News.ToString (). ToLower ();      This. Articles = new list<articleentity> ();    }    Public responsenews (basemessage info): this ()    {this      . Fromusername = info. Tousername;      This. Tousername = info. fromusername;    }    <summary>///    number of text messages, limited to 10///    </summary> public    int articlecount    {      get      {        return this. Articles.count;      }      Set      {        ;//Increase this step to come out of XML content}}///<summary>//    graphic list. ////    multiple message messages, the default first item is a large image, note that if the number of text is more than 10, it will not respond///    </summary>    [ System.Xml.Serialization.XmlArrayItem ("item")] public    list<articleentity> articles {get; set;}  }

And in the list of objects in the collection, it is also an entity type, contains a number of graphic links, headings and other information, not repeat.

2, the reply processing of the message

For text messages, we can handle them in the following ways.


ResponseText response = new ResponseText (info); response. Content = "Sorry, this feature is not currently open. "; result = Response." TOXML ();

For text messages, we may need to enter more messages to return to better results.

Note the text message, the size of the picture is best according to the official standard, otherwise on the phone does not look good, the official standard seems to be the width of the height is (360,200) pixels


<summary>    ///Subscribe or display company information//</summary>//    <param name= "info" ></param>    //<returns></returns> private string Showcompanyinfo (basemessage info)    {      string result = "";      responsenews response = new Responsenews (info) using the graphics and text information on the platform (single graphic information);      articleentity entity = new articleentity ();      Entity. Title = "Guangzhou Echidi Software Technology Co., Ltd.";      Entity. Description = "Welcome to Guangzhou Echidi Software--Professional unit information software and software development framework provider, we are determined to provide customers with the best software and services. \ r \ n ";      Entity. Description + = "We are a highly innovative software technology company engaged in research, development and sales of the most reliable, safe and easy-to-use technology products and high-quality professional services to help customers and partners worldwide succeed. R \ n ... (1000 words omitted here, haha) ";      Entity. Picurl = "Http://www.iqidi.com/WeixinImage/company.png";      Entity. URL = "http://www.iqidi.com";      Response. Articles.add (entity);      result = Response. TOXML ();      return result;    }

Let's take a look at my company's portal menu and look cool.

For these two (text messages, graphics messages) is the most places, many portals, are mainly used in these two ways to respond. Of course, we can also be based on the customer's mobile phone submission of various messages to different processing, the type of request message I have in the previous essay is introduced, as shown below.

Need to focus on understanding the overall effect, you can use direct scanning QR code.

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.