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

首頁(yè) > 編程 > C# > 正文

C#微信公眾號(hào)與訂閱號(hào)接口開(kāi)發(fā)示例代碼

2019-10-29 21:26:32
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文實(shí)例講述了C#微信公眾號(hào)與訂閱號(hào)接口開(kāi)發(fā)示例代碼。分享給大家供大家參考,具體如下:

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")    {      //微信服務(wù)器對(duì)接口消息      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    {      //微信進(jìn)行的Get測(cè)試(開(kāi)發(fā)者認(rèn)證)      WxAuth();    }  }  /// <summary>  /// 處理信息并應(yīng)答  /// </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 微信驗(yàn)證  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>  /// 驗(yàn)證微信簽名  /// </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;    }  }}


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到c#教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 滨州市| 长顺县| 舟曲县| 开远市| 海安县| 苍溪县| 沿河| 井冈山市| 图们市| 松阳县| 晴隆县| 星座| 长岛县| 渭源县| 柳江县| 平塘县| 读书| 木里| 夹江县| 长治市| 泊头市| 称多县| 夹江县| 页游| 永州市| 泽州县| 镇坪县| 呼图壁县| 图片| 浙江省| 乐陵市| 东光县| 综艺| 亚东县| 扶风县| 乐山市| 广安市| 南昌市| 赤城县| 衡南县| 游戏|