This article focuses on things you need to know as a secondary developer of a public platform. It also involves some official regulations or relatively masking considerations. Please add it! This article focuses on things you need to know as a secondary developer of a public platform. It also involves some official regulations or relatively masking considerations. Please add it!
I think it is more important to be a developer than to activate the "advanced" function in the background.
1. public platform communication process
As developers, we have two main targets: Servers and application (website) servers.
When a user sends a message to your public platform, the message is actually sent to the server first. the server initiates another request to the website server, and the website server returns the result of this request, then the server sends it to the client.
The entire message communication process is as follows:
In the above five steps, as developers, we focus mainly on step 3, which actually requires three tasks:
- Receive XML information from 2
- Internal server logic execution
- Organize and return XML information for 4
I will describe the above three tasks in detail and provide a complete set of simple and efficient processing methods.
II. XML communication format
If you use a client to send different types of messages, the website server will receive data in different formats (text, voice, images, and so on). The data format is only XML.
As a student, I think it is enough to master the simplest types of text. other formats are similar. In the subsequent instructions, you will find that Senparc. Weixin. MP. dll can help us to completely ignore these tedious formats and definitions.
The content of a simple text request XML (RequestMessage) is as follows:
View sourceprint?
olPjZjsXuQPJoV0HlruZkNzKc91E |
The official description of the corresponding node is as follows:
Parameters |
Description |
ToUserName |
DeveloperNo. |
FromUserName |
Sender account (one OpenID) |
CreateTime |
Message creation time (integer) |
MsgType |
Text |
Content |
Text message content |
MsgId |
Message id, 64-bit integer |
A simple text returns the following XML (ResponseMessage) content:
View sourceprint?
olPjZjsXuQPJoV0HlruZkNzKc91E |
The official description of the corresponding node is as follows:
Parameters |
Description |
ToUserName |
Recipient account (received OpenID) |
FromUserName |
Developer ID |
CreateTime |
Message creation time |
MsgType |
Text |
Content |
The content of the reply message. the length cannot exceed 2048 bytes. |
FuncFlag |
The message received by the star when 0x0001 is marked. |
III. issues that need attention and are easily overlooked:
- Each XML message has a size limit, such as text information. it is recommended that the Content should not exceed 600 characters.
- , After step 2 starts, the server has a waiting time:5 secondsIf step 4 is not completed within this time period, the request will be closed (including the data transmission time ). That is to say, if the time limit is exceeded, the client cannot receive a reply even if the website server returns data.
- In text messages, tags are allowed to be added to place connections. However, many of my friends found that there is no problem with iOS after testing, and the link on Android cannot be clicked because (at least so far ): the Android client strictly determines the tag format. please write in this format Strictly:
- The FromeUserName in the XML node above is the user's OpenId. for the same public account, the first six digits of this OpenId are consistent and are unique in the record of the entire public platform. That is to say, the same user pays attention to two different public accounts and has two different OpenIDs.
- CreateTime uses Unix time. Therefore, if C # is used, a conversion is required.
- Keep the order of XML nodes in the official API as much as possible. in the past, the server used the node location to read information (node [0]) instead of the node name. now this problem seems to have improved, but be careful ............ & % &......).
- Because of this special communication method, (at least so far) All requests must be initiated from the client first, don't expect, but you can use APIs to actively push messages to the client from the website server (of course, there are other methods, such as simulated login ).
4. to do a good job, you must first sharpen the tool: Senparc. Weixin. MP. dll.
Although the entire communication process is very simple, the official API still makes special conventions or processes on some fields, moreover, process-oriented processing of so many types of request data is also very laborious.
So I made an open source project: Senparc. Weixin. MP, address: https://github.com/JeffreySu/WeiXinMPSDK/
Senparc. Weixin. MP aims to help C # developers simplify the entire communication process, process messages in an object-oriented manner, and focus on business logic rather than tedious APIs.
Use Senparc. Weixin. MP and deploy it on the Internet to communicate with the server. you need to prepare these environments:
- VS2012 (at least VS2010 SP1 );
- If you need to run the MVC Demo, at least. NET 4.0 (install MVC 4) is required, and Webforms Demo is run, at least. NET 3.5 is required;
- A domain name or IP address that can be accessed through port 80. the VM, peanut shell ing intranet, VPS, and independent servers can all be used.
Here, Senparc is introduced briefly. weixin. the introduction of this project MP, I will give more detailed instructions and examples (https://github.com/JeffreySu/WeiXinMPSDK/ has prepared enough use documentation and Demo can refer ).