国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

微信公眾平臺開發(fā)(二)

2019-11-14 13:47:05
字體:
供稿:網(wǎng)友

一、實現(xiàn)URL接入

相關參數(shù)描述

 

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Web;namespace WeiXinWebapplication{    public class CheckSignature    {        /// <summary>        /// 網(wǎng)站沒有提供Token情況下的默認Token        /// </summary>        public const string Token = "weixin";        /// <summary>        /// 檢查簽名是否正確        /// </summary>        /// <param name="signature">微信加密簽名</param>        /// <param name="timestamp">時間戳</param>        /// <param name="nonce">隨機數(shù)</param>        /// <param name="token"></param>        /// <returns></returns>        public static bool Check(string signature, string timestamp, string nonce, string token)        {            return signature == GetSignature(timestamp, nonce, token);        }        /// <summary>        /// 返回正確的簽名        /// </summary>        /// <param name="timestamp"></param>        /// <param name="nonce"></param>        /// <param name="token"></param>        /// <returns></returns>        public static string GetSignature(string timestamp, string nonce, string token = Token)        {            token = token ?? Token;            string[] arr = new[] {token,timestamp,nonce }.OrderBy(z=>z).ToArray();            string arrString = string.Join("",arr);            System.Security.Cryptography.SHA1 shal = System.Security.Cryptography.SHA1.Create();            byte[] shalArr = shal.ComputeHash(Encoding.UTF8.GetBytes(arrString));            StringBuilder enText = new StringBuilder();            foreach (var b in shalArr)            {                enText.AppendFormat("{0:x2}",b);            }            return enText.ToString();        }    }}

 

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace WeiXinWebApplication{    public partial class Index : System.Web.UI.Page    {        /// <summary>        /// 與微信公眾賬號后臺的Token設置保持一致,區(qū)分大小寫        /// </summary>        PRivate readonly string Token = "weixin";        protected void Page_Load(object sender, EventArgs e)        {            Auth();        }        /// <summary>        /// 處理微信服務器驗證消息        /// </summary>        private void Auth()        {            string signature = Request["signature"];            string timestamp = Request["timestamp"];            string nonce = Request["nonce"];            string echostr = Request["echostr"];            if (Request.HttpMethod == "GET")            {                if (CheckSignature.Check(signature, timestamp, nonce, Token))                {                    WriteContent(echostr);                }                else                {                    WriteContent("failed:" + signature + "," + CheckSignature.GetSignature(timestamp, nonce, Token) + "." + "如果你在瀏覽器中看到這句話,說明此地址可以被作為微信公眾號后臺的URL,請注意保持Token一致。");                }                Response.End();            }        }        private void WriteContent(string str)        {            Response.Output.Write(str);        }    }}

 二、接入微信公眾平臺

這樣我們就成功實現(xiàn)了URL接入微信公眾平臺的工作。

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 攀枝花市| 肥城市| 莱芜市| 扶沟县| 福清市| 巴彦县| 扎兰屯市| 湄潭县| 龙门县| 五原县| 黔西| 盘锦市| 鹰潭市| 文登市| 嘉荫县| 晋中市| 乐亭县| 宣武区| 景泰县| 集安市| 无极县| 延川县| 沾化县| 西乡县| 赤峰市| 荣昌县| 乌兰县| 彰武县| 凉山| 祁东县| 韶山市| 会昌县| 鲁山县| 芜湖市| 洮南市| 贞丰县| 盐山县| 东港市| 泗阳县| 枣阳市| 兴安县|