.NET develop micro-channel micro-channel configuration several methods public basic configuration No.

      It recently staged a public number, record it.

 

The purpose is to enable the server in micro-channel public number in the configuration. Micro-channel document

 

 

 In fact, micro-channel document has been written very clearly, very simple. (Purpose micro-channel is that it sends a get request, I hope we can accept it, then back to the data tell it to the micro-Letter)

Method One: Use WebApi, MVC architecture (note that in this Action Controller do not go adding views)

Micro letter sent to us four parameters: signature timestamp nonce echostr us after the micro-letter requested that echostr the string and then distributed micro letter. (The most simple way is, consequently we do not do, to receive echostr parameters, return directly to this parameter. Hey hey hey)

 

 

 Lane wrote in the Controller, also can pass. API architecture to add a route, get request. You can use when you are ready to test the postman (and consequently do not really write)

Micro-channel according to requirements: micro-channel flowchart official

 

 We get the data needed to handle it: code is as follows

        /// <summary>
        /// 验证微信签名 wuchen
        /// </summary>
        /// <returns></returns>
        /// * 将token、timestamp、nonce三个参数进行字典序排序
        /// * 将三个参数字符串拼接成一个字符串进行sha1加密
        /// * 开发者获得加密后的字符串可与signature对比,标识该请求来源于微信。
        public  bool CheckSignature()
        {
            var WeChat_Token = "TokenCrCool";
            //从微信服务器接收传递过来的数据
            string signature = VqiRequest.GetQueryString("signature"); //微信加密签名
            string timestamp = VqiRequest.GetQueryString("timestamp");//时间戳
            string nonce = VqiRequest.GetQueryString("nonce");//随机数
            
            string[] ArrTmp = { WeChat_Token, timestamp, nonce };
            Array.Sort(ArrTmp);     //字典排序
            string tmpStr = string.Join("", ArrTmp);//将三个字符串组成一个字符串
            tmpStr = FormsAuthentication.HashPasswordForStoringInConfigFile(tmpStr, "SHA1");//进行sha1加密
            tmpStr = tmpStr.ToLower();
            //加过密的字符串与微信发送的signature进行比较,一样则通过微信验证,否则失败。
            if (tmpStr == signature)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

返回true,然后再返回echostr字符串。

 方法二:三层架构的aspx页面(注意把前端页面删除干净,确保自己用postman测试的时候,只返回echostr)

 

就是这么简单粗暴。前端页面代码要删除干净的,像这样

 

 

方法三:一般处理程序 就两行代码。

 

 

三种方法都是可行的,完成之后发布在自己的云服务器上。使用80,443端口才可以。其他的微信文档有步骤的。

 

Guess you like

Origin www.cnblogs.com/cr-cool/p/12376468.html