WeChat Development Series ---- 01: Becoming a developer and ---- 01 A developer

Source: Internet
Author: User
Tags string back website server

Development Series ---- 01: Become a developer and ---- 01 A developer

Third-partySDK[Senparc. Weixin. MP] to develop your own public account.

GitHub address for this project: https://github.com/Andyahui/xgyxsh_WeiXin

This series is a self-developed dome. I mainly want to use this exercise to clarify the basic development process and website development ideas, and learn how to learn in the project practice, bring yourself closer to Daniel.

Not much nonsense-enter the topic.

 

I. Development Tool Gift Packs

Public platform developer API: http://mp.weixin.qq.com/wiki/home/index.html

Public number platform interface debugging tools: https://mp.weixin.qq.com/debug/cgi-bin/apiinfo? T = index & type = % E6 % B6 % 88% E6 % 81% AF % E6 % 8E % A5 % E5 % 8F % A3 % E8 % B0 % 83% E8 % AF % 95 & form = % E8 % A7 % 86% E9 % A2 % 91% E6 % B6 % 88% E6 % 81% AF

Senparc. Weixin. MPGithub address: https://github.com/JeffreySu/WeiXinMPSDK/

Senparc. Weixin. MPOfficial blog address:Http://www.cnblogs.com/szw/archive/2013/05/14/weixin-course-index.html

Senparc. Weixin. MPOfficial web address: http://weixin.senparc.com/QA

 

2. Understand the communication process

We know that as long as we pay attention to the public number, we can simply communicate with the public number. For example, the Public number sends news, and the user clicks the public number menu to get a series of replies. These are simple communications.

 

2.1 -- communication principle:

We need to know that the requests sent by the client are not directly sent to our website server, but forwarded through the server. Every interaction between us and the public account is performed by the server as a man-in-the-middle (so called ), in this way, you can perform some simple interactions normally. Interaction is transmitted through the XML file format. For details, see the map of the great god.

The figure clearly shows the communication process between the two. The third-party SDK can simplify the process of 2, 4. Because it is encapsulated, what we need to do is 3 to process some logical relationships, call a third-party SDK to complete the 2, 4 functions.

Communication between the server and the website ----- XML <The developer information contains the specific communication data interaction process>

 

2.2 -- Precautions

  • The size of each XML message is limited. The Content cannot exceed 600 words;
  • After step 2, the server has a wait time: 5 seconds. If the wait time is not 4, the request will be closed.
  • The same user pays attention to two different public accounts, which will generate two different openids;
  • CreateTime uses Unix time and needs to be converted;
  • Ensure the node sequence of the official API;
  • The above communication diagram is a single item and does not actively push messages from the website to the client. It is what we get in response to client requests;
 

3. Become a developer

After the development, we need to apply for a public number (service number/subscription number ). There is a difference between the two. You can see it when you apply for it. Because we are developing dome, you can use all the test numbers to complete it. You can directly replace it during future deployment.

Test code application page: ttp: // mp.weixin.qq.com/debug/cgi-bin/sandbox? T = sandbox/login

<You can use it for free for one year by directly logging on Via scan code. Basic Development interfaces are available, which is good enough to complete routine development and testing.>

We can see the specificTest number informationAndInterface Configuration InformationWe need to configure the interface information. to configure the interface information, we need a server and a domain name (which can be the IP address of the server );

Become a developerPrerequisitesYes: the server sends a GET request to the website server and sends the introduced random string back to the server through the website server. In this way, the verification succeeds and you can become a developer. Each subsequent request is a POST request.

URL: it can receive GET/POST requests sent by the server, and the address exists, which can be accessed through a browser. Specific to a page for processing get requests.

Token: can be entered by the developer at will to generate a signature (this Token will be compared with the Token contained in the interface URL to verify security ).

 

3.1 -- complete authentication

Directly create a project with an empty MVC4, reference the SDK, add the corresponding reference, create a WeixinController controller, fill in the following code, and publish it directly. Without adding a view, deploy it on the website server to complete authentication and become a developer.

Namespace XGY_WeiXin.Controllers {// <summary> // The GET/POST request sent by the server, from here to other places to process the corresponding logic. /// </Summary> public class WeiXinController: Controller {public static readonly string Token = "xgyweixin"; // consistent with the Token settings in the public account background, case sensitive. # Region GET verification request // <summary> // backend authentication address (Get request processing) /// </summary> [HttpGet] [ActionName ("Index")] public ActionResult Get (PostModel postModel, string echostr) {if (CheckSignature. check (postModel. signature, postModel. timestamp, postModel. nonce, Token) {return Content (echostr); // If a random string is returned, it indicates that the verification is successful.} Else {return Content ("failed:" + postModel. Signature + "," + CheckSignature. GetSignature (postModel. Timestamp, postModel. Nonce, Token) + ". "+" If you see this sentence in the browser, it indicates that this address can be used as the Url of the public account background. please ensure that the Token is consistent. "); }}# Endregion }}

Publish such a project to the server for deployment. Fill in the relevant content in the URL and Token to see if it is qualified. Fill in the URL of this project: http: www.xgy.llili.cn/Weixin. The URL is specific to the relevant page, in this way, the request is sent to the specific controller. Token: xgyweixin, which must be the same as that in your own controller.

As a developer, you can perform a series of related operations. You can use the SDK to complete related functions.

----------------------------------------------- Continue tomorrow -----------------------------------------------------

Related Article

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.