Senparc. Weixin. MPSDK WeChat public platform development tutorial (2): become a developer

Source: Internet
Author: User
Tags website server
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:

  1. Receive XML information from 2
  2. Internal server logic execution
  3. 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?
gh_a96a4a619366
olPjZjsXuQPJoV0HlruZkNzKc91E
1357986928
text
TNT2
5832509444155992350

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
gh_a96a4a619366
12345678
text
content
0

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:
  1. Each XML message has a size limit, such as text information. it is recommended that the Content should not exceed 600 characters.
  2. , 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.
  3. 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:
  4. 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.
  5. CreateTime uses Unix time. Therefore, if C # is used, a conversion is required.
  6. 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 ............ & % &......).
  7. 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:

  1. VS2012 (at least VS2010 SP1 );
  2. 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;
  3. 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 ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.