Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basic principles and message interfaces in the development of Wechat public platform

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Many novices are not very clear about the basic principles and message interfaces in the development of Wechat public platform. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.

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, the terminal (mobile phone, Pad, etc.) initiates a request to Wechat server, Wechat server, and then forwards the request to the custom service.

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.

two。 Concatenate three parameter strings into one string for sha1 encryption

3. The encrypted string obtained by the developer can be compared with signature, indicating 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 sender account (one 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 sender account (one OpenID) CreateTime message creation time (integer) MsgTypeimagePicUrl picture link MsgId message id,64 bit integer

Geolocation message

135177636023.134521113.358803201234567890123456 Parameter description ToUserName developer WeChat account FromUserName sender account (one 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, if an ordinary user, it 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, corresponding to the key value in the custom menu interface.

Message reply

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 the ToUserName receiver account (received OpenID) FromUserName developer WeChat CreateTime message creation time MsgTypetextContent reply message content, no more than 2048 bytes in length

Reply to music messages

12345678 parameters describe the ToUserName receiver account (received OpenID) FromUserName developer WeChat CreateTime message creation time MsgTypemusicMusicUrl music link HQMusicUrl high quality music link, which is preferred for WIFI environment to play music.

Reply to a picture and text message

Parameter 12345678 describes the number of ToUserName receiver accounts (received OpenID) FromUserName developer WeChat CreateTime messages creation time MsgTypenewsArticleCount picture and text messages, which is limited to less than 10 Articles picture and text messages. By default, the first item is large picture Title picture message title Description picture text message description PicUrl picture link, and supports JPG and PNG formats. The better effect is 640 pictures 320 in big pictures and 80 messages in small pictures. Url clicks the picture and text message to jump the link

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 the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report