C#微信公衆平臺接入示例代碼

http://mp.weixin.qq.com/wiki/17/2d4265491f12608cd170a95559800f2d.html php

這是微信公衆平臺提供的接入指南。官網只提供了php的示例代碼,這裏我提供一份C#的接入示例代碼,只須要修改web.config中對應的配置[token]就能夠使用了html

值得注意的是,你須要申請一個域名,把這個網站發佈出去,綁定你申請的域名,而後把對應的信息填寫到web

選擇安全模式,由於代碼裏邊已經進行了加密處理,url裏填寫以前申請到的域名,encodingAESkey隨機生成。安全

 

········································別忘了綁定域名哦····································································微信

 

主要代碼片斷:微信公衆平臺

        /// <summary>
        /// 對字符串進行SHA1加密
        /// </summary>
        /// <param name="strIN">須要加密的字符串</param>
        /// <returns>密文</returns>
        public string SHA1_Encrypt(string Source_String)
        {
            byte[] StrRes = Encoding.Default.GetBytes(Source_String);
            HashAlgorithm iSHA = new SHA1CryptoServiceProvider();
            StrRes = iSHA.ComputeHash(StrRes);
            StringBuilder EnText = new StringBuilder();
            foreach (byte iByte in StrRes)
            {
                EnText.AppendFormat("{0:x2}", iByte);
            }
            return EnText.ToString();
        }
            List<String> strs = new List<string>();
            strs.Add(token);
            strs.Add(timestamp);
            strs.Add(nonce);
            strs.Sort();//這裏進行字典排序
            string GetStr = "";
            strs.ForEach(a => GetStr += a);//獲得排序後的字符串

代碼文件下載連接: http://pan.baidu.com/s/1dDczaTz 密碼: 6cc4ide

相關文章
相關標籤/搜索