This article introduces the basic concepts of public platform development
I. how to start
1: If there is no public account, you can apply for a test account: http://mp.weixin.qq.com/debug/cgi-bin/sandbox? T = sandbox/login
2: After logon, the interface is as follows:
3: Next, I need to prepare my own website and then publish my own URL. Therefore, I wrote a WeixinTest. ashx using ASP. NET. the code is as follows:
public void ProcessRequest(HttpContext context) { string echoStr = HttpContext.Current.Request.QueryString["echoStr"]; string signature = HttpContext.Current.Request.QueryString["signature"]; string timestamp = HttpContext.Current.Request.QueryString["timestamp"]; string nonce = HttpContext.Current.Request.QueryString["nonce"];
if (!string.IsNullOrEmpty(echoStr)) { HttpContext.Current.Response.Write(echoStr); HttpContext.Current.Response.End(); } }
After the website is published on your server, we enter the address and TOKEN (note that the TOKEN is not verified in my test code ). Then, click submit in the figure above to get the interface:
It is worth noting that this value has an invalid period.
4. instance-a real url handler
public void ProcessRequest(HttpContext param_context) { if (HttpContext.Current.Request.HttpMethod.ToUpper() == "POST") { using (Stream stream = HttpContext.Current.Request.InputStream) { Byte[] postBytes = new Byte[stream.Length]; stream.Read(postBytes, 0, (Int32)stream.Length); Handle(Encoding.UTF8.GetString(postBytes)); } } else { Auth(); } }
Why is it POST? When applying for a public account, the website uses GET to verify the url. in this way, we can use Auth to interact, POST is used. Next, we can start development in the true sense :)~~
Refer:
1: Developer files, http://mp.weixin.qq.com/wiki/index.php? Title = % E5 % BC % 80% E5 % 8F % 91% E8 % 80% 85% E8 % A7 % 84% E8 % 8C % 83
For more articles about basic concepts of public platform development, please refer to PHP Chinese network!