C # develop WeChat portals and applications (3) -- Response to text messages and text messages

Source: Internet
Author: User

The object class of the Message Base Class BaseMessage is defined as follows. It constructs an integer value for the date and has some common attributes. In addition, there is an important ToXML method, used to pass the XML data to the method. Copy the code /// <summary> /// basic message content /// </summary> [XmlRoot (ElementName = "xml")] public class BaseMessage {// <summary> // initialize some content, such as the creation time is an integer, /// </summary> public BaseMessage () {this. createTime = DateTime. now. dateTimeToInt ();} // <summary> // developer ID // </summary> public string ToUserName {get; set ;} /// <summary> /// sender account (an OpenID) /// </summary> public string FromUserName {get; set ;}/// <s Ummary >/// 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) ;}} the text message entity class code returned by the copy code is as follows. We can see that it inherits many common entity attributes, we also have a general ToXml method. We can use this method when converting it into the response XML. Copy the code /// <summary> /// reply to a 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 strin G Content {get; set ;}} copies the code and the message object class ResponseNews, it contains more information to define the copy code /// <summary> /// reply to text 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 and image messages, limited to 10 or less /// </summary> public int ArticleCount {get {return this. articles. count;} set {; // Add this step to display the XML content }}/// <summary> // graphic list. /// Multiple text message items. By default, the first item is a large image. Note that if the number of text items exceeds 10, no response is returned. /// </summary> [System. xml. serialization. xmlArrayItem ("item")] public List <ArticleEntity> Articles {get; set ;}} copies the code and the object in the text List set, which is also an object type, contains some text links, titles, and other information. 2. For text messages, we can process them in the following ways. ResponseText response = new ResponseText (info); response. Content = "sorry, this function is not yet activated. "; Result = response. ToXml (); for graphic messages, we may need to enter more messages to return better results. Pay attention to text message. The size of the image is best in accordance with the official standard. Otherwise, it may not look good on the mobile phone. The official standard seems to be width/height (360,200) pixel copy code /// <summary> /// subscribe to or display company information /// </summary> /// <param name = "info"> </param>/ // <returns> </returns> private string ShowCompanyInfo (BaseMessage info) {string result = ""; // ResponseNews response = new ResponseNews (info); ArticleEntity entity = new ArticleEntity (); entity. title = "Guangzhou aiqidi Software Technology Co., Ltd."; entity. description = "Welcome to Guangzhou aiqidi software, a professional enterprise information software and software development framework provider. We are determined to provide the best software and services for our customers. \ R \ n "; entity. description + = "we are an innovative software technology company engaged in research, development and sales of the most reliable, secure, and easy-to-use technical products and high-quality professional services, help customers and partners around the world to succeed. \ R \ n ...... (1000 words are 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;} copy the 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.