C # development journey-preparation stage,
I recently started to learn the development related content, record it, and gradually develop the habit!
1. Apply for a public account: the public account is divided into a subscription account and a service account. You can click here to view their previous differences
Because we are testing, we can apply for a test account directly and activate all the functions. Address: http://mp.weixin.qq.com/debug/cgi-bin/sandbox? T = sandbox/login
After applying, you will have your ownAppIDAndAppsecret
2. Configure the URL address for receiving information (you must ensure that the Internet can be accessed and verification is required). I only use handler to receive and process information here. At the same time, set your own Token. (the token value must be consistent with the value written in your program)
/// <Summary> /// summary of MarkWeixin /// </summary> public class MarkWeixin: IHttpHandler {public void ProcessRequest (HttpContext context) {weixinHelper wx = new weixinHelper (); String postStr = String. empty; if (HttpContext. current. request. httpMethod. toUpper () = "POST") {Stream s = HttpContext. current. request. inputStream; Byte [] B = new Byte [s. length]; s. read (B, 0, (Int32) s. length); postStr = E Ncoding. UTF8.GetString (B); if (! String. isNullOrEmpty (postStr) {// receives and processes the message wx. handle (postStr) ;}} else {// verify the token method wx. interfaceTest () ;}} public bool IsReusable {get {return false ;}}}
The following is the verification method: (the token value in the configuration is the value in this method)
/// <Summary> /// verify /// </summary> public void InterfaceTest () {string token = "marktesttoken"; if (string. isNullOrEmpty (token) {return;} string echoString = HttpContext. current. request. queryString ["echoStr"]; string signature = HttpContext. current. request. queryString ["signature"]; string timestamp = HttpContext. current. request. queryString ["timestamp"]; string nonce = HttpContext. current. reque St. QueryString ["nonce"]; if (! String. IsNullOrEmpty (echoString) {HttpContext. Current. Response. Write (echoString); HttpContext. Current. Response. End ();}}
Conclusion: The simple configuration is complete, and the method for receiving and processing information can be improved later!