In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you how to realize automatic message reply and custom menu in the development of Weixin Official Accounts. The content is simple and easy to understand and the organization is clear. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn this article "How to realize automatic message reply and custom menu in the development of Weixin Official Accounts."
message reply
Process requests and respond
1) Concern
You can also refer to the official website document: mp.weixin.qq.com/wiki
When WeChat users pay attention to public accounts, they can be given appropriate prompts. It could be a welcome word, it could be a help tip. The sample code is as follows:
class EventHandler : IHandler { /// ///requested xml /// private string RequestXml { get; set; } /// ///constructor /// /// public EventHandler(string requestXml) { this.RequestXml = requestXml; } /// ///process request /// /// public string HandleRequest() { string response = string.Empty; EventMessage em = EventMessage.LoadFromXml(RequestXml); if (em.Event.Equals("subscribe",StringComparison.OrdinalIgnoreCase)) { //Reply to welcome message TextMessage tm = new TextMessage(); tm.ToUserName = em.FromUserName; tm.FromUserName = em.ToUserName; tm.CreateTime = Common.GetNowTime(); tm.Content = "Welcome to pay attention to us, I am the service waiter, if you have anything to say ~\n\n"; response = tm.GenerateContent(); } return response; } }
The official introduction is like this
Follow/Unfollow Events
When users follow and unfollow public accounts, WeChat will push this event to the URL filled in by developers. It is convenient for developers to send welcome messages to users or unbind accounts.
If the WeChat server does not receive a response within five seconds, the connection will be broken and the request will be re-initiated, retrying a total of three times.
For retry message sorting, it is recommended to use FromUserName + CreateTime for sorting.
If the server cannot guarantee to process and reply within five seconds, it can directly reply to the empty string, and the WeChat server will not do anything about it and will not initiate a retry.
Push XML packet example:
123456789
Parameter Description:
Parameter Description ToUserDeveloper Microsignal FromUserSender Account (an OpenID) CreateTime Message Creation Time (integer) MsgType Message Type, eventEvent Type, subscribe, unsubscribe
You can also use WeChat online interface debugging tool to test whether it is normal: cancel/pay attention to event interface online debugging
2) Greetings
Simple exchange greetings, such as hello, help, etc., are the same as we use WeChat chat, but the response is responded by our program. Specific functions can be added according to their own needs.
WeChat is a platform for communication. This case can be used for online service robots, similar to Taobao's customer service robots, but our version is WeChat.
In fact, it's very simple. Get the request message and match the response according to the keyword. Of course, there may be a lot of work to be done here, how to support intelligent matching, how to support fuzzy matching, etc.
/// ///Text information processing class /// public class TextHandler : IHandler { /// ///XML requested /// private string RequestXml { get; set; } /// ///constructor /// ///requested xml public TextHandler(string requestXml) { this.RequestXml = requestXml; } /// ///process request /// /// public string HandleRequest() { string response = string.Empty; TextMessage tm = TextMessage.LoadFromXml(RequestXml); string content = tm.Content.Trim(); if (string.IsNullOrEmpty(content)) { response = "You haven't entered anything, I can't help you, %>_
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.