ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
微信企业号开发如何启用回调模式?就是简单的登陆PC版微信,点击应用中心,选择需要应用,再点击回调模式启用? **似乎不是这么简单!!** ![](https://box.kancloud.cn/2016-01-14_569757dd6d5bb.jpg) 可以看到核心的只有三个URL,Token,EncodingAESKey这三个参数可以随便填写吗? 1URL可以随便填写吗? 可以肯定的是,不能随便填写。不信你可以试试。因为点击确定后微信会给这个URL发送信息。因此这个URL必须是外网可以访问的地址。 而且后台还必须处理微信发送过来的信息。例如URL 是http://www.hao123.com/可以在外网方法,但点击保存时就会出现: **echostr校验失败,请您检查是否正确解密并输出明文echostr** **2Token可以随便填写吗?** 可以,目前我没有发现有什么特殊的要求 **3EncodingAESKey能随便填写吗?** 不能随便填写,必须是数字字母的组合,而且是43个字符,建议使用微信随机生成的。 我们知道在URL处配置一个外网可以访问的URL,并不能保证保存成功,后台如何处理呢? 例如我配置为http://.../TestWeixin.ashx 则后台的处理方式,需要调用微信的相关加密解密函数 TestWeixin.ashx的后台代码为: ~~~ public void ProcessRequest (HttpContext context) { if (context.Request.HttpMethod.ToLower() == "post") { } else //点击保存时,微信需要验证时调用 { Valid(); } } private void Valid() { string msg_signature = HttpContext.Current.Request.QueryString["msg_signature"]; string timestamp = HttpContext.Current.Request.QueryString["timestamp"]; string nonce = HttpContext.Current.Request.QueryString["nonce"]; string decryptEchoString = ""; // 解析之后的明文 string echoStr = HttpContext.Current.Request.QueryString["echoStr"]; bool isok = CheckSignature(msg_signature, timestamp, nonce, echoStr, ref decryptEchoString); if (isok) { if (!string.IsNullOrEmpty(decryptEchoString)) { HttpContext.Current.Response.Write(decryptEchoString); HttpContext.Current.Response.End(); } } } public bool CheckSignature(string signature, string timestamp, string nonce,string echostr, ref string retEchostr) { string token = "token"; //配置的token string corpId = "corpId"; //corpid, string encodingAESKey = "encodingAESKey"; //配置的tokenencodingAESKey WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(token, encodingAESKey, corpId); //调用微信提供的函数 int result = wxcpt.VerifyURL(signature, timestamp, nonce, echostr, ref retEchostr);//调用微信提供的函数 if (result != 0) { LogInfo.Error("ERR: VerifyURL fail, ret: " + result); return false; } return true; //ret==0表示验证成功,retEchostr参数表示明文,用户需要将retEchostr作为get请求的返回参数,返回给企业号。 } ~~~