C # WeChat development tour-preparation stage,

Source: Internet
Author: User

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!

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.