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

首頁 > 編程 > C# > 正文

C#微信公眾號與訂閱號接口開發示例代碼

2020-01-24 01:07:00
字體:
來源:轉載
供稿:網友

本文實例講述了C#微信公眾號與訂閱號接口開發示例代碼。分享給大家供大家參考,具體如下:

using System;using System.Web;using System.IO;using System.Text;using System.Web.Security;using weixin_api;public class wxgz_api : IHttpHandler{  public void ProcessRequest(HttpContext context)  {    context.Response.ContentType = "text/plain";    string postString = string.Empty;    if (HttpContext.Current.Request.HttpMethod.ToUpper() == "POST")    {      //微信服務器對接口消息      using (Stream stream = HttpContext.Current.Request.InputStream)      {        Byte[] postBytes = new Byte[stream.Length];        stream.Read(postBytes, 0, (Int32)stream.Length);        postString = Encoding.UTF8.GetString(postBytes);        Handle(postString);      }    }    else    {      //微信進行的Get測試(開發者認證)      WxAuth();    }  }  /// <summary>  /// 處理信息并應答  /// </summary>  private void Handle(string postStr)  {    messageHelp help = new messageHelp();    string responseContent = help.ReturnMessage(postStr);    HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;    HttpContext.Current.Response.Write(responseContent);  }  #region 微信驗證  public void WxAuth()  {    string token = "xxxxxxxx";    if (string.IsNullOrEmpty(token))    {      return;    }    string echoString = HttpContext.Current.Request.QueryString["echostr"];    string signature = HttpContext.Current.Request.QueryString["signature"];    string timestamp = HttpContext.Current.Request.QueryString["timestamp"];    string nonce = HttpContext.Current.Request.QueryString["nonce"];    if (CheckSignature(token, signature, timestamp, nonce))    {      if (!string.IsNullOrEmpty(echoString))      {        HttpContext.Current.Response.Write(echoString);        HttpContext.Current.Response.End();      }    }  }  /// <summary>  /// 驗證微信簽名  /// </summary>  public bool CheckSignature(string token, string signature, string timestamp, string nonce)  {    string[] ArrTmp = { token, timestamp, nonce };    Array.Sort(ArrTmp);    string tmpStr = string.Join("", ArrTmp);    tmpStr = FormsAuthentication.HashPasswordForStoringInConfigFile(tmpStr, "SHA1");    tmpStr = tmpStr.ToLower();    if (tmpStr == signature)    {      return true;    }    else    {      return false;    }  }  #endregion  public bool IsReusable  {    get    {      return false;    }  }}

更多關于C#相關內容感興趣的讀者可查看本站專題:《C#常見控件用法教程》、《WinForm控件用法總結》、《C#數據結構與算法教程》、《C#面向對象程序設計入門教程》及《C#程序設計之線程使用技巧總結

希望本文所述對大家C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 龙海市| 奉贤区| 五寨县| 鲁山县| 米脂县| 蕉岭县| 合阳县| 新乡市| 南岸区| 瓦房店市| 德州市| 宁远县| 东乡族自治县| 东乌珠穆沁旗| 东乡族自治县| 西安市| 尚志市| 富阳市| 大连市| 策勒县| 眉山市| 沂水县| 香河县| 宕昌县| 夏邑县| 元朗区| 新龙县| 兴和县| 凯里市| 通化市| 扎兰屯市| 南充市| 邓州市| 滕州市| 壤塘县| 洪江市| 仁怀市| 娄烦县| 都昌县| 穆棱市| 汝州市|