In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you the basic principles of Wechat public platform development and sample analysis of the message interface, I believe most people do not know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's take a look at it!
I. basic principles
Before you start to do it, you may be very interested in this, but at a loss. Isn't it complicated? Is it hard to learn?
In fact, on the contrary, it is very simple. In order to allay everyone's concerns, this paper first briefly introduces the basic principles of Wechat public platform.
Wechat server is equivalent to a forwarding server, terminals (mobile phones, Pad, etc.) initiate requests to Wechat server, Wechat server, and then forward the request to the custom service (this is our specific implementation).
After the service is processed, it is volatilized to the Wechat server, and the Wechat server replies the specific response to the terminal.
The communication protocol is: HTTP
The data format is: XML
The specific process is shown in the following figure:
In fact, all we need to do is respond to the HTTP request.
The specific request content is parsed according to the specific XML format, and after processing, it is also returned according to the specific XML format.
All we need is a simple implementation of HttpHandler.
Of course, Wechat platform can also implement more complex businesses, such as Wechat can be used as an embedded browser, we can through the link to Wechat, open the htm interface, and then implement our own logic.
Message interface (official document) application message interface
Click apply, and fill in the URL url and token, in which token can be entered by the developer to generate a signature.
Web site access
After the user of the public platform submits the information, the Wechat server will send a GET request to the entered URL with four parameters:
Parameter description signature Wechat encryption signature timestamp timestamp nonce random number echostr random string
The developer verifies the request by verifying the signature (there is a verification method below). If it is confirmed that the GET request is from Wechat server, return the echostr parameter content as is, then the access will take effect, otherwise the access will fail.
Signature combines the token parameters entered by the developer with the timestamp parameters and nonce parameters in the request.
Encryption / verification process: 1. The three parameters token, timestamp and nonce are sorted in dictionary order 2. The three parameter strings are concatenated into one string for sha1 encryption 3. The encrypted string obtained by the developer can be compared with signature to identify that the request originated from Wechat message push
When an ordinary Wechat user sends a message to a public account, the Wechat server POST the message to the filled URL. The structure is as follows:
Text message 1348831860 1234567890123456 Parameter description ToUserName developer WeChat FromUserName account (an OpenID) CreateTime message creation time (integer) MsgTypetextContent text message content MsgId message id,64 bit integer picture message 1348831860 1234567890123456 parameter description ToUserName developer WeChat FromUserName account (one OpenID) CreateTime message creation time MsgTypeimagePicUrl picture link MsgId message id 64-bit integer geolocation message 135177636023.134521113.358803201234567890123456 parameter description ToUserName developer WeChat FromUserName account (an OpenID) CreateTime message creation time (integer) MsgTypelocationLocation_X geographic location latitude Location_Y geographic location longitude Scale map zoom size Label geographic location information MsgId message id,64 bit integer link message 13517763601234567890123456 parameter description ToUserName receiver WeChat FromUserName sender WeChat Is an OpenIDCreateTime message creation time MsgType message type, linkTitle message title Description message description Url message link MsgId message id,64 bit integer event push
Event push only supports Wechat version 4.5.Custom menu API for event push, follow and cancel event push is enabled. The rest of the features will be available soon, please look forward to it.
Parameter 123456789 describes the ToUserName receiver's WeChat account FromUserName sender's WeChat. If it is an ordinary user, it is an OpenIDCreateTime message creation time MsgType message type, eventEvent event type, subscribe (subscription), unsubscribe (unsubscribe), CLICK (custom menu click event) EventKey event key value, and message reply corresponding to the key value in the custom menu interface.
For each POST request, the developer returns a specific xml structure in the response package to respond to the message (text, image, voice, video, music are now supported).
The Wechat server will be disconnected if it does not receive a response within five seconds.
The structure of the reply xml is as follows:
Reply text message 12345678 parameter describes ToUserName recipient account (received OpenID) FromUserName developer WeChat message creation time MsgTypetextContent reply message content, length not more than 2048 bytes reply music message 12345678 parameter description ToUserName receiver account (received OpenID) FromUserName developer WeChat CreateTime message creation time MsgTypemusicMusicUrl music link HQMusicUrl high quality music link The WIFI environment gives priority to using this link to play music reply Teletext messages 12345678 2 parameters to describe the ToUserName recipient account (received OpenID) FromUserName developer WeChat CreateTime messages creation time MsgTypenewsArticleCount Teletext messages, which is limited to less than 10 Articles Teletext messages. By default, the first item is large Title Teletext message title Description Teletext message description PicUrl Picture Link, supported JPG, PNG format The better effect is the big picture 640-320 and the small picture 80-80. Url Click the picture and text message to jump to the official API document:
Http://mp.weixin.qq.com/wiki/index.php?title=%E6%B6%88%E6%81%AF%E6%8E%A5%E5%8F%A3%E6%8C%87%E5%8D%97
Matters needing attention
1. User OpenID is a fixed and unique string for an official account.
two。 Please use port 80
Please follow us: we will fully explain the specific development process in the future. 3. Message class diagram
The above is all the contents of the article "basic principles of Wechat Public platform Development and sample Analysis of message Interface". 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.