微信企業號開發怎樣啟用回調模式?就是簡單的登陸PC版微信,點擊應用中心,選擇須要應用,再點擊回調模式啟用?
似乎不是這么簡單。!
能夠看到核心的僅僅有三個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"; //配置的tokenstring corpId = "corpId"; //corpid,string encodingAESKey = "encodingAESKey"; //配置的tokenencodingAESKeyWXBizMsgCrypt 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請求的返回參數,返回給企業號。 }