手把手教你微信公衆號開發(開放源碼)

手把手教你微信公眾號開發(開放源碼)

開發語言:C#

手把手教你微信公眾號開發(開放源碼)

點擊登錄之後,用微信掃一掃就就進去了

手把手教你微信公眾號開發(開放源碼)

然後就可以愉快的開始開發咯

我們可以在上面的配置界面中填入一個URL,這個URL將用於微信和我們系統之間的通信,具體的操作方式在微信官方的開發文檔中有很詳細的說明,這裡就囉嗦了,直接來看代碼

string signature = context.Request["signature"].ToString();

string timestamp = context.Request["timestamp"].ToString();

string nonce = context.Request["nonce"].ToString();

string echostr = context.Request["echostr"].ToString();

string result = WeChatClassLibrary.Function.WeChatFunction.CheckURL("xuhaotest", signature, timestamp, nonce, echostr);

if (result != null)

{

context.Response.Write(result);

}

驗證的方法是這樣

public static string CheckURL(string token, string signature, string timestamp, string nonce, string echostr)

{

// 將token、timestamp、nonce三個參數進行字典序排序

string[] temp1 = { token, timestamp, nonce };

//排序

Array.Sort(temp1);

//將三個參數字符串拼接成一個字符串進行sha1加密

string temp2 = string.Join("", temp1);

string temp3 = SHA1(temp2, Encoding.UTF8);

//開發者獲得加密後的字符串可與signature對比,標識該請求來源於微信

//SHA1有大小寫區別,先轉成小寫再對比

if (temp3.ToLower().Equals(signature))

{

return echostr;

//如果相同就返回微信服務器要求的signature,不相同就沒有必要處理

}

return null;

}

這裡我將這些方法都做了封裝

手把手教你微信公眾號開發(開放源碼)

代碼

手把手教你微信公眾號開發(開放源碼)

還有一些其他的方法,都封裝好了,有需要的朋友可以私信我,我把源碼發給你,不間斷更新,會逐漸完善這個裡面的功能,由於工程量較大,所以用到一點做一點,逐步的完成


分享到:


相關文章: