In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article shows you how to achieve the text message and picture message response in the C# development Wechat portal, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.
Wechat applications are in full swing, and many companies hope to get on the information express, which is not only a business opportunity, but also a direction of technology. Therefore, it has become one of the arrangements for the plan to have time to study and learn the related development of Wechat.
We know that sending response messages to mobile phone users can be divided into many ways, such as reply text message, reply picture message, reply voice message, reply video message, reply music message, reply picture message and so on, as shown below.
Among the three methods, picture, video and voice, you need to activate Wechat authentication before you can send media information stored on the Wechat server to users. Generally, there is no official account or service number for authentication. You can't send these kinds of content.
1. Entity information relationship and definition
In my last Wechat development essay, I showed the application entity classes that receive messages and reply messages. These entity classes are encapsulated at the application level according to my needs and development needs. The message relationship of the reply is as follows.
The entity class definition of the message base class BaseMessage is shown below, which constructs an integer value for the date and has some regular properties, as well as an important ToXML method for passing these XML data to the method.
/ basic message content / / [XmlRoot (ElementName = "xml")] public class BaseMessage {/ initialize some content, for example, the creation time is plastic, / public BaseMessage () {this.CreateTime = DateTime.Now.DateTimeToInt ();} / developer Wechat / public string ToUserName {get; set } / sender account (an OpenID) / public string FromUserName {get; set;} / message creation time (integer) / public int CreateTime {get; set;} / message type / public string MsgType {get; set } public virtual string ToXml () {this.CreateTime = DateTime.Now.DateTimeToInt (); / / renew return MyXmlHelper.ObjectToXml (this);}}
The reply text message entity class code is shown below. We can see that it inherits a lot of common entity attributes and has a general method of ToXml, which we can use when we need to convert it to the XML of the response.
/ / reply text message / [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 } / content / public string Content {get; set;}}
And the picture-text message object class ResponseNews, which contains more information definitions
/ / reply to the graphic message / [System.Xml.Serialization.XmlRoot (ElementName = "xml")] public class ResponseNews: BaseMessage {public ResponseNews () {this.MsgType = ResponseMsgType.News.ToString () .ToLower (); this.Articles = new List ();} public ResponseNews (BaseMessage info): this () {this.FromUserName = info.ToUserName; this.ToUserName = info.FromUserName } / the number of picture and text messages is limited to less than 10 / public int ArticleCount {get {return this.Articles.Count;} set {; / / add this step to XML content}} / image and text list. / / multiple picture and text messages. By default, the first item is a large image. Note that if the number of pictures and texts exceeds 10, there will be no response / [System.Xml.Serialization.XmlArrayItem ("item")] public List Articles {get; set;}}
The object in the list of pictures and texts, which is also an entity type, contains some links to pictures and texts, titles and other information, which will not be repeated.
2. Reply processing of message
For example, for text messages, we can handle them in the following ways.
ResponseText response = new ResponseText (info); response.Content = "Sorry, this feature is not enabled yet." ; result = response.ToXml ()
For picture and text messages, we may need to enter more messages to return better results.
Pay attention to the news of the picture and text, the size of the picture had better be in accordance with the official standard, otherwise it does not look good on the phone, the official standard seems to be a width and height of (360200) pixels
/ subscribe or display company information / private string ShowCompanyInfo (BaseMessage info) {string result = ""; / / Picture and text information (single text message) ResponseNews response = new ResponseNews (info) used on Wechat platform; ArticleEntity entity = new ArticleEntity (); entity.Title = "Guangzhou iQidi Software Technology Co., Ltd." Entity.Description = "Welcome to Guangzhou Aiqidi Software, a professional provider of information software and software development framework, 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 researching, developing and selling the most reliable, safe and easy-to-use technology products and quality professional services to help global customers and partners succeed. \ r\ n. (1000 words are omitted here, ) "; 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 our company's Wechat portal menu. Doesn't it look cool?
For these two kinds of (text message, picture and text message) is the most used, many Wechat portals, mainly use these two ways to respond. Of course, we can also carry out different processing according to the various messages submitted by the customer's mobile phone. I introduced the types of request messages in my essay in the previous article, as shown below.
The above content is how to achieve the text message and picture-text message response in the development of Wechat portal by C#. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.