In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "what are the skills of asp.net Wechat in developing message response". The content is simple and clear. I hope it can help you solve your doubts. Now let the editor lead you to study and learn "what are the skills of asp.net Wechat in developing message response".
When an ordinary Wechat user sends a message to a public account, the Wechat server packets the XML of the POST message to the URL filled in by the developer.
Please note:
1. For retry message weighting, it is recommended to use msgid.
2. If the Wechat server does not receive a response within five seconds, it will disconnect and reinitiate the request for a total of three retries. If the server cannot guarantee to process and reply within five seconds, you can reply to the empty string directly. The Wechat server will not do anything about it and will not initiate a retry. For more information, see "send message-passive reply message".
3. To ensure higher security, developers can set message encryption at the developer center on the official website of the public platform. When encryption is enabled, the messages sent by users will be encrypted, and the messages that the official account passively replies to users also need to be encrypted (but developers will not be affected if they send messages to users through API calls such as customer service APIs). For a detailed description of message encryption and decryption, see message encryption and decryption instructions.
The structure of push XML packets for each message type is as follows:
Text message
1348831860 1234567890123456
Picture message
1348831860 1234567890123456
Voice message
13572909131234567890123456
Please note that after enabling speech recognition, every time a user sends a voice to the official account, Wechat will add a Recongnition field to the pushed voice message XML packet (Note: due to the client cache, the developer enables or disables the speech recognition feature, which takes effect immediately for new followers and 24 hours for already followed users. Developers can re-follow this account for testing). The voice XML packets after speech recognition is enabled are as follows:
13572909131234567890123456
In the extra fields, Format is in voice format, usually amr,Recognition is the result of speech recognition, and UTF8 coding is used.
Video message
13572909131234567890123456
Small video message
13572909131234567890123456
Geolocation message
135177636023.134521113.358803201234567890123456
Link message
13517763601234567890123456
In the previous article, see ResponseXML (postString); the method is as follows
/ / get the message sent by the user / private void ResponseXML (string postString) {/ / use XMLDocument to load the information structure XmlDocument xmlDoc = new XmlDocument (); xmlDoc.LoadXml (postString); XmlElement rootElement = xmlDoc.DocumentElement;// to get the root XmlNode MsgType of the document = rootElement.SelectSingleNode ("MsgType"); / / get the text type of the message RequestXML requestXML = new RequestXML () / / declare the instance, get each attribute and assign the value requestXML.ToUserName = rootElement.SelectSingleNode ("ToUserName"). InnerText;// official account requestXML.FromUserName = rootElement.SelectSingleNode ("FromUserName"). InnerText;// user requestXML.CreateTime = rootElement.SelectSingleNode ("CreateTime") .InnerText;// creation time requestXML.MsgType = MsgType.InnerText / / message type / / A pair of message types are assigned if (requestXML.MsgType = = "text") {/ / assign text message content requestXML.Content = rootElement.SelectSingleNode ("Content"). InnerText;} if (requestXML.MsgType.Trim () = = "location") {/ / assign geographic location latitude, longitude, map scaling, geographic location description requestXML.Location_X = rootElement.SelectSingleNode ("Location_X"). InnerText RequestXML.Location_Y = rootElement.SelectSingleNode ("Location_Y"). InnerText; requestXML.Scale = rootElement.SelectSingleNode ("Scale"). InnerText; requestXML.Label = rootElement.SelectSingleNode ("Label"). InnerText;} if (requestXML.MsgType.Trim (). ToLower () = = "event") {/ assign event name and event key value requestXML.EventName = rootElement.SelectSingleNode ("Event"). InnerText; requestXML.EventKey = rootElement.SelectSingleNode ("EventKey"). InnerText } if (requestXML.MsgType.Trim (). ToLower () = "voice") {/ assign the speech recognition result. Remember to enable the speech recognition function in developer mode before assigning the result, otherwise you will not get requestXML.Recognition = rootElement.SelectSingleNode ("Recognition"). InnerText;} ResponseMsg (requestXML);}
The voice recognition function is enabled as follows:
RequestXML is a class I created separately, which declares the property fields commonly used in messages, as follows:
/ public class RequestXML {private String toUserName = String.Empty; / public String ToUserName {get;set;} / user Wechat account / public String FromUserName {get;set;} / creation time / public String CreateTime {get;set } / public String MsgType {get;set;} / public String Content {get;set;} / * the following are the properties specific to messages of event type * / public String EventName {get;set;} / event value / event value / event {get;set } / * the following are the properties specific to teletext messages * / public int ArticleCount {get; set;} / public string Title {get; set;} / public string Description {get; set of teletext messages Link address of picture / public string PicUrl {get; set;} / public string Url {get; set;} / public List Articles {get; set } / * the following are specific properties of geolocation type messages * / public String Location_X {get; set;} / public String Location_Y {get; set;} / public String Scale {get; set } / Map location description / public String Label {get; set;} / unique fields for voice messages / public String Recognition {get; set;}}
Continue to follow ResponseMsg (requestXML); the method is as follows
Private void ResponseMsg (RequestXML requestXML) {string MsgType = requestXML.MsgType; try {/ / determine which type of message to send switch (MsgType) {case "text": SendTextCase (requestXML); / / send text message break; case "event": / / send event message if (! string.IsNullOrWhiteSpace (requestXML.EventName) & & requestXML.EventName.ToString (). Trim (). Equals ("subscribe")) {SendWelComeMsg (requestXML) / / else if (! string.IsNullOrWhiteSpace (requestXML.EventName) & & requestXML.EventName.ToString (). Trim (). Equals ("CLICK")) {SendEventMsg (requestXML); / / send event message} break; case "voice": SendVoiceMsg (requestXML); / / send voice message break; case "location": / / send location message SendMapMsg (requestXML); break; default: break }} catch (Exception ex) {HttpContext.Current.Response.Write (ex.ToString ());}}
Let's first focus on sending text messages, SendTextCase (requestXML); / / sending text messages
/ / send text / private void SendTextCase (RequestXML requestXML) {string responseContent = FormatTextXML (requestXML.FromUserName, requestXML.ToUserName, requestXML.Content); HttpContext.Current.Response.ContentType = "text/xml"; HttpContext.Current.Response.ContentEncoding = Encoding.UTF8; HttpContext.Current.Response.Write (responseContent); HttpContext.Current.Response.End ();}
Formulation of FormatTextXML method
/ / return formatted Xml format content / official account / user ID / reply content / private string FormatTextXML (string p1, string p2, string p3) {return "+ DateTime.Now.Subtract (new DateTime (1970, 1, 1, 8, 0, 0)). TotalSeconds.ToString () +" 1 ";}
In this way, the reply to the message can be realized. If the user clicks the button, the code is as follows:
Case "event": / / send event message if (! string.IsNullOrWhiteSpace (requestXML.EventName) & & requestXML.EventName.ToString (). Trim (). Equals ("subscribe")) {SendWelComeMsg (requestXML); / / Teletext message returned when following} else if (! string.IsNullOrWhiteSpace (requestXML.EventName) & & requestXML.EventName.ToString (). Trim (). Equals ("CLICK")) {SendEventMsg (requestXML); / / send event message} break / / send response event message / private void SendEventMsg (RequestXML requestXML) {string keyStr = requestXML.EventKey.ToString (); switch (keyStr) {case "mypay": SendPayDetails (requestXML); / / send payroll break; case "tianqiyubao": SendWeaterMessage (requestXML); / / send weather forecast break; case "kaixinyixiao": SendKaiXinMessage (requestXML); / / send smile result set break; case "updateMessage": SendUpdateMessage (requestXML) / / send modification information link break; case "yuangonghuodong": SendYuanGongHuoDong (requestXML); / / send student activity break; case "yuangongtongzhi": SendYuanGongTongZhi (requestXML); / / send employee notification break; case "youwenbida": SendWenti (requestXML); / / send employee submission question link break; case "mywen": SendWentiList (requestXML); / / send problem list link break; case "PhoneSerices": SendKeFuMessage (requestXML); / / access customer service break Default: String responseContent = String.Empty; responseContent = FormatTextXML (requestXML.FromUserName, requestXML.ToUserName, "this feature is not available yet! Please wait for it! ") ; HttpContext.Current.Response.ContentType = "text/xml"; HttpContext.Current.Response.ContentEncoding = Encoding.UTF8; HttpContext.Current.Response.Write (responseContent); HttpContext.Current.Response.End (); break;}}
SendWelComeMsg (requestXML); / / Picture and text messages returned when following
/ private void SendWelComeMsg (RequestXML requestXML) {String responseContent = String.Empty; string newdate = DateTime.Now.Subtract (new DateTime (1970, 1, 1, 8, 0, 0)). TotalSeconds.ToString (); string PUrlfileName = "http://www.deqiaohr.com.cn/weixin/welcome.jpg"; ResponseContent = string.Format (Message_News_Main, requestXML.FromUserName, requestXML.ToUserName, newdate, "1", string.Format (Message_News_Item, "Welcome to Deqiao staff Service Center", "Suzhou Deqiao Human Resources was founded in 2002." PUrlfileName, "http://www.deqiaohr.com.cn/weixin/WxGsjianjie.aspx")); HttpContext.Current.Response.ContentType =" text/xml "; HttpContext.Current.Response.ContentEncoding = Encoding.UTF8 HttpContext.Current.Response.Write (responseContent); HttpContext.Current.Response.End ();}
Message_News_Main and Message_News_Item are picture and text message formatting.
/ return Teletext message body / public static string Message_News_Main {get {return @ "{2} {3} {4}";}} / return Teletext message item / public static string Message_News_Item {get {return @ "" } / private void SendVoiceMsg (RequestXML requestXML) {string responseContent = FormatTextXML (requestXML.FromUserName, requestXML.ToUserName, "the speech message recognition result you just mentioned is:" + requestXML.Recognition.ToString ()); HttpContext.Current.Response.ContentType = "text/xml"; HttpContext.Current.Response.ContentEncoding = Encoding.UTF8; HttpContext.Current.Response.Write (responseContent); HttpContext.Current.Response.End ();}
The above is all the contents of this article entitled "what are the skills of asp.net Wechat in developing message response?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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.