微信企業號開發如何啟用回調模式?就是簡單的登陸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"; //配置的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請求的返回參數,返回給企業號。
}
~~~