這篇文章給大家分享的是有關微信開發.Net 接入的示例分析的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
微信公眾平臺接口開發官方僅提供了 PHP 接入示例代碼, 網上找到的.Net代碼多半需要積分下載,
所以自己寫了一個
如下:
<%@ Page Language="C#" %>
<script runat="Server" >
//此處TOKEN可以自行修改
public const String TOKEN = "weixin_kevinlc";
private void Page_Load(object sender, EventArgs e)
{
String echoStr = Request["echostr"];
if(this.checkSignature()){
Response.Write(echoStr);
}
}
//驗證
private bool checkSignature(){
string signature = Request["signature"];
string timestamp = Request["timestamp"];
string nonce = Request["nonce"];
string token = TOKEN;
string[] tmpArr = new string[]{token, timestamp, nonce};
Array.Sort(tmpArr);
string tmpStr = string.Join("",tmpArr);
//sha1加密
System.Security.Cryptography.SHA1 sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] secArr = sha1.ComputeHash(System.Text.Encoding.Default.GetBytes(tmpStr));
tmpStr = BitConverter.ToString(secArr).Replace("-","").ToLower();
if( tmpStr == signature ){
return true;
}else{
return false;
}
}
</script>將以上代碼 另存 為 wx_sample.aspx
上傳到你的服務器
填寫當前頁面訪問路徑, 填寫對應的TOKEN
感謝各位的閱讀!關于“微信開發.Net 接入的示例分析”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。